c# - 从 IdentityServer4 注销时撤销刷新令牌
问题描述
这是我的自定义注销端点:
[HttpPost("logout")]
public async Task<IActionResult> LogoutAsync()
{
await _interaction.RevokeTokensForCurrentSessionAsync();
await HttpContext.SignOutAsync();
return Ok();
}
它会删除 IdentityServer cookie,但如果此时用户有一个 refresh_token,他仍然可以在注销后使用它。如何撤销所有相关的刷新令牌?我尝试使用IIdentityServerInteractionService.RevokeTokensForCurrentSessionAsync
,但它不像预期的那样工作。
解决方案
你的客户是SPA吗?如果是,请在注销操作时从 localstorage 中删除 refresh_token。
此外,您可以使用 HttpClient 在自定义注销函数中向此端点发出 POST 请求:
https://[Your_IdentityServer4_url]/connect/revocation
token_type_hint=refresh_token
client_id=[your_client_id]
client_secret=[your_client_secret]
token=[your_refresh_token]
或者,您可以像这样在注销时使用事件来撤销刷新令牌。
.AddCookie("cookie", options =>
{
options.Cookie.Name = "mvccode";
options.Events.OnSigningOut = async e =>
{
// revoke refresh token on sign-out
await e.HttpContext.RevokeUserRefreshTokenAsync();
};
})
链接到文档 -这里。
推荐阅读
- documentation - 开发人员技术文档
- python - 如何有效地分配给 TensorFlow 中的张量切片
- sql - 查找值是否在 SQL 中不存在
- nopcommerce-4.2 - “Nop Ajax filter Pro”的性能问题
- c++ - cmd.exe vs Powershell中C++程序的不同执行时间
- python - 我可以使用 kwargs 来传递这部分功能吗?
- azure - 使用 azure-python-sdk 拉取应用程序列表时出现“权限不足,无法完成操作”错误
- sql - 条件语句不能正常工作
- lua - 如何在 LUA 脚本中正确格式化日期 - 05292020
- ios - 嵌入式 UIcollectionView 在 UITableView Cell 内滚动