I am using Helix API and creating an app in Python and Flask. But I encountered a problem. Everytime I make a request it just returns 401 - invalid access token.
User authorizes app from this link: “https://id.twitch.tv/oauth2/authorize?client_id=rzmgq7ybviufdw3llgx1upt3w9ila5&response_type=code&redirect_uri=http://localhost:5000&scope=openid ”, it redirects to the “http://localhost:5000/?code= <access_token>&scope=openid” and validates token using a GET request. But everytime it just returns “invalid access token” error.
Source code:
from flask import Flask, request
from requests import get
app = Flask(__name__)
@app.route('/')
def validatetoken():
ACCESS_TOKEN = request.args.get('code')
r = get(url='https://id.twitch.tv/oauth2/validate', headers={'Authorization': f'Bearer {ACCESS_TOKEN}'})
return r.json()
Thanks in advance!
After getting the code you need to exchange the code for an access token
The code is NOT an access token.
Step 3
Getting Tokens: OAuth
NodeJS example that may help
state = decodeURIComponent(state);
if (req.session.state != state) {
req.session.error = 'State does not match. Please try again!';
res.redirect('/');
return;
}
// done with the state params
delete req.session.state;
// start the oAuth dance
got({
"url": "https://id.twitch.tv/oauth2/token",
"method": 'POST',
"headers": {
"Accept": "application/json"
},
"form": {
"client_id": config.client_id,
"client_secret": config.client_secret,
"code": code,
Ok. Now it works, one more thing does the /oauth2/token
require an redirect_uri? Without specyfing it, it wouldn’t let me in.
system
closed
October 8, 2020, 6:57pm
#6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.