<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />

Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler

public class JsonWebTokenHandler : TokenHandler, IResultBasedValidation
A SecurityTokenHandler designed for creating and validating Json Web Tokens. See: https://datatracker.ietf.org/doc/html/rfc7519 and http://www.rfc-editor.org/info/rfc7515.
public const string Base64UrlEncodedUnsignedJWSHeader = "eyJhbGciOiJub25lIn0"

Gets the Base64Url encoded string representation of the following JWT header: { Alg, None }.

public static IDictionary<string, string> DefaultInboundClaimTypeMap

Default claim type mapping for inbound claims.

public static bool DefaultMapInboundClaims

Default value for the flag that determines whether or not the InboundClaimTypeMap is used.

public static string ShortClaimTypeProperty { get; set; }

Gets or sets the property name of Properties the will contain the original JSON claim 'name' if a mapping occurred when the Claim(s) were created.

public virtual bool CanValidateToken { get; }

Returns a value that indicates if this handler can validate a SecurityToken.

public IDictionary<string, string> InboundClaimTypeMap { get; set; }

Gets or sets the InboundClaimTypeMap which is used when setting the Type for claims in the ClaimsPrincipal extracted when validating a JsonWebToken.

The Type is set to the JSON claim 'name' after translating using this mapping.

The default value is ClaimTypeMapping.InboundClaimTypeMap.

public bool MapInboundClaims { get; set; }

Gets or sets the MapInboundClaims property which is used when determining whether or not to map claim types that are extracted when validating a JsonWebToken.

If this is set to true, the Type is set to the JSON claim 'name' after translating using this mapping. Otherwise, no mapping occurs.

The default value is false.

public Type TokenType { get; }

Gets the type of the JsonWebToken.

Initializes a new instance of the JsonWebTokenHandler class.

public virtual bool CanReadToken(string token)

Determines if the string is a well formed JSON Web Token (JWT). See: .

protected virtual ClaimsIdentity CreateClaimsIdentity(JsonWebToken jwtToken, TokenValidationParameters validationParameters)

Creates a ClaimsIdentity from a JsonWebToken.

protected virtual ClaimsIdentity CreateClaimsIdentity(JsonWebToken jwtToken, TokenValidationParameters validationParameters, string issuer)

Creates a ClaimsIdentity from a JsonWebToken with the specified issuer.

public virtual string CreateToken(string payload)

Creates an unsigned JSON Web Signature (JWS).

public virtual string CreateToken(string payload, IDictionary<string, object> additionalHeaderClaims)

Creates an unsigned JSON Web Signature (JWS).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials)

Creates a JSON Web Signature (JWS).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, IDictionary<string, object> additionalHeaderClaims)

Creates a JSON Web Signature (JWS).

public virtual string CreateToken(SecurityTokenDescriptor tokenDescriptor)

Creates a JWT that can be a JWS or JWE.

public virtual string CreateToken(string payload, EncryptingCredentials encryptingCredentials)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, EncryptingCredentials encryptingCredentials, IDictionary<string, object> additionalHeaderClaims)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, IDictionary<string, object> additionalHeaderClaims)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, EncryptingCredentials encryptingCredentials, string compressionAlgorithm)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, string compressionAlgorithm)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, string compressionAlgorithm, IDictionary<string, object> additionalHeaderClaims, IDictionary<string, object> additionalInnerHeaderClaims)

Creates a JSON Web Encryption (JWE).

public virtual string CreateToken(string payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, string compressionAlgorithm, IDictionary<string, object> additionalHeaderClaims)

Creates a JSON Web Encryption (JWE).

public string DecryptToken(JsonWebToken jwtToken, TokenValidationParameters validationParameters)

Decrypts a JWE and returns the clear text.

public Task<string> DecryptTokenWithConfigurationAsync(JsonWebToken jwtToken, TokenValidationParameters validationParameters, CancellationToken cancellationToken)

Decrypts a JWE and returns the clear text.

public string EncryptToken(string innerJwt, EncryptingCredentials encryptingCredentials)

Encrypts a JWS.

public string EncryptToken(string innerJwt, EncryptingCredentials encryptingCredentials, IDictionary<string, object> additionalHeaderClaims)

Encrypts a JWS.

public string EncryptToken(string innerJwt, EncryptingCredentials encryptingCredentials, string algorithm)

Encrypts a JWS.

public string EncryptToken(string innerJwt, EncryptingCredentials encryptingCredentials, string algorithm, IDictionary<string, object> additionalHeaderClaims)

Encrypts a JWS.

public virtual JsonWebToken ReadJsonWebToken(string token)

Converts a string into an instance of JsonWebToken.

public virtual JsonWebToken ReadJsonWebToken(ReadOnlyMemory<char> token)

Converts a ReadOnlyMemory span of characters into an instance of JsonWebToken.

protected virtual SecurityKey ResolveTokenDecryptionKey(string token, JsonWebToken jwtToken, TokenValidationParameters validationParameters)

Returns a SecurityKey to use when decrypting a JWE.

public virtual TokenValidationResult ValidateToken(string token, TokenValidationParameters validationParameters)

Validates a JWS or a JWE.