首页 > 解决方案 > 强制 google oauth 提示用户选择帐户

问题描述

根据这个,您可以使用prompt查询字符串告诉 google oauth 您希望用户选择用户帐户。

有人可以告诉我如何在 asp.net 核心中执行此操作 - 如果您AddGoogle按照以下方式使用代码:

.AddGoogle(GoogleDefaults.AuthenticationScheme, googleOptions =>
{
    googleOptions.ClientId = "***";
    googleOptions.ClientSecret = "***";
    googleOptions.AccessType = "offline";

    googleOptions.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
    googleOptions.ClaimActions.Clear();
    googleOptions.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
    googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
    googleOptions.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
    googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
    googleOptions.ClaimActions.MapJsonKey("urn:google:profile", "link");
    googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
})

标签: c#asp.net-coreasp.net-identity

解决方案


我最近也需要这样做。

尝试这个:

googleOptions.AuthorizationEndpoint += "?prompt=consent";

推荐阅读