在用户注册后,在我的 Web Api 2 Identity 2 应用程序中,我在单个表中有一条记录:AspNetUsers。我使用以下 http 请求来获取令牌:
POST https://localhost:44304/Token HTTP/1.1
Accept: application/json
Content-type: application/x-www-form-urlencoded
Accept-Encoding: gzip
Content-Length: 68
Host: localhost:44304
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
grant_type=password&[email protected] /cdn-cgi/l/email-protection&password=123456
我得到了 access_token 的响应:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 695
Content-Type: application/json;charset=UTF-8
Expires: -1
Server: Microsoft-IIS/8.0
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcU2VyZ2V5XERvY3VtZW50c1xWaXN1YWwgU3R1ZGlvIDIwMTNcUHJvamVjdHNcbXZjX3dlYmFwaVxXZWJBcHBsaWNhdGlvblxXZWJBcHBsaWNhdGlvblxUb2tlbg==?=
X-Powered-By: ASP.NET
Date: Tue, 25 Nov 2014 17:40:07 GMT
{"access_token":"gsvW23e1...}
获得令牌后,数据库中不会添加任何记录。表 AspNetUsers 中仍然只有一条记录。数据库中的任何表中均不存储有关已发行令牌的信息。
我在 Web api 控制器中使用以下代码来验证用户身份:
var currentUser = manager.FindById(User.Identity.GetUserId());
if (currentUser == null)
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
return ResponseMessage(response);
}
之后,我执行密码更改并尝试使用旧的 access_token (我在密码更改之前获得的)调用一些 Web api 控制器方法,并且 access_token 仍然有效!当前用户不为空!
我读过 stackoverflow 上的其他帖子ASP.Net Identity 注销所有会话 https://stackoverflow.com/questions/21218027/asp-net-identity-sign-out-all-sessions
ASP.Net 身份注销 https://stackoverflow.com/questions/20681726/asp-net-identity-logout和博文https://timlotter.com/blog/asp-net-identity-invalidate-all-sessions-on-securitystamp-update/ https://timmlotter.com/blog/asp-net-identity-invalidate-all-sessions-on-securitystamp-update/但我还是不明白发行的代币的信息存储在哪里。
所以我的问题是:
1)access_token的信息存储在服务器的哪里?
2)为什么修改密码后我仍然可以使用修改密码前服务器颁发的access_token?
3)如何使修改密码前发放的所有access_token失效?