simonh1000 / elm-jwt / Jwt

Helper functions for working with Jwt tokens

Token reading

decodeToken : Json.Decode.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 : Json.Decode.Decoder a -> Json.Decode.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 Basics.Bool

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

getTokenExpirationMillis : String -> Result JwtError Basics.Int

Extracts the token expiration timestamp from the JWT "exp" field. Returns the timestamp in milliseconds since epoch, or any error that occurred while processing the token.

isExpired : Time.Posix -> String -> Result JwtError Basics.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


type JwtError
    = TokenProcessingError String
    | TokenDecodeError Json.Decode.Error
    | TokenHeaderError

The following errors are modeled

errorToString : JwtError -> String

Provides a default conversion of a JwtError to a string