OAuth2 and C# Desktop Apps Don’t Seem To Get Along.

I hadn’t been in Visual Studio for a while now, mostly because I had given up on all of my side projects due to the amount of time they soaked up vs my desire to do better game reviews on here, requiring me to spend more time actually playing the games. I had come up with an idea for a game a while back and was really enjoying developing the concept in my head so I figured it would be good to code up a small application to get my head back in the game before I tackled something a little bit more difficult. One particular idea I had was a Soundcloud downloader/library manager as whilst there are other tools to do this job they’re  a little cumbersome and I figured it couldn’t be too difficult to whip it up in a days worth of coding.

How wrong I was.

OAuth2The Soundcloud API has a good amount of documentation about it and from what I could tell I would be able to get my stream using it. However since this wasn’t something that was publicly available I’d have to authenticate to the API first through their OAuth2 interface, something which I had done with other sites so I wasn’t too concerned that it would be a barrier. Of course the big difference between those other projects and this one was the fact that this application was going to be a desktop app and so I figured I was either going to have to do some trickery to get the token or manually step through the process in order to get authenticated.

After having a quick Google around it looked like the OAuth library I had used previously, DotNetOpenAuth, would probably be able to fit the bill and it didn’t take me long to find a couple examples that looked like they’d do the job. Even better I found an article that showed an example of the exact problem I was trying to solve, albeit using a different library to the one I was. Great, I thought, I’ll just marry up the examples and get myself going in no time and after a little bit of working around I was getting what appeared to be an auth token back. Strangely though I couldn’t access any resources using it, either through my application or directly through my browser (as I had been able to do in the past). Busting open Fiddler showed that I was getting 401 (unauthorized) errors back, indicating that the token I was providing wasn’t a viable option.

After digging around and looking at some various resources it appears that whilst the OAuth API might still be online it’s not the preferred way of accessing anything and, as far as I can tell, is mostly deprecated. No worries I’ll just hit up the OAuth2 API instead, figuring that it should be relatively simple to authenticate to it since DotNetOpenAuth now natively supports it. Try as I might to find a working example I just simply could not get it to work with Soundcloud’s API, not even using the sample application that DotNetOpenAuth provides. Trying to search for other, more simplistic examples left me empty handed, especially if I tried to search for a desktop application workflow.

I’m willing to admit that I probably missed something here but honestly the amount of code and complexity that appears to be required to handle the OAuth2 authentication process, even when you’re using a library, seems rather ludicrous. Apparently WinRT has it pretty easy but those are web pages masquerading as applications which are able to take advantage of their auth work flow, something which I was able to make work quite easily in the past. If someone knows of a better library or has an example of the OAuth2 process working with a desktop application in C# then I’d love to see it because I simply couldn’t find out how to do it, at least not after half a day of frustration.

4 Comments

Leave a Comment
  1. I never did unfortunately. I had a ray of hope when I saw some intermediary services that I could potentially use to hook into it but I just couldn’t get anything to work. I’m sure someone much smarter than me has figured this out but it was turning into too much effort for a throwaway project, so it’s unfortunately fallen by the wayside.

  2. Sorry to hear that. I managed to get it working specifically with Google sign in and Windows Live Connect using their own APIs. Google sign in was quite easy, window’s live connect made you use the REST APIs directly with an embedded web browser.

    I guess it’s just a sign that desktop apps are fading away, being replaced by WinRT and web apps…

  3. Yeah that was very much the feeling I got which is really annoying when it comes to throwaway style applications like this one. Sure, I could build a full web app, but I was just making something quick and dirty for my own purposes and didn’t want to bother with all the other set up required to get that going.

    Maybe I just need to shift my mindset away from building throwaway desktop apps to making throwaway web apps 😉

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.