简体   繁体   English

Identity Server 4注销-令牌生存期

[英]Identity Server 4 Signout - Token Lifetime

I have Identity server 4 at is.mysite.com and then I have mysite.com which uses angular to serve the content. 我在is.mysite.com有身份服务器4,然后有mysite.com ,它使用angular来提供内容。 Lastly, I have api.mysite.com which uses is4 to protect the content. 最后,我有api.mysite.com ,它使用is4保护内容。

What I'd like to know is what is the expected behavior of the lifetime of the token after the user has signed out. 我想知道的是用户注销后令牌的生存期的预期行为是什么。 Consider the following scenario: 请考虑以下情形:

  1. User opens mysite.com and click login. 用户打开mysite.com,然后单击登录。
  2. User is redirected to is.mysite.com and logs in 用户被重定向到is.mysite.com并登录
  3. User redirected back to mysite.com and can make api requests. 用户重定向回mysite.com,可以发出api请求。
  4. User open a new tab in the browser and goes to is.mysite.com and clicks logout. 用户在浏览器中打开一个新选项卡,然后转到is.mysite.com,然后单击注销。
  5. User goes back to previous tab where mysite.com is and tries to make the api call. 用户返回到mysite.com所在的上一个选项卡,并尝试进行api调用。

The current result that I get is that the user is able to retrieve the data. 我得到的当前结果是用户能够检索数据。 Is this expected? 这是预期的吗? Shouldn't the user no longer be able to use said token because they have logged out? 用户是否应该因为注销而不能再使用该令牌? The way I log out the users is as follows: 我注销用户的方式如下:

await _loginManager.LoggOffAsync(HttpContext.User);
await HttpContext.SignOutAsync();

Also if I visit the is.mysite.com, the user truly is logged out. 另外,如果我访问is.mysite.com,则该用户实际上已注销。

The angular client may monitor the session state of the user by using the session management specification, this is accomplished through an iframe. 角度客户端可以使用会话管理规范来监视用户的会话状态,这是通过iframe完成的。 For more information on the logout process you can take a look at the official documentation , specifically the section describing Javascript clients. 有关注销过程的更多信息,您可以查看官方文档 ,特别是描述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. 考虑到会话管理规范的设计方式,IdentityServer中没有什么特别的事情需要通知这些客户端用户已经注销。 The clients, though, must perform monitoring on the check_session_iframe, and this is implemented by the oidc-client JavaScript library . 但是,客户端必须在check_session_iframe上执行监视,这是由oidc-client JavaScript库实现的

It is intended behavior that the access token remains valid, this is why access tokens are valid for a short duration. 预期的行为是访问令牌保持有效,这就是为什么访问令牌在短时间内有效的原因。 If you need precise control over the validity of access tokens you can look into reference tokens , which are able to be revoked. 如果您需要对访问令牌的有效性进行精确控制,可以查看参考令牌 ,这些令牌可以被撤销。

I have set up my IdentityServer4 to a ReactJS client. 我已经将我的IdentityServer4设置为ReactJS客户端。 For the communication of javascript clients with IdentityServer4, I assume you might have installed the oidc-client-js. 为了与IdentityServer4进行javascript客户端通信,我假设您可能已经安装了oidc-client-js。 Through which you redirect the user to the IdentityServer4 (is.mysite.com) from you AngularClient (mysite.com) 通过它,您可以将用户从AngularClient(mysite.com)重定向到IdentityServer4(is.mysite.com)。

If so, you have to call signoutRedirect() method in your logout button click. 如果是这样,则必须在注销按钮单击中调用signoutRedirect()方法。 Only then your AngularClient (mysite.com) can successfully logout your user from IdentityServer4 (is.mysite.com). 只有这样,您的AngularClient(mysite.com)才能成功从IdentityServer4(is.mysite.com)注销您的用户。

Once the user has been signed out, the remaining tabs will be notified and will be signed out by the browser. 用户注销后,其余选项卡将收到通知,并将被浏览器注销。

"Make sure you add the [Authorize] tag on the controller to restrict the client to consume the API without a valid access token." “确保在控制器上添加[Authorize]标签,以限制客户端使用没有有效访问令牌的API。”

If you're talking about tokens with security stamps, then it depends on the validation interval that you have configured for your service. 如果您谈论的是带有安全标记的令牌,则取决于您为服务配置的验证间隔。 Setting this to zero will cause the security stamp to be validated on every request, so that logout everywhere will take effect immediately: 将其设置为零将使安全标记在每个请求上都得到验证,因此到处注销都将立即生效:

https://docs.microsoft.com/en-us/previous-versions/aspnet/dn497603%28v%3dvs.108%29 https://docs.microsoft.com/en-us/previous-versions/aspnet/dn497603%28v%3dvs.108%29

If this isn't how you're doing log out everywhere then we'd need to see more of your auth setup code to know where the issue is. 如果这不是您要注销的方式,那么我们需要查看更多身份验证设置代码才能知道问题出在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM