Class JwtValidator
- Namespace
- JWT
- Assembly
- Coherence.JWT.dll
Jwt validator.
public sealed class JwtValidator : IJwtValidator
- Inheritance
-
JwtValidator
- Implements
Constructors
JwtValidator(IJsonSerializer, IDateTimeProvider)
Creates an instance of JwtValidator
public JwtValidator(IJsonSerializer jsonSerializer, IDateTimeProvider dateTimeProvider)
Parameters
jsonSerializer
IJsonSerializerThe JSON serializer
dateTimeProvider
IDateTimeProviderThe DateTime provider
JwtValidator(IJsonSerializer, IDateTimeProvider, ValidationParameters)
Creates an instance of JwtValidator with time margin
public JwtValidator(IJsonSerializer jsonSerializer, IDateTimeProvider dateTimeProvider, ValidationParameters valParams)
Parameters
jsonSerializer
IJsonSerializerThe JSON serializer
dateTimeProvider
IDateTimeProviderThe DateTime provider
valParams
ValidationParametersValidation parameters that are passed on to JwtValidator
JwtValidator(IJsonSerializer, IDateTimeProvider, ValidationParameters, IBase64UrlEncoder)
Creates an instance of JwtValidator with time margin
public JwtValidator(IJsonSerializer jsonSerializer, IDateTimeProvider dateTimeProvider, ValidationParameters valParams, IBase64UrlEncoder urlEncoder)
Parameters
jsonSerializer
IJsonSerializerThe JSON serializer
dateTimeProvider
IDateTimeProviderThe DateTime provider
valParams
ValidationParametersValidation parameters that are passed on to JwtValidator
urlEncoder
IBase64UrlEncoderThe base64 URL Encoder
Methods
GetValidationException(JwtParts)
public Exception GetValidationException(JwtParts parts)
Parameters
parts
JwtParts
Returns
GetValidationException(byte[])
public Exception GetValidationException(byte[] bytes)
Parameters
bytes
byte[]
Returns
TryValidate(string, IAsymmetricAlgorithm, byte[], byte[], out Exception)
Given the JWT, verifies its signatures correctness without throwing an exception but returning it instead.
public bool TryValidate(string payloadJson, IAsymmetricAlgorithm alg, byte[] bytesToSign, byte[] decodedSignature, out Exception ex)
Parameters
payloadJson
stringAn arbitrary payload (already serialized to JSON)
alg
IAsymmetricAlgorithmThe asymmetric algorithm to validate with
bytesToSign
byte[]The header and payload bytes to validate
decodedSignature
byte[]The decodedSignatures to validate with
ex
ExceptionValidation exception, if any
Returns
- bool
True if exception is JWT is valid and exception is null, otherwise false
Exceptions
TryValidate(string, string, string, out Exception)
Given the JWT, verifies its signature correctness without throwing an exception but returning it instead.
public bool TryValidate(string payloadJson, string signature, string decodedSignature, out Exception ex)
Parameters
payloadJson
stringAn arbitrary payload (already serialized to JSON)
signature
stringDecoded body
decodedSignature
stringThe signature to validate with
ex
ExceptionThe resulting validation exception, if any
Returns
- bool
Returns
true
if exception is JWT is valid and exception is null, otherwise false
Exceptions
TryValidate(string, string, string[], out Exception)
Given the JWT, verifies its signature correctness without throwing an exception but returning it instead.
public bool TryValidate(string payloadJson, string signature, string[] decodedSignature, out Exception ex)
Parameters
payloadJson
stringAn arbitrary payload (already serialized to JSON)
signature
stringDecoded body
decodedSignature
string[]The signatures to validate with
ex
ExceptionThe resulting validation exception, if any
Returns
- bool
Returns
true
if exception is JWT is valid and exception is null, otherwise false
Exceptions
Validate(string, IAsymmetricAlgorithm, byte[], byte[])
Given the JWT, verifies its signature correctness.
public void Validate(string decodedPayload, IAsymmetricAlgorithm alg, byte[] bytesToSign, byte[] decodedSignature)
Parameters
decodedPayload
stringAn arbitrary payload (already serialized to JSON)
alg
IAsymmetricAlgorithmThe asymmetric algorithm to validate with
bytesToSign
byte[]The header and payload bytes to validate
decodedSignature
byte[]The signature to validate with
Remarks
Used by the asymmetric algorithms only.
Exceptions
Validate(string, string, params string[])
Given the JWT, verifies its signature correctness.
public void Validate(string decodedPayload, string signature, params string[] decodedSignatures)
Parameters
decodedPayload
stringAn arbitrary payload (already serialized to JSON)
signature
stringDecoded body
decodedSignatures
string[]The signatures to validate with