simonh1000 / elm-jwt

Json Web Token (JWT) helper functions for Elm
http://package.elm-lang.org/packages/simonh1000/elm-jwt/latest
MIT License
94 stars 12 forks source link

Elm helpers for working with Jwt tokens.

A collection of functions to decode Jwt tokens, and to use them for authenticated CRUD requests.

Decode a token

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.

Make an authenticated CRUD request

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) }

Examples

An example with a Node backend is provided.

I previous blogged about using elm-jwt with Phoenix.

Changelog