Helper functions for working with Jwt tokens
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
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 bodyTokenHeaderError
- the header is corrupted in some wayerrorToString : JwtError -> String
Provides a default conversion of a JwtError to a string