singingwolfboy / flask-dance

Doing the OAuth dance with style using Flask, requests, and oauthlib.
https://pypi.python.org/pypi/Flask-Dance/
MIT License
997 stars 156 forks source link

redirect_url not being respected for custom blueprint #429

Closed robcowen closed 5 months ago

robcowen commented 5 months ago

I have built a custom blueprint, following the docs, but the redirect_url parameter is not being passed on.

Here is my blueprint:

mylogin_blueprint = OAuth2ConsumerBlueprint(
    "mylogin", __name__,
    client_id="CLIENT_ID",
    client_secret=os.environ.get('MYLOGIN_CLIENT_SECRET'),
    base_url="https://app.mylogin.com/",
    token_url="https://app.mylogin.com/oauth/token",
    authorization_url="https://app.mylogin.com/oauth/authorize",
    redirect_url="/login/mylogin/route"
)
app.register_blueprint(mylogin_blueprint, url_prefix="/login")

I receive an error from the authorisation server, saying that the redirect_uri is incorrect. However, when I inspect the response the redirect_uri in their parameters is redirect_uri=http://localhost:5000/login/mylogin/authorized. This seems to suggest that Flask-Dance is not passing the redirect_url on correctly, so a default is being passed instead (/login/<name>/authorized). If I manually correct the response URL, it works correctly.

singingwolfboy commented 5 months ago

redirect_url is where to redirect the user after the OAuth dance successfully completes. Based on your description, I think you want to set authorized_url. See the docs for OAuth2ConsumerBlueprint.