Hi All,
I am having trouble with my code and was wondering if anyone could help point me in the right direction. Currently I am following the Authrorization Code Flow and have steps 1 and 2 working:
1.Send the user you’d like to authenticate to this URL:
https://api.twitch.tv/kraken/oauth2/authorize
?response_type=code
&client_id=[your client ID]
&redirect_uri=[your registered redirect URI]
&scope=[space separated list of scopes]
&state=[your provided unique token]
We support the state OAuth2 parameter, which is strongly recommended for avoid cross-site scripting attacks. If included, it is appended to the list of query parameters when redirecting the user to the redirect_uri .
This page will ask the user to sign up or log in with their Twitch account and allow them to choose whether to authorize your application or not.
2.If the user authorizes your application, they will be redirected to the following URL:
https://[your registered redirect URI]/?code=[CODE]
I am stuck on part 3:
3.On your server, you can now make the following request to obtain an access token:
POST https://api.twitch.tv/kraken/oauth2/token
POST Body (URL-encoded)
client_id=[your client ID]
&client_secret=[your client secret]
&grant_type=authorization_code
&redirect_uri=[your registered redirect URI]
&code=[code received from redirect URI]
&state=[your provided unique token]
My code is as follows:
string URI = "https://api.twitch.tv/kraken/oauth2/token";
string myParameters = "client_id=" + clientId
+ "&client_secret=" + clientSecret
+ "&grant_type=authorization_code"
+ "&redirect_uri=" + Uri.EscapeDataString(redirectUrl)
+ "&code= " + codeFromResult;
var httpClient = new HttpClient();
var responseFromPost = await httpClient.PostAsync(new Uri(URI), new StringContent(myParameters));
What is contained in responseFromPost is: 'StatusCode: 400, ReasonPhrase: ‘Bad Request’
I am writing a .NET C# application. Any help would be great. Thankyou in advance.