检索生成访问令牌的时间?
Retrieving the time that an access token was generated?
我正在尝试获取包含令牌创建日期的声明...我尝试了以下操作:
var createdDate = contextAccessor.HttpContext.User.FindFirstValue("IssuedUtc");
var createdDate = contextAccessor.HttpContext.User.FindFirstValue("iss");
var createdDate = contextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.AuthenticationInstant);
当使用 JWT 作为访问令牌格式时,您可以使用 iat
声明。
使用默认的不透明格式时,创建日期不会作为声明存储,而是作为身份验证存储 属性。您可以使用 AuthenticationManager
API:
检索它
var result = await contextAccessor.HttpContext.Authentication.GetAuthenticateInfoAsync(OAuthValidationDefaults.AuthenticationScheme);
var date = result.Properties.IssuedUtc;
注意:第二个选项也适用于 JWT,只需将 OAuthValidationDefaults.AuthenticationScheme
常量替换为 JwtBearerDefaults.AuthenticationScheme
。
我正在尝试获取包含令牌创建日期的声明...我尝试了以下操作:
var createdDate = contextAccessor.HttpContext.User.FindFirstValue("IssuedUtc");
var createdDate = contextAccessor.HttpContext.User.FindFirstValue("iss");
var createdDate = contextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.AuthenticationInstant);
当使用 JWT 作为访问令牌格式时,您可以使用 iat
声明。
使用默认的不透明格式时,创建日期不会作为声明存储,而是作为身份验证存储 属性。您可以使用 AuthenticationManager
API:
var result = await contextAccessor.HttpContext.Authentication.GetAuthenticateInfoAsync(OAuthValidationDefaults.AuthenticationScheme);
var date = result.Properties.IssuedUtc;
注意:第二个选项也适用于 JWT,只需将 OAuthValidationDefaults.AuthenticationScheme
常量替换为 JwtBearerDefaults.AuthenticationScheme
。