JonRowe / elm-jwt / 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 : Json.Decode.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 : Json.Decode.Decoder a -> Json.Decode.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 : Time.Posix -> String -> Result JwtError Basics.Bool

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

checkTokenExpiry : String -> Task Basics.Never JwtError

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

Error handlers


type JwtError
    = Unauthorized
    | TokenExpired
    | TokenNotExpired
    | TokenProcessingError String
    | TokenDecodeError Json.Decode.Error

The following errors are modeled