You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用.NET 6应用Google社交登录的上次账户自动登录功能?

解决Google登录自动选择之前账户的问题

这个问题是Google OAuth认证的默认行为——Google端会保留用户的登录会话,导致跳转后自动登录之前的账户。要强制每次登录都显示账户选择界面,你需要在认证请求中添加prompt=select_account参数,具体实现如下:

在配置Google认证时,通过OnRedirectToIdentityProvider事件修改跳转请求的参数:

builder.Services.AddAuthentication()
    .AddGoogle(options =>
    {
        options.ClientId = "你的Google Client ID";
        options.ClientSecret = "你的Google Client Secret";
        
        // 强制显示账户选择界面
        options.Events.OnRedirectToIdentityProvider = context =>
        {
            // 添加prompt参数,指定select_account
            context.ProtocolMessage.SetParameter("prompt", "select_account");
            return Task.CompletedTask;
        };
    });

补充说明:

  • prompt=select_account是Google OAuth 2.0的标准参数,作用是强制Google展示账户选择列表,忽略已有的登录会话。
  • 如果需要更严格的验证(比如每次都要求输入密码),可以将参数值改为prompt=consent,但这会同时要求用户重新授权权限,根据你的需求选择即可。

内容的提问来源于stack exchange,提问作者doogdeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 11:42:04