[C#] Using OAuth2.0 to get followed streams

I’ve just been working on something similar, to be honest I’m no expert with WPF so I’ve put together a solution based on the following useful resources.

First you do need a very simple web server to listen for the response from the initial oAuth call, I used this as my starting point:

Second I set up a very simple Window containing one WebBrowser Control. The only bit of code is to set this to navigate to the initial Authorization url, something like this:

myWeb.Navigate(“https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=fqyfzn1c10xqpzc54uok2vuv6l7bs1&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2Fauth%2Ftwitch%2Fcallback&scope=user_read&state=OAUth2”);

Third take a read (I’m sure you already have) of this article particularly read about the Authorization Code Flow:

Last bit, take a look at the code I posted here:

Make sure you fix the PUT to POST.

Then you’ve got all the pieces you need to get the oAuth token.

  1. Spin up your web server listening to the url you configured as your redirect url in your Twitch application settings
  2. Send the user to the Auth URL using your WebBrowser control
  3. The user will have to enter their credentials, and maybe Two Factor auth details
  4. On a successful attempt your web server should then get a callback
  5. The callback for Authorization Code Flow contains a code
  6. Using the piece of code I posted you can make the final POST to Twitch and get the oAuth token back in the Json response.

I am planning on writing a small sample for this as I went through quite a few iterations before I got it working, in the mean time I hope this helps.

1 Like