c# - ASP.NET Core 2.0+ 中 JwtBearerOptions.SaveToken 属性的用途是什么?

标签 c# authentication asp.net-core jwt

Microsoft Docs只要有这个描述:

Defines whether the bearer token should be stored in the AuthenticationProperties after a successful authorization.

我想知道保存 JWT 是否允许您以某种方式撤销它,但我读到的每个关于 JWT 的地方都说它们是不可撤销的。您将如何处理存储在 AuthenticationProperties 中的 JWT?

最佳答案

将 JWT 存储在 AuthenticationProperties 中允许您从应用程序中的其他位置检索它。

例如,使用 GetTokenAsync在 Action 内部,如下所示:

public async Task<IActionResult> SomeAction()
{
    // using Microsoft.AspNetCore.Authentication;
    var accessToken = await HttpContext.GetTokenAsync("access_token");

    // ...
}

例如,如果您想在传出请求中转发 JWT,这非常有用。

关于c# - ASP.NET Core 2.0+ 中 JwtBearerOptions.SaveToken 属性的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57057749/

相关文章:

c# - swift 中对内部数组的本地引用

java - 错误: Value Fatal of type java. lang.String无法转换为JSONObject

c# - 使用.Net 6动态读取.Net core Web App中的Azure应用程序配置

ios - PFAnonymousUtils.logIn 出错

php - 这是 flash、php 和 mysql 中的错误登录算法吗?

c# - 如何仅为一个 Razor 页面设置 `ValidationVisitor.MaxValidationDepth` = 1?

c# - 匿名方法 - 3 种不同的方式 - 异步

c# - 下载期间即时计算哈希值

javascript - 将列表传递给 View 后如何转换列表的 C# 列表?

c# - 我可以 "multiply"一个字符串(在 C# 中)吗?