simonh1000/elm-jwt/7.0.0

NOTE: the latest version is 7.1.1

Jwt

Helper functions for working with Jwt tokens

Token reading

decodeToken : Decoder a -> String -> Result JwtError a

Parses the token, checking that it meets the Jwt standards. In the event of success, decodeToken returns result of the JSON Decoder.

decodeToken dec token
tokenDecoder : Decoder a -> Decoder a

All the token parsing goodness in the form of a Json Decoder

firebaseToken =
    Json.Decode.decodeString (tokenDecoder Jwt.Decoders.firebase) tokenString
checkTokenExpiry : String -> Task JwtError Bool

Checks a token for Expiry (used the "exp" field). Returns expiry or any error that occurred in processing.

isExpired : Posix -> String -> Result JwtError Bool

Checks whether a token has expired, and returns True or False, or any error that occurred while processing the token.

getTokenHeader : String -> Result JwtError String

Returns stringified json of the token's header

Errors

= TokenProcessingError String
| TokenDecodeError Error
| TokenHeaderError

The following errors are modeled

  • TokenProcessingError - something wrong with the the raw token (e.g. length, base64 encoding)
  • TokenDecodeError - the token is not valid JSON or the decoder provided could not decode the body
  • TokenHeaderError - the header is corrupted in some way

Provides a default conversion of a JwtError to a string