Einhugur JWT Plugin |

# EinhugurJWT.Decode Method

Decodes and validates JSON Web Token.

Decode(
params as EinhugurJWT.DecodingParameters,
getClaims as Boolean) as EinhugurJWT.JWTResult

#### Parameters

params
  Parameters to specify how to decode and what to validate.
getClaims
  Set to true if also wanting to get claims.

#### Returns

EinhugurJWT.JWTResult
  JWTResult instance or exception is thrown.

#### Remarks

This function can throw JWTException.
try
var params as new EinhugurJWT.DecodingParameters()
params.Algorithm = EinhugurJWT.Algorithm.HS512
params.JWT =TextArea1.Text
params.VerificationKey = "Some SupER s3kret HMAC keY"
params.ValidateSubject = "Bjorn Eiriksson"
params.ValidateIssuer = "Einhugur"
params.ValidateExpiration = true
params.ExpirationToleranceSeconds = 60
params.ValidateIssuedAt = true
params.IssuedAtToleranceSeconds = 60
var result as EinhugurJWT.JWTResult = EinhugurJWT.Decode(params, true)
if result.ValidationResult = result.ResultValid then
MessageBox "Token is valid."
for each claim as EinhugurJWT.Claim in result.Claims
MessageBox claim.Key + " - " + claim.Value
next
else
// The result is bitmask and we can have multiple faults which is why we will not be using elseif here.
if (result.ValidationResult and result.ResultTokenIsExpired) = result.ResultTokenIsExpired then
MessageBox "Token has expired."
end if
if (result.ValidationResult and result.ResultTokenIsNotYetValid) = result.ResultTokenIsNotYetValid then
MessageBox "The token is not yet valid."
end if
if (result.ValidationResult and result.ResultTokenNotIssuedYet) = result.ResultTokenNotIssuedYet then
MessageBox "The token has not been issued yet, are you from the future?"
end if
if (result.ValidationResult and result.ResultAudienceClaimInvalid) = result.ResultAudienceClaimInvalid then
MessageBox "The audience claim is invalid."
end if
if (result.ValidationResult and result.ResultIdClaimInvalid) = result.ResultIdClaimInvalid then
MessageBox "The JWT ID claim is invalid."
end if
if (result.ValidationResult and result.ResultIssuerClaimInvalid) = result.ResultIssuerClaimInvalid then
MessageBox "The issuer claim is invalid."
end if
if (result.ValidationResult and result.ResultSignatureVerificationFailure) = result.ResultSignatureVerificationFailure then
MessageBox "The token was potentially tampered with: its signature couldn't be verified."
end if
if (result.ValidationResult and result.ResultSubjectClaimInvalid) = result.ResultSubjectClaimInvalid then
MessageBox "The subject claim is invalid."
end if
if (result.ValidationResult and result.ResultTypeClaimFailure) = result.ResultTypeClaimFailure then
MessageBox "The token's ""typ"" claim validation failed."
end if
end if
catch ex as EinhugurJWT.JWTException
MessageBox(ex.Message)
end try

#### Supported Platforms:

- macOS Intel 64 bit
- macOS Apple Silicon
- Windows 32 bit
- Windows 64 bit
- Windows ARM 64 bit
- Linux 32 bit
- Linux 64 bit
- Linux ARM 32 bit
- Linux ARM 64 bit
- iOS

#### See Also

EinhugurJWT Module