I am using the flask-dance library to handle custom OAuth, here's a code sample:
oh = OAuth2ConsumerBlueprint(
"oh", __name__,
client_id="",
client_secret="",
authorization_url="",
token_url="",
redirect_uri="",
scope=[""],
redirect_to='/oauth-redirect'
)
I want to specify a URL parameter so that when the token is granted and the 3rd party website redirects back to my website, it knows where it came from. Like:
localhost:5010/oauth-redirect?id=oh
I know the redirect_to
variable is a repurposed url_for
via:
https://flask-dance.readthedocs.io/en/latest/api.html#flask_dance.consumer.OAuth2ConsumerBlueprint
which accepts vars like: url_for('page.route', foo="bar")
but how do I do something similar, be it passing data to the page or as a url parameter?
You can hook into the oauth_authorized
signal, and return a response object. This response can redirect to whatever URL you want, and you can pass whatever data you want in the URL parameters.