I am attempting to extract an authorization code from an Oauth2 redirect URI.
I.E. once one of my users clicks allow on an Oauth2 consent form, they are redirected back to my indicated URL - but with an important authorization code in the parameters. For example:
http://localhost:5000/account?code=authorization_code
I know I can use Selenium Webdriver to grab the URL, but I have to eventually deploy this to my Linux server.
My question is, how can I pull the current user URL from the browser such that I can use it for my purposes?
(I am also open to other suggestions for how to approach this if there are better alternatives)
If it is your page in Flask
then you can use request.args.get('code')
to get it in function created with @app.route('/account')
from flask import Flask, request
app = Flask(__name__)
@app.route('/account')
def account():
code = request.args.get('code')
print('code:', code)
return "Your code: " + code
app.run()
If you use in browser http://localhost:5000/account?code=1234567890
then it will send it to your Flask and it will display 1234567890
in console/terminal and "Your code: 1234567890"
on page.