【问题标题】:Single sign-out in ASP.NET Core OpenID ConnectASP.NET Core OpenID Connect 中的单点注销
【发布时间】:2021-08-16 20:53:56
【问题描述】:
我有许多应用程序通过使用 Auth0 的单点登录 (SSO) 对用户进行身份验证。其中之一是 ASP.NET Core MVC 应用程序,它使用 ASP.NET Core OpenID Connect (OIDC) 中间件。单点登录工作正常。对于当前应用程序的单点注销,我从OnRedirectToIdentityProviderForSignOut 事件调用Auth0 的/v2/logout 端点,每个Auth0's quickstart example。但是,当从 另一个 应用程序退出 SSO 会话时,我不知道如何配置该应用程序以清除本地会话。 Auth0 mentions:
将用户重定向到注销端点不包括用户需要退出他们使用的所有应用程序的场景。如果您需要提供此功能,则必须通过以下两种方式之一进行处理:
我觉得checkSession 建议是针对 SPA 的。 ASP.NET Core OpenID Connect 中间件如何处理此类 SSO 会话注销?它是否会定期自动与身份验证服务器重新进行身份验证?如果是这样,这个频率如何配置?
【问题讨论】:
标签:
asp.net-core
.net-core
oauth-2.0
openid-connect
auth0
【解决方案1】:
AddOpenIDConnect 中间件模块有一个专用的 URL,它可以监听,并且外部提供者可以在用户退出后调用。
URL 在源代码here 中定义,如下所示:
SignedOutCallbackPath = new PathString("/signout-callback-oidc");
RemoteSignOutPath = new PathString("/signout-oidc");
/// <summary>
/// The request path within the application's base path where the user agent will be returned after sign out from the identity provider.
/// See post_logout_redirect_uri from http://openid.net/specs/openid-connect-session-1_0.html#RedirectionAfterLogout.
/// </summary>
public PathString SignedOutCallbackPath { get; set; }
/// <summary>
/// Requests received on this path will cause the handler to invoke SignOut using the SignOutScheme.
/// </summary>
public PathString RemoteSignOutPath { get; set; }
因此,您可以尝试将 Auth0 配置为调用 RemoteSignOutPath,这可能对您有用。但是,如果您有很多客户,那么您需要有不同的策略。也许使用更短的访问令牌生命周期?
【解决方案2】:
我接受了 Tore 的回答,因为这是 OpenID 身份提供程序支持前通道注销时的最佳方法。就我而言,Auth0 doesn't support OpenID Connect 前通道或后通道注销:
除了 Auth0 使用 SAML 时,Auth0 本身不支持单点注销。可以通过让每个应用程序在其令牌过期后检查活动会话来实现单次注销,或者您可以通过在应用程序级别终止应用程序会话来强制注销。
我设法在 ASP.NET Core MVC 3.1 中通过减少 AddCookie 配置中的 ExpireTimeSpan 来实现这一点:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(/* ... */)
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(1);
});
// ...
}
}
因此,任何以[Authorize] 修饰的控制器方法都会每分钟自动使用 Auth0 重新进行身份验证。如果 Auth0 会话仍然处于活动状态,用户将立即被重定向到目标页面。如果没有,他们将看到 Auth0 登录页面。