returngithub.authorize(scope="user")#redirect the user to the github login page and ask for access to user data (name, email, ...)
returnredirect("https://github.com/login/oauth/authorize/?client_id="+GITHUB_CLIENT_ID+"&scope=user")#redirect the user to the github login page and ask for access to user data (name, email, ...)
@app.route('/user/github-callback')#Github redirects to this link after the user authenticated. Then we use the Token we get from github and request via the github api the username and the userid
@app.route('/user/github-callback')#Github redirects to this link after the user authenticated. Then we use the Token we get from github and request via the github api the username and the userid
@github.authorized_handler
defauthorized():
defauthorized(oauth_token):
try:
ifoauth_tokenisNone:
code=request.args.get("code")
return"oauth failed, please try again"#If you call this page manual you get this error
params={'client_id':GITHUB_CLIENT_ID,'client_secret':GITHUB_CLIENT_SECRET,'code':code}#As paramtere we send the client id and the client secret which we get from github when registering an application and the user code from before
headers={'Authorization':'token '+oauth_token,}#Useragent doesn't matters, but is set here
oauth_token=post(url,params).text.split("access_token=")[1].split("&")[0]#Send a post request with the parameters from