So I’m making a website and I’m trying to make a Login via Twitch option. It redirects to Twitch for authentication from the user with all the correct parameters in the URL but when it returns back to my webpage, how do I begin to get data from Twitch with the auth token?
Depending on what method of authentication you are using, you can go about this in two difference ways.
If you are using the Implicit Grant Flow in which the access_token and the scope appears in the Fragmented part of a url http://example.com/twitch.php#access_token=aaaaaaa&scope=user_read
You will want to read from document.location.hash and split the string using the ampersand as the delimiter. Once you have the access_token you can include it in the URL’s you request as a parameter of ?oauth_token= or as a HTTP header of Authorization: OAuth [access token].
As for the Authorization Code Flow, once the user is back on your website, you will have a parameter of ?code= inside the URL. Use this to perform another request to twitch to obtain the access token. Once you have the access token, use it the same was as the other method.