语言

JsonWebTokenHandler 类

定义

专为 SecurityTokenHandler 创建和验证 Json Web 令牌而设计。 请参阅: https://datatracker.ietf.org/doc/html/rfc7519 和 http://www.rfc-editor.org/info/rfc7515。

public class JsonWebTokenHandler : Microsoft.IdentityModel.Tokens.TokenHandler, Microsoft.IdentityModel.Tokens.Experimental.IResultBasedValidation
type JsonWebTokenHandler = class
    inherit TokenHandler
    interface IResultBasedValidation
Public Class JsonWebTokenHandler
Inherits TokenHandler
Implements IResultBasedValidation
继承
JsonWebTokenHandler
实现

注解

此分部类包含与令牌验证相关的方法和逻辑。

构造函数

名称 说明
JsonWebTokenHandler()

初始化 JsonWebTokenHandler 类的新实例。

字段

名称 说明
Base64UrlEncodedUnsignedJWSHeader

获取以下 JWT 标头的 Base64Url 编码字符串表示形式:{ Alg, None }。

DefaultInboundClaimTypeMap

入站声明的默认声明类型映射。

DefaultMapInboundClaims

确定是否使用 InboundClaimTypeMap 的标志的默认值。

属性

名称 说明
CanValidateToken

返回一个值,该值指示此处理程序是否可以验证 。SecurityToken

InboundClaimTypeMap

获取或设置InboundClaimTypeMap在验证 a Type时为提取的ClaimsPrincipal声明设置JsonWebToken时使用的项。

使用此映射进行转换后,该 Type 属性将设置为 JSON 声明“name”。

默认值为 ClaimTypeMapping.InboundClaimTypeMap。

MapInboundClaims

获取或设置在 MapInboundClaims 确定是否映射验证 a JsonWebToken时提取的声明类型时使用的属性。

如果此值设置为 true, Type 则使用此映射进行转换后,将设置为 JSON 声明“name”。 否则,不会发生映射。

默认值为 false。

MaximumTokenSizeInBytes

获取和设置将处理的最大令牌大小(以字节为单位)。

(继承自 TokenHandler)
SetDefaultTimesOnTokenCreation

获取或设置一个布尔值,用于控制令牌创建是否将设置默认的“exp”、“nbf”和“iat”(如果未指定)。

(继承自 TokenHandler)
ShortClaimTypeProperty

获取或设置在创建 时发生映射时Properties,将包含原始 JSON 声明“name”的属性名称Claim。

TokenLifetimeInMinutes

获取或设置令牌生存期(以分钟为单位)。

(继承自 TokenHandler)
TokenType

获取 JsonWebToken的类型。

方法

名称 说明
CanReadToken(String)

确定字符串是否是格式良好的 JSON Web 令牌 (JWT)。 请参阅:https://datatracker.ietf.org/doc/html/rfc7519。

CreateClaimsIdentity(JsonWebToken, TokenValidationParameters, String)

使用指定的颁发者创建一个ClaimsIdentityJsonWebToken。

CreateClaimsIdentity(JsonWebToken, TokenValidationParameters)

从 . 创建一个 ClaimsIdentityJsonWebToken。

CreateToken(SecurityTokenDescriptor)

创建可以是 JWS 或 JWE 的 JWT。

CreateToken(String, EncryptingCredentials, IDictionary<String,Object>)

创建 JSON Web 加密 (JWE)。

CreateToken(String, EncryptingCredentials, String)

创建 JSON Web 加密 (JWE)。

CreateToken(String, EncryptingCredentials)

创建 JSON Web 加密 (JWE)。

CreateToken(String, IDictionary<String,Object>)

创建未签名的 JSON Web 签名(JWS)。

CreateToken(String, SigningCredentials, EncryptingCredentials, IDictionary<String,Object>)

创建 JSON Web 加密 (JWE)。

CreateToken(String, SigningCredentials, EncryptingCredentials, String, IDictionary<String,Object>, IDictionary<String,Object>)

