【问题标题】:Sign Out of a Blazor App using the OIDC Authentication Scheme使用 OIDC 身份验证方案注销 Blazor 应用程序
【发布时间】:2023-01-31 01:10:00
【问题描述】:

我们有一个 .NET Core 6 Blazor 服务器应用程序。我们使用 OIDC 使用我们自己的身份提供者登录。我们在注销时遇到问题。

我们使用以下代码块设置了身份验证。

builder.Services
    .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddCookie()
    .AddOpenIdConnect(opts => {
        opts.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        opts.RequireHttpsMetadata = !isDebug;
        opts.ClientId = "user-accounts-app";
        opts.CallbackPath = "/signin-oidc";
        opts.ResponseType = OpenIdConnectResponseType.Code;
        opts.Authority = authority;
        opts.ClientSecret = builder.Configuration["CLIENT_SECRET"];
        var scopes = new List<string>() {
            "openid", "profile", "email", "phone", "offline_access"
        };
        foreach(var s in scopes)
        {
            opts.Scope.Add(s);
        }
    });

发现文档确实包含一个end_session_endpoint;但是,端点永远不会被击中。我们尝试从剃刀页面注销

await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
// This line does not work
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
{
    RedirectUri = "http://mydomainhere.com/our/path/here",
});

运行第二个SignOutAsync 似乎什么也没做。身份提供者未在结束会话端点命中,我们的注销页面上没有任何反应。我们的会话没有从 IDP 中清除。

此外,我们的 blazor 应用程序 cookie 并未完全清除。我们有大量挥之不去的.AspNetCorrelation.hash&lt;hash-here&gt;,路径为/signin-oidc(试图获取屏幕截图,但现在服务器出现错误)。但是 .AspNetCore cookie 被第一个 SignOutAsync 调用成功清除。

我不确定第二个 SignOutAsync 的行为应该是什么。它会将用户重定向到 IDP 的注销 url 吗?还是它在后台执行此操作?我们在调用 AddOpenIdConnect() 以处理注销时是否缺少某些配置?

【问题讨论】:

  • 服务器还是 WASM?身份验证提供者在哪里/谁
  • 这事有进一步更新吗?

标签: c# asp.net-core authentication blazor openid-connect


【解决方案1】:

看起来我们只是缺少 OIDC 注销方案。

opts.SignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;

这就是我们让它工作所需的一切。

如果未指定注销方案,ASP.net 将使用登录方案。登录方案是 cookie,这有点误导,因为 OpenID 机构实际上是您登录的机构。登录会导致创建 cookie 以存储该机构提供的身份验证令牌(因此您可以有效地登录到客户端应用程序)。如果您使用 cookie 方案注销,则只会销毁 cookie——您将退出客户端,但不会退出权限。下次你来到一个页面时,你只会得到一个新的 cookie,因为你已经登录了授权。

因此,上面的注销方案注销了权限,而不仅仅是客户端。我不确定弄清楚的同事是否也添加了删除cookie的步骤。如果我发现他们这样做了,我会用细节来编辑它。它可能以某种方式被 asp 框架神奇地处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2021-10-25
    • 2022-01-03
    • 2019-01-02
    • 2021-02-27
    • 2021-05-24
    相关资源
    最近更新 更多