JonRowe/elm-jwt/1.0.0

Jwt

Helper functions for working with Jwt tokens and authenticated CRUD APIs.

This package provides functions for reading tokens, and for using them to make authenticated Http requests.

Token reading

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

decodeToken parses the token, checking that it meets the Jwt standards.

decodeToken dec token

In the event of success, decodeToken returns an Elm record structure using the JSON Decoder.

tokenDecoder : Decoder a -> Decoder a

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

-- decode token from Firebase
let firebaseToken =
        decodeString (tokenDecoder Jwt.Decoders.firebase) tokenString
isExpired : Posix -> String -> Result JwtError Bool

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

checkTokenExpiry : String -> Task Never JwtError

Checks a token for Expiry. Returns expiry or any errors that occurred in decoding.

Error handlers

= Unauthorized
| TokenExpired
| TokenNotExpired
| TokenProcessingError String
| TokenDecodeError Error

The following errors are modeled

  • 401 (Unauthorized), due either to token expiry or e.g. inadequate permissions
  • token (non-)expiry information
  • issues with processing (e.g. base 64 decoding) the token
  • problems decoding the json data within the content of the token
  • Any Http.Error, other than a 401