Json Web Token (JWT) helper functions for Elm
Clone or download
Latest commit 2ae7bf3 Aug 25, 2018
Permalink
Failed to load latest commit information.
examples update deps Aug 25, 2018
src remove local base64 code Aug 25, 2018
.gitignore remove local base64 code Aug 25, 2018
LICENSE Create LICENSE Jun 18, 2017
README.md update readme Aug 25, 2018
elm-package.json updates for RC1 Jul 22, 2018
elm.json bump Aug 25, 2018
release.sh Bump to 5.3.0 Dec 31, 2017

README.md

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

* header
* content
* signature

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 Elm standard Http functions to make CRUD requests with the Authorization header set to "bearer "

let
    url =
        "http://example.com/new"
    body =
        jsonBody <some Value>
in
    Jwt.post token url body (Json.Decode.field "confirmation" Json.Decode.string)

Examples

Examples are included of the software working with Phoenix and Node backends. More discussion of the Phoenix example can be found in this blog post.

Changelog

  • 6.0.0: 0.19
  • 5.3.0: Adds decoder got Elixir-Guardian token
  • 5.2.0: Update NodeJS example
  • 5.1.0: Adds a decoder for the Firebase Jwt.
  • 5.0.0 (Elm 0.18): Corrects a typo in name of checkTokenExpiry and separates out createRequestObject
  • 4.0.0 (Elm 0.18): Elm's Http library has undergone a major rewrite for 0.18 and this library depends upon it. As a result much has changed and you are encouraged to re-look at the examples and the docs.
  • 3.0.0 (Elm 0.18): Elm 0.17 users should use version 2.0.0.
  • 2.0.0 (Elm 0.17): The one breaking change is that authenticate now returns 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.