Skip to content Skip to sidebar Skip to footer

Python Authlib Flask - How To Do Authorize_redirect Explicitly?

I have 'code grant flow' login with the authlib flask integration working nicely: redirect_uri = url_for('authorize', _external=True) return oauth.myOauth2.authorize_redirect(redir

Solution 1:

There are two ways to get your job done:

  1. extract url from .authorize_redirect:
redirect_uri = url_for('authorize', _external=True)
resp = oauth.myOauth2.authorize_redirect(redirect_uri)
url = resp.headers.get('Location')
return render_template('redirect.html', delay=2,
                       redirect_notice='Redirecting to login', 
                       redirect_url=url)
  1. use .save_authorize_data to save CSRF and other data:
redirect_uri = url_for('authorize', _external=True)
rv = oauth.myOauth2.create_authorization_url(redirect_uri)
oauth.myOauth2.save_authorize_data(request, redirect_uri=redirect_uri, **rv)
return render_template('redirect.html', delay=2,
                       redirect_notice='Redirecting to login', 
                       redirect_url=rv['url'])

You can learn it from: https://github.com/lepture/authlib/blob/master/authlib/integrations/flask_client/remote_app.py#L51

Post a Comment for "Python Authlib Flask - How To Do Authorize_redirect Explicitly?"