【问题标题】:Identityserver4 doesn't revoke access tokens when calling end_session_endpointIdentityserver4 在调用 end_session_endpoint 时不会撤销访问令牌
【发布时间】:2021-02-16 01:32:23
【问题描述】:

从身份服务器 4 成功注销后(我看到日志消息 AuthenticationScheme: idsrv signed out.),实际的访问令牌仍然有效。因此,有了这个访问令牌,我仍然可以访问我的 API。

我可以通过调用自己使这些令牌失效:

_persistedGrantService.RemoveAllGrantsAsync(logoutContext.SubjectId, null, logoutContext.SessionId);

但我想知道这是否是正确的方法,因为我期望通过调用 end_session_endpoint 来管理身份服务器。 是不是我做错了什么?

我的退出方法如下所示:

await HttpContext.SignOutAsync();
var logoutContext = await _interactionService.GetLogoutContextAsync(logoutId);
if (logoutContext == null)
{
    return NotFound();
}

// Is this needed?
await _persistedGrantService.RemoveAllGrantsAsync(logoutContext.SubjectId, null, logoutContext.SessionId);

SignOutIframeUrl = logoutContext.SignOutIFrameUrl;

var externalIdp = await GetExternalIdpAsync();
if (externalIdp != null)
{
    // build a return URL so the upstream provider will redirect back
    // to us after the user has logged out. this allows us to then
    // complete our single sign-out processing.
    var url = Url.Page("SignOut", new {logoutId});

    // this triggers a redirect to the external provider for sign-out
    return SignOut(new AuthenticationProperties {RedirectUri = url}, externalIdp);
}

if (logoutContext.PostLogoutRedirectUri != null)
{
    return Redirect(logoutContext.PostLogoutRedirectUri);
}

return Page();


【问题讨论】:

    标签: identityserver4 openid-connect


    【解决方案1】:

    有一件事是您不应该从您的注销方法返回任何视图/数据。相反,SignOutAsync 在内部为您处理。

    所以,它可能看起来像这样:

        public async Task DoLogout()
        {
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
            await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
        }
    

    【讨论】:

    • 感谢您的回复。我按照docs.identityserver.io/en/latest/topics/… 的说明进行操作。您能否解释一下您的评论与那里提出的代码有何关系,因为他们和我一样,确实从注销方法返回视图/数据
    • 啊,我是在你使用 AddOpenIDConnect 客户端时使用的,而不是与 IdentityServer 一起使用,所以那里可能会有所不同...
    猜你喜欢
    • 2019-04-12
    • 2021-07-05
    • 2020-09-29
    • 2022-07-05
    • 1970-01-01
    • 2015-03-06
    • 2015-04-16
    • 1970-01-01
    相关资源
    最近更新 更多