如何使用Google的OAuth 2.0强制单个帐户用户登录帐户? [英] How to force account login for a single account user with Google's OAuth 2.0?

查看:300
本文介绍了如何使用Google的OAuth 2.0强制单个帐户用户登录帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,当用户使用Google的OAuth 2.0登录网站时,他们选择了错误的帐户进行登录.通常,如果用户在浏览器中注册了多个帐户,这不是问题,Google会自动显示用户选择屏幕:

Sometimes when a user logins into a site with Google's OAuth 2.0 they choose the wrong account to login with. Normally this isn't a problem if the user has more than one account registered with the browser, google will automatically show the user select screen:

但是,如果用户只有一个帐户并已登录,则将跳过此屏幕.相反,我需要始终显示Google的登录面板,以便确保用户可以选择尝试输入正确的帐户.我尝试使用approval_prompt = "force",但这会强制接受权限,而不是简单地显示登录页面.
如何强制Google的OAuth 2.0始终显示登录屏幕?
(并且永远不会自动跳过它)

But if a user has only one account and is logged in, this screen is skipped. Instead I need Google's sign in panel to always appear, so that I can be sure the user has the option to try and enter the correct account. I tried using approval_prompt = "force", but that forces the acceptance of permissions rather than simply showing the login page.
How can I force Google's OAuth 2.0 to always show the login screen?
(and never automatically skip it)

推荐答案

将参数prompt=select_account添加到您的授权请求中.

Add the parameter prompt=select_account to your authorization request.

这将导致始终显示帐户选择器,即使用户仅登录到一个帐户也是如此.用户将能够从他们的帐户中进行选择,或添加一个新帐户.

This will cause the account chooser to always be shown, even if the user is only logged in to one account. Users will be able to select from their accounts, or add a new one.

例如: 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