是否有一种方法可以强制Google帐户选择器出现,即使用户只使用一个帐户登录也是如此.
我试过重定向到这个URL:
https://accounts.google.com/AccountChooser?service=lso&continue=[authorizeurl]
Run Code Online (Sandbox Code Playgroud)
它似乎工作,但我不知道是否有任何其他条件可能会失败.

bre*_*eno 89
OAuth2授权URL支持以下参数:
prompt
目前,它可以有值none,select_account和consent.
none:将导致Google不显示任何UI,因此如果用户需要登录则失败,或者在多次登录时选择帐户,或者在首次批准时同意.它可以在不可见的i帧中运行,以便在您决定(例如)呈现授权按钮之前从先前授权的用户获取令牌.
同意:即使用户之前已经授权您的申请,也会强制显示批准页面.在一些极端情况下可能很有用,例如,如果您丢失了用户的refresh_token,因为Google仅在明确同意操作时发出refresh_tokens.
select_account:将导致帐户选择器显示,即使有一个登录用户,就像你问的那样.
select_account可以结合使用consent,如:
prompt=select_account consent
此外,您可以在HTML标记中添加"prompt"参数作为data-prompt ="select_account":
<div class="g-signin2" data-onsuccess="onSignIn" data-prompt="select_account">
Run Code Online (Sandbox Code Playgroud)
即使您只使用一个帐户登录,它也会每次强制进行帐户选择
某些人可能最终在这里寻找有关如何在Microsoft.AspNetCore.Authentication中执行此操作的答案。
我们可以通过Startup.ConfigureServices方法中的以下代码完成此操作:
services.AddAuthentication()
.AddGoogle(options =>
{
options.ClientId = configHelper.GoogleOAuthClientID;
options.ClientSecret = configHelper.GoogleOAuthSecret;
options.CallbackPath = "/signin-google";
options.AuthorizationEndpoint = string.Concat(options.AuthorizationEndpoint, "?prompt=select_account");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23087 次 |
| 最近记录: |