创建 JSON Web 加密 (JWE)。

CreateToken(String, SigningCredentials, EncryptingCredentials, String, IDictionary<String,Object>)

创建 JSON Web 加密 (JWE)。

CreateToken(String, SigningCredentials, EncryptingCredentials, String)

创建 JSON Web 加密 (JWE)。

CreateToken(String, SigningCredentials, EncryptingCredentials)

创建 JSON Web 加密 (JWE)。

CreateToken(String, SigningCredentials, IDictionary<String,Object>)

创建 JSON Web 签名(JWS)。

CreateToken(String, SigningCredentials)

创建 JSON Web 签名(JWS)。

CreateToken(String)

创建未签名的 JSON Web 签名(JWS)。

DecryptToken(JsonWebToken, TokenValidationParameters)

解密 JWE 并返回明文。

DecryptTokenWithConfigurationAsync(JsonWebToken, TokenValidationParameters, CancellationToken)

解密 JWE 并返回明文。

EncryptToken(String, EncryptingCredentials, IDictionary<String,Object>)

加密 JWS。

EncryptToken(String, EncryptingCredentials, String, IDictionary<String,Object>)

加密 JWS。

EncryptToken(String, EncryptingCredentials, String)

加密 JWS。

EncryptToken(String, EncryptingCredentials)

加密 JWS。

ReadJsonWebToken(ReadOnlyMemory<Char>)

将字符的 ReadOnlyMemory 范围转换为实例 JsonWebToken。

ReadJsonWebToken(String)

将字符串转换为 . 的 JsonWebToken实例。

ReadToken(String)

将字符串转换为 . 的 JsonWebToken实例。

ReplaceTokenHeader(JsonWebToken, String)

通过替换现有JsonWebToken标头并重用已分析的有效负载和签名来创建一个新JsonWebToken项。

ResolveTokenDecryptionKey(String, JsonWebToken, TokenValidationParameters)

返回解密 JWE 时要使用的值 SecurityKey 。

ValidateToken(String, TokenValidationParameters)
已过时.

验证 JWS 或 JWE。

ValidateTokenAsync(SecurityToken, TokenValidationParameters)

验证令牌。 在验证失败时,不会引发异常;相反,将在返回的 TokenValidationResult.Exception 属性中设置异常。 调用方应始终检查 TokenValidationResult.IsValid 属性以验证结果的有效性。

ValidateTokenAsync(String, TokenValidationParameters)

验证令牌。 在验证失败时,不会引发异常;相反,将在返回的 TokenValidationResult.Exception 属性中设置异常。 调用方应始终检查 TokenValidationResult.IsValid 属性以验证结果的有效性。

显式接口实现

名称 说明
IResultBasedValidation.ValidateTokenAsync(SecurityToken, ValidationParameters, CallContext, CancellationToken)

专为 SecurityTokenHandler 创建和验证 Json Web 令牌而设计。 请参阅: https://datatracker.ietf.org/doc/html/rfc7519 和 http://www.rfc-editor.org/info/rfc7515。

IResultBasedValidation.ValidateTokenAsync(SecurityToken, ValidationParameters, CallContext)

专为 SecurityTokenHandler 创建和验证 Json Web 令牌而设计。 请参阅: https://datatracker.ietf.org/doc/html/rfc7519 和 http://www.rfc-editor.org/info/rfc7515。

IResultBasedValidation.ValidateTokenAsync(String, ValidationParameters, CallContext, CancellationToken)

专为 SecurityTokenHandler 创建和验证 Json Web 令牌而设计。 请参阅: https://datatracker.ietf.org/doc/html/rfc7519 和 http://www.rfc-editor.org/info/rfc7515。

IResultBasedValidation.ValidateTokenAsync(String, ValidationParameters, CallContext)

专为 SecurityTokenHandler 创建和验证 Json Web 令牌而设计。 请参阅: https://datatracker.ietf.org/doc/html/rfc7519 和 http://www.rfc-editor.org/info/rfc7515。

适用于