【发布时间】:2018-02-20 01:06:58
【问题描述】:
我已经实现了 JWT Bearer 令牌基础认证和授权。我正在使用以下代码销毁 JWT 令牌或注销当前用户,但它不起作用。
//var claim = _httpContextAccessor.HttpContext.User.Claims;
// var users = await _userManager.FindByNameAsync(_httpContextAccessor.HttpContext.User.Identity.Name);
// var identity = _httpContextAccessor.HttpContext.User.Identity as ClaimsIdentity;
// foreach (var item in claim)
// {
// identity.RemoveClaim(item);
// }
await _signInManager.SignOutAsync();
【问题讨论】:
-
欢迎来到 Stack Overflow,@SumitRawat。您的代码以什么方式不起作用?你得到什么结果?你期待什么结果?
-
我可能在这里错了,所以如果其他人知道得更好,请发表评论。我认为应该在客户端撤销 JWT Bearer 令牌?
-
是的@DavidLee 我想从服务器撤销 JWT 不记名令牌。在上面的代码中,我只是想删除用户的声明
-
有没有办法验证令牌或将到期日期更改为过去?
标签: authentication jwt asp.net-core-webapi asp.net-core-1.1