Python authlib flask-如何显式授权\u重定向?
我有“代码授予流”登录,authlib flask集成运行良好:Python authlib flask-如何显式授权\u重定向?,python,flask,authlib,Python,Flask,Authlib,我有“代码授予流”登录,authlib flask集成运行良好: redirect_uri = url_for('authorize', _external=True) return oauth.myOauth2.authorize_redirect(redirect_uri) 出于某种原因,我决定尝试使重定向更加可见。向用户显示一下我的应用程序,然后再重定向到一些人可能不太熟悉的登录页面 现在这种作品: redirect_uri = url_for('authorize', _externa
redirect_uri = url_for('authorize', _external=True)
return oauth.myOauth2.authorize_redirect(redirect_uri)
出于某种原因,我决定尝试使重定向更加可见。向用户显示一下我的应用程序,然后再重定向到一些人可能不太熟悉的登录页面
现在这种作品:
redirect_uri = url_for('authorize', _external=True)
aurl = oauth.myOauth2.create_authorization_url(redirect_uri)
# what to do with aurl['state']?
return render_template('redirect.html', delay=2,
redirect_notice='Redirecting to login',
redirect_url=aurl['url'])
但是,当我在登录后重定向回“authorize”时,我会得到authlib.integrations.base\u client.errors.mistchingstateError:mistching\u state:CSRF警告!请求和响应中的状态不相等。
我认为这是因为我没有保存aurl['State']
但我怎么能做到呢?我很难弄清楚授权重定向是如何做到的。也许有更好的办法?感谢您的帮助 完成工作有两种方法:
.authorize\u重定向中提取url
:redirect\u uri=url\u for('authorize',\u external=True)
resp=oauth.myOauth2.authorize\u重定向(重定向\u uri)
url=resp.headers.get('Location')
返回render_模板('redirect.html',delay=2,
redirect_notice='Redirecting to login',
重定向(url=url)
.save\u authorize\u data
保存CSRF和其他数据:您可以从以下方面学习:完成工作有两种方法:
.authorize\u重定向中提取url
:redirect\u uri=url\u for('authorize',\u external=True)
resp=oauth.myOauth2.authorize\u重定向(重定向\u uri)
url=resp.headers.get('Location')
返回render_模板('redirect.html',delay=2,
redirect_notice='Redirecting to login',
重定向(url=url)
.save\u authorize\u data
保存CSRF和其他数据: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'])