Functions - jwt

buildHeaderString
Builds the header string from the jwt:JwtHeader record.
buildPayloadString
Builds the payload string from the jwt:JwtPayload record.
decodeJwt
Decodes the given JWT string.
issueJwt
Issues a JWT based on the provided header and payload.
validateJwt
Validates the given JWT string.

buildHeaderString

(JwtHeader header)

returns string | Error

Builds the header string from the jwt:JwtHeader record.

 string|jwt:Error jwtHeader = buildHeaderString(header);

Parameters

  • header JwtHeader
  • JWT header record to be built as a string

  • Return Type

    (string | Error)
  • The header string or else a jwt:Error if building the string fails

buildPayloadString

(JwtPayload payload)

returns string | Error

Builds the payload string from the jwt:JwtPayload record.

 string|jwt:Error jwtPayload = jwt:buildPayloadString(payload);

Parameters

  • payload JwtPayload
  • JWT payload record to be built as a string

  • Return Type

    (string | Error)
  • The payload string or else a jwt:Error if building the string fails

decodeJwt

(string jwt)

returns [JwtHeader, JwtPayload] | Error

Decodes the given JWT string.

 [jwt:JwtHeader, jwt:JwtPayload]|jwt:Error [header, payload] = jwt:decodeJwt(jwt);

Parameters

  • jwt string
  • JWT that needs to be decoded

  • Return Type

    ([JwtHeader, JwtPayload] | Error)
  • The JWT header and payload tuple or else a jwt:Error if token decoding fails

issueJwt

(JwtHeader header, JwtPayload payload, JwtKeyStoreConfig? config)

returns string | Error

Issues a JWT based on the provided header and payload. JWT will be signed (JWS) if crypto:KeyStore information is provided in the jwt:JwtKeyStoreConfig and the alg field of the jwt:JwtHeader is not jwt:NONE.

 string|jwt:Error jwt = jwt:issueJwt(header, payload, keyStoreConfig);

Parameters

  • Return Type

    (string | Error)
  • JWT as a string or else a jwt:Error if token validation fails

validateJwt

(string jwt, JwtValidatorConfig config)

returns JwtPayload | Error

Validates the given JWT string.

 jwt:JwtPayload|jwt:Error result = jwt:validateJwt(jwt, validatorConfig);

Parameters

  • jwt string
  • JWT that needs to be validated

  • Return Type

    (JwtPayload | Error)
  • JWT payload or else a jwt:Error if token validation fails