Identity Server 4 注销 - 令牌生命周期
Identity Server 4 Signout - Token Lifetime
我在 is.mysite.com
有身份服务器 4,然后我有 mysite.com
,它使用 angular 来提供内容。最后,我有 api.mysite.com
使用 is4 来保护内容。
我想知道的是用户注销后令牌生命周期的预期行为是什么。考虑以下情况:
- 用户打开 mysite.com 并单击登录。
- 用户被重定向到 is.mysite.com 并登录
- 用户重定向回 mysite.com 并且可以发出 api 请求。
- 用户在浏览器中打开一个新选项卡并转到 is。mysite.com 然后单击注销。
- 用户返回 mysite.com 所在的上一个选项卡并尝试拨打 api 电话。
我得到的当前结果是用户能够检索数据。这是预期的吗?用户不应该因为他们已经注销而不能再使用所述令牌吗?我退出用户的方式如下:
await _loginManager.LoggOffAsync(HttpContext.User);
await HttpContext.SignOutAsync();
此外,如果我访问 is。mysite.com,用户确实已注销。
我已经将我的 IdentityServer4 设置为 ReactJS 客户端。对于 javascript 客户端与 IdentityServer4 的通信,我假设您可能已经安装了 oidc-client-js。通过它将用户从 AngularClient (mysite.com)
重定向到 IdentityServer4 (is.mysite.com)
如果是这样,您必须在单击注销按钮时调用 signoutRedirect() 方法。
只有这样,您的 AngularClient (mysite.com) 才能从 IdentityServer4 (is.mysite.com) 成功注销您的用户。
用户注销后,其余选项卡将收到通知并由浏览器注销。
"Make sure you add the [Authorize] tag on the controller to restrict the client to consume the API without a valid access token."
如果您谈论的是带有安全标记的令牌,那么它取决于您为服务配置的验证间隔。将此设置为零将导致在每次请求时验证安全戳,以便在任何地方注销都会立即生效:
https://docs.microsoft.com/en-us/previous-versions/aspnet/dn497603%28v%3dvs.108%29
如果这不是您到处注销的方式,那么我们需要查看更多您的身份验证设置代码才能知道问题出在哪里。
angular 客户端可以使用 session management specification, this is accomplished through an iframe. For more information on the logout process you can take a look at the official documentation 监视用户的会话状态,特别是描述 Javascript 客户端的部分。
Given how the session management specification is designed, there is nothing special in IdentityServer that you need to do to notify these clients that the user has signed out. The clients, though, must perform monitoring on the check_session_iframe, and this is implemented by the oidc-client JavaScript library.
访问令牌保持有效是预期的行为,这就是访问令牌在短时间内有效的原因。如果您需要精确控制访问令牌的有效性,您可以查看 reference tokens,它可以被撤销。
我在 is.mysite.com
有身份服务器 4,然后我有 mysite.com
,它使用 angular 来提供内容。最后,我有 api.mysite.com
使用 is4 来保护内容。
我想知道的是用户注销后令牌生命周期的预期行为是什么。考虑以下情况:
- 用户打开 mysite.com 并单击登录。
- 用户被重定向到 is.mysite.com 并登录
- 用户重定向回 mysite.com 并且可以发出 api 请求。
- 用户在浏览器中打开一个新选项卡并转到 is。mysite.com 然后单击注销。
- 用户返回 mysite.com 所在的上一个选项卡并尝试拨打 api 电话。
我得到的当前结果是用户能够检索数据。这是预期的吗?用户不应该因为他们已经注销而不能再使用所述令牌吗?我退出用户的方式如下:
await _loginManager.LoggOffAsync(HttpContext.User);
await HttpContext.SignOutAsync();
此外,如果我访问 is。mysite.com,用户确实已注销。
我已经将我的 IdentityServer4 设置为 ReactJS 客户端。对于 javascript 客户端与 IdentityServer4 的通信,我假设您可能已经安装了 oidc-client-js。通过它将用户从 AngularClient (mysite.com)
重定向到 IdentityServer4 (is.mysite.com)如果是这样,您必须在单击注销按钮时调用 signoutRedirect() 方法。 只有这样,您的 AngularClient (mysite.com) 才能从 IdentityServer4 (is.mysite.com) 成功注销您的用户。
用户注销后,其余选项卡将收到通知并由浏览器注销。
"Make sure you add the [Authorize] tag on the controller to restrict the client to consume the API without a valid access token."
如果您谈论的是带有安全标记的令牌,那么它取决于您为服务配置的验证间隔。将此设置为零将导致在每次请求时验证安全戳,以便在任何地方注销都会立即生效:
https://docs.microsoft.com/en-us/previous-versions/aspnet/dn497603%28v%3dvs.108%29
如果这不是您到处注销的方式,那么我们需要查看更多您的身份验证设置代码才能知道问题出在哪里。
angular 客户端可以使用 session management specification, this is accomplished through an iframe. For more information on the logout process you can take a look at the official documentation 监视用户的会话状态,特别是描述 Javascript 客户端的部分。
Given how the session management specification is designed, there is nothing special in IdentityServer that you need to do to notify these clients that the user has signed out. The clients, though, must perform monitoring on the check_session_iframe, and this is implemented by the oidc-client JavaScript library.
访问令牌保持有效是预期的行为,这就是访问令牌在短时间内有效的原因。如果您需要精确控制访问令牌的有效性,您可以查看 reference tokens,它可以被撤销。