https://github.com/simonh1000/elm-jwt
Json Web Token (JWT) helper functions for Elm
https://github.com/simonh1000/elm-jwt
Last synced: about 2 months ago
JSON representation
Json Web Token (JWT) helper functions for Elm
- Host: GitHub
- URL: https://github.com/simonh1000/elm-jwt
- Owner: simonh1000
- License: mit
- Created: 2016-01-15T15:36:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-27T10:32:08.000Z (almost 3 years ago)
- Last Synced: 2025-03-20T19:28:43.481Z (2 months ago)
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/simonh1000/elm-jwt/latest
- Size: 1.84 MB
- Stars: 94
- Watchers: 3
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm helpers for working with Jwt tokens.
A collection of functions to decode [Jwt tokens](https://jwt.io/), and to use them for authenticated CRUD requests.
## Decode a token
A Jwt is a Base64 string that has three parts
- header
- content
- signatureThe 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
in
Jwt.Http.post token { url = url, body = body, expect = Http.expectJson OnData (Json.Decode.field "confirmation" Json.Decode.string) }## Examples
An [example](https://github.com/simonh1000/elm-jwt/tree/master/examples/node) with a Node backend is provided.
I previous blogged about using [elm-jwt with Phoenix](http://simonh1000.github.io/2016/05/phoenix-elm-json-web-tokens/).
## Changelog
* 7.1.1: (0.19.1) Use faster Base64 library (thanks Petre)
* 7.1.0: (0.19) Expose getTokenExpirationMillis (thanks robx)
* 7.0.0: (0.19) Http 2.0.0 necessitated major changes. I took the opportunity to simplify my code and the JwtError type in particular. All token processing functions now also do a cursory check that the header is valid json
* 6.0.0: (0.19) Update
* 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 (0.18): Corrects a typo in name of checkTokenExpiry and separates out createRequestObject
* 4.0.0 (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](http://package.elm-lang.org/packages/simonh1000/elm-jwt/latest/Jwt).
* 3.0.0 (0.18): Elm 0.17 users should use version 2.0.0.
* 2.0.0 (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.