0

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)

8
  • 1
    if it is autorization for your page then in Google you should set http://yourdomain/your_function and then Google will redirect to http://yourdomain/your_function?code=authorization_code and then you can get this code in your function. Commented Dec 5, 2019 at 23:25
  • @furas It is authorization to access a users API credentials. How do I pass the code to my function? Commented Dec 5, 2019 at 23:28
  • 1
    if this is your page (in Django, Flask) then you can get it in function account in your project Commented Dec 5, 2019 at 23:28
  • 1
    create function with @app.route('/account') and in this function you should get it with request.args.get('code') Commented Dec 5, 2019 at 23:32
  • 1
    did you run url with ?code=authorization_code ? if not then get('code') gives None because it can't find code= in url. Commented Dec 5, 2019 at 23:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.