使用FlaskOAuthlib,我如何强制Facebook在重新验证时请求帐户?

2024-04-23 18:07:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Flask-OAuthlib包实现Google和Facebook对oauth2提供者的身份验证。在

对于谷歌,我使用的是:

google = oauth.remote_app(
    "google",
    consumer_key=client_id,
    consumer_secret=client_secret,
    request_token_params={"scope": "email"},
    base_url="https://www.googleapis.com/oauth2/v1/",
    request_token_url=None,
    access_token_method="POST",
    access_token_url="https://accounts.google.com/o/oauth2/token",
    authorize_url="https://accounts.google.com/o/oauth2/auth",
)

对于Facebook来说,代码是相似的:

^{pr2}$

更多完整的例子可用here。在

当我使用googleprovider时,我可以成功登录,一旦我注销,当我再次尝试登录时,我会被重定向到Google的页面,该页面显示了账户列表,并让我选择一个。在

当我使用Facebook提供者时,我可以成功地登录,但是一旦我注销,当我再次登录时,Facebook不再询问任何问题,只是用以前使用过的帐户自动登录我。在

我如何强制Facebook重新验证,即每次向用户显示Facebook页面,从而可以选择一个给定的帐户?在


Tags: httpscomclienttokenurlsecretfacebookaccess
1条回答
网友
1楼 · 发布于 2024-04-23 18:07:17

找到了。在

行:

request_token_params={"scope": "email"},

应替换为:

^{pr2}$

事实上,根据official documentation

To re-authenticate, you can use these same steps with additional parameters to force it:

[...]

reauthenticate - asks the person to re-authenticate unconditionally

相关问题 更多 >