A collection of functions to decode Jwt tokens, and to use them for authenticated CRUD requests.
A Jwt is a Base64 string that has three parts
The library functions decodeToken
and tokenDecoder
provide the means to decode the content of a token, while checkTokenExpiry
and isExpired
specifically analyse whether the token remains within its expiry time.
The library also provides modified versions of thet standard Http functions to make CRUD requests with the Authorization header set to "bearer
let
url =
"http://example.com/new"
body =
Http.jsonBody <some Value>
in
Jwt.Http.post token { url = url, body = body, expect = Http.expectJson OnData (Json.Decode.field "confirmation" Json.Decode.string) }
An example with a Node backend is provided.
I previous blogged about using elm-jwt with Phoenix.
Task JwtError String
rather than Task never (Result JwtError String)
. It is better to leave it to the user to handle the conversion to a Cmd. Elm 0.16 users should use version 1.0.2.