Table of Contents

Class JwtDecoder

Namespace
JWT
Assembly
Coherence.JWT.dll

Decodes JWT.

public sealed class JwtDecoder : IJwtDecoder
Inheritance
JwtDecoder
Implements
Extension Methods

Constructors

JwtDecoder(IJsonSerializer, IBase64UrlEncoder)

Creates an instance of JwtDecoder

public JwtDecoder(IJsonSerializer jsonSerializer, IBase64UrlEncoder urlEncoder)

Parameters

jsonSerializer IJsonSerializer

The JSON serializer

urlEncoder IBase64UrlEncoder

The base64 URL encoder

Remarks

This overload supplies no IJwtValidator and no IAlgorithmFactory so the resulting decoder cannot be used for signature validation.

Exceptions

ArgumentNullException

JwtDecoder(IJsonSerializer, IJwtValidator, IBase64UrlEncoder, IAlgorithmFactory)

Creates an instance of JwtDecoder

public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder, IAlgorithmFactory algFactory)

Parameters

jsonSerializer IJsonSerializer

The JSON serializer

jwtValidator IJwtValidator

The JWT validator

urlEncoder IBase64UrlEncoder

The base64 URL encoder

algFactory IAlgorithmFactory

The JWT algorithm Factory

Exceptions

ArgumentNullException

JwtDecoder(IJsonSerializer, IJwtValidator, IBase64UrlEncoder, IJwtAlgorithm)

Creates an instance of JwtDecoder

public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder, IJwtAlgorithm algorithm)

Parameters

jsonSerializer IJsonSerializer

The JSON serializer

jwtValidator IJwtValidator

The JWT validator

urlEncoder IBase64UrlEncoder

The base64 URL encoder

algorithm IJwtAlgorithm

The JWT algorithm

Exceptions

ArgumentNullException

Methods

Decode(JwtParts, bool)

Given a JWT, decodes it and return the payload.

public string Decode(JwtParts jwt, bool verify)

Parameters

jwt JwtParts

The JWT

verify bool

Whether to verify the signature (default is true)

Returns

string

A string containing the JSON payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
InvalidTokenPartsException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

Decode(JwtParts, byte[], bool)

Given a JWT, decodes it and return the payload.

public string Decode(JwtParts jwt, byte[] key, bool verify)

Parameters

jwt JwtParts

The JWT

key byte[]

The key that were used to sign the JWT

verify bool

Whether to verify the signature (default is true)

Returns

string

A string containing the JSON payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
InvalidTokenPartsException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

Decode(JwtParts, byte[][], bool)

Given a JWT, decodes it and return the payload.

public string Decode(JwtParts jwt, byte[][] keys, bool verify)

Parameters

jwt JwtParts

The JWT

keys byte[][]

The keys provided which one of them was used to sign the JWT

verify bool

Whether to verify the signature (default is true)

Returns

string

A string containing the JSON payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

DecodeHeader(string)

Given a JWT, decodes it and return the header.

public string DecodeHeader(string token)

Parameters

token string

The JWT

Returns

string

Exceptions

ArgumentException
InvalidTokenPartsException
FormatException

DecodeHeader<T>(JwtParts)

Given a JWT, decodes it and return the header as an object.

public T DecodeHeader<T>(JwtParts jwt)

Parameters

jwt JwtParts

The JWT

Returns

T

Type Parameters

T

Exceptions

ArgumentException
ArgumentNullException
FormatException

DecodeToObject(Type, JwtParts, bool)

Given a JWT, decodes it and return the payload as an object.

public object DecodeToObject(Type type, JwtParts jwt, bool verify)

Parameters

type Type

The type to deserialize to.

jwt JwtParts

The JWT

verify bool

Whether to verify the signature (default is true)

Returns

object

An object representing the payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

DecodeToObject(Type, JwtParts, byte[], bool)

Given a JWT, decodes it and return the payload as an object.

public object DecodeToObject(Type type, JwtParts jwt, byte[] key, bool verify)

Parameters

type Type

The type to deserialize to.

jwt JwtParts

The JWT

key byte[]

The key that was used to sign the JWT

verify bool

Whether to verify the signature (default is true)

Returns

object

An object representing the payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

DecodeToObject(Type, JwtParts, byte[][], bool)

Given a JWT, decodes it and return the payload as an object.

public object DecodeToObject(Type type, JwtParts jwt, byte[][] keys, bool verify)

Parameters

type Type

The type to deserialize to.

jwt JwtParts

The JWT

keys byte[][]

The keys which one of them was used to sign the JWT

verify bool

Whether to verify the signature (default is true)

Returns

object

An object representing the payload

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

Validate(JwtParts, params byte[][])

Prepares data before calling IJwtValidator

public void Validate(JwtParts jwt, params byte[][] keys)

Parameters

jwt JwtParts

The JWT parts

keys byte[][]

The keys provided which one of them was used to sign the JWT

Exceptions

ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

Validate(string[], byte[])

Prepares data before calling IJwtValidator

public void Validate(string[] parts, byte[] key)

Parameters

parts string[]

The array representation of a JWT

key byte[]

The key that was used to sign the JWT

Exceptions

ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException

Validate(string[], params byte[][])

Prepares data before calling IJwtValidator

public void Validate(string[] parts, params byte[][] keys)

Parameters

parts string[]

The array representation of a JWT

keys byte[][]

The keys provided which one of them was used to sign the JWT

Exceptions

ArgumentNullException
ArgumentOutOfRangeException
FormatException
SignatureVerificationException
TokenNotYetValidException
TokenExpiredException