JsonWebTokenHandler Class

Definition

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 class JsonWebTokenHandler : Microsoft.IdentityModel.Tokens.TokenHandler
type JsonWebTokenHandler = class
    inherit TokenHandler
Public Class JsonWebTokenHandler
Inherits TokenHandler
Inheritance
JsonWebTokenHandler

Remarks

This partial class is focused on TokenCreation.

Constructors

JsonWebTokenHandler()

Initializes a new instance of the JsonWebTokenHandler class.

Fields

Base64UrlEncodedUnsignedJWSHeader

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

DefaultInboundClaimTypeMap

Default claim type mapping for inbound claims.

DefaultMapInboundClaims

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

Properties

CanValidateToken

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

InboundClaimTypeMap

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.

MapInboundClaims

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.

MaximumTokenSizeInBytes

Gets and sets the maximum token size in bytes that will be processed.

(Inherited from TokenHandler)
SetDefaultTimesOnTokenCreation

Gets or sets a bool that controls if token creation will set default 'exp', 'nbf' and 'iat' if not specified.

(Inherited from TokenHandler)
ShortClaimTypeProperty

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.

TokenLifetimeInMinutes

Gets or sets the token lifetime in minutes.

(Inherited from TokenHandler)
TokenType

Gets the type of the JsonWebToken.

Methods

CanReadToken(String)

Determines if the string is a well formed Json Web Token (JWT).

See: https://datatracker.ietf.org/doc/html/rfc7519

CreateClaimsIdentity(JsonWebToken, TokenValidationParameters)

Creates a ClaimsIdentity from a JsonWebToken.

CreateClaimsIdentity(JsonWebToken, TokenValidationParameters, String)

Creates a ClaimsIdentity from a JsonWebToken with the specified issuer.

CreateToken(SecurityTokenDescriptor)

Creates a JWt that can be a JWS or JWE.

CreateToken(String)

Creates an unsigned JWS (Json Web Signature).

CreateToken(String, EncryptingCredentials)

Creates a JWE (Json Web Encryption).

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

Creates a JWE (Json Web Encryption).

CreateToken(String, EncryptingCredentials, String)

Creates a JWE (Json Web Encryption).

CreateToken(String, IDictionary<String,Object>)

Creates an unsigned JWS (Json Web Signature).

CreateToken(String, SigningCredentials)

Creates a JWS (Json Web Signature).

CreateToken(String, SigningCredentials, EncryptingCredentials)

Creates a JWE (Json Web Encryption).

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

Creates a JWE (Json Web Encryption).

CreateToken(String, SigningCredentials, EncryptingCredentials, String)

Creates a JWE (Json Web Encryption).

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

Creates a JWE (Json Web Encryption).

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

Creates a JWE (Json Web Encryption).

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

Creates a JWS (Json Web Signature).

DecryptToken(JsonWebToken, TokenValidationParameters)

Decrypts a JWE and returns the clear text

EncryptToken(String, EncryptingCredentials)

Encrypts a JWS.

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

Encrypts a JWS.

EncryptToken(String, EncryptingCredentials, String)

Encrypts a JWS.

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

Encrypts a JWS.

ReadJsonWebToken(String)

Converts a string into an instance of JsonWebToken.

ReadToken(String)

Converts a string into an instance of JsonWebToken.

ResolveTokenDecryptionKey(String, JsonWebToken, TokenValidationParameters)

Returns a SecurityKey to use when decrypting a JWE.

ValidateToken(String, TokenValidationParameters)
Obsolete.

Validates a JWS or a JWE.

ValidateTokenAsync(SecurityToken, TokenValidationParameters)

Validates a token. On a validation failure, no exception will be thrown; instead, the exception will be set in the returned TokenValidationResult.Exception property. Callers should always check the TokenValidationResult.IsValid property to verify the validity of the result.

ValidateTokenAsync(String, TokenValidationParameters)

Validates a token. On a validation failure, no exception will be thrown; instead, the exception will be set in the returned TokenValidationResult.Exception property. Callers should always check the TokenValidationResult.IsValid property to verify the validity of the result.

Applies to