georgesboris/elm-jwt/1.0.0

Rerouted (archive, verified). The original repository is gone. This copy comes from an archive (Software Heritage). The Lamdera package server serves a copy recovered from swh:1:rev:6e42bbcb75707ce44273d810b1c9b2ec2eb20c4c (Software Heritage, origin https://github.com/georgesboris/elm-jwt).

What we checked: Software Heritage archived tag 1.0.0 of github.com/georgesboris/elm-jwt at commit 6e42bbcb7570; its commit 6e42bbcb7570 is from 2023-08-16 18:53 UTC, before the version was published (2023-08-16 18:54 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip is our own, made from Software Heritage's copy of the files Elm uses, so its SHA-1 is not the published one.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/georgesboris/elm-jwt/zipball/1.0.0/

JsonWebToken

JSON Web Token encoder and decoder.

Decoder payload
-> Secret
-> Token
-> Result (DecodeError payload) payload

Verify a token given a secret or public key.

import Json.Decode
import Json.Encode
import TestHelpers
    exposing
        ( aValidToken
        , correctSecret
        , encodePayload
        , payload
        , payloadDecoder
        , wrongSecret
        )

If all goes well, you'll get a result back with the payload.

decode payloadDecoder correctSecret aValidToken
--> Ok payload

If something goes wrong, you get an error:

decode payloadDecoder correctSecret "token.should.have.three.parts"
--> Err InvalidToken

Some errors will include the payload. However, whenever there is an error the payload should not be trusted.

decode payloadDecoder wrongSecret aValidToken
--> Err <| InvalidSecret payload
encode : Alg -> (payload -> Value) -> Secret -> payload -> Token

Create and sign a token.

import Json.Decode
import Json.Encode
import TestHelpers
    exposing
        ( aValidToken
        , correctSecret
        , encodePayload
        , payload
        , payloadDecoder
        , wrongSecret
        )


encode hmacSha256 encodePayload correctSecret payload
--> aValidToken


encode hmacSha512 Json.Encode.string "other secret" "some payload"
    |> (decode Json.Decode.string "other secret")
--> Ok "some payload"


encode hmacSha224 Json.Encode.int "123" 456
    |> (decode Json.Decode.int "abc")
--> Err <| InvalidSecret 456
-> (payload -> List ( String, Value ))
-> (payload -> Value)
-> Secret
-> payload
-> Token

Create and sign a token, optionally passing extra values to be included in your JWT header.

import Json.Decode
import Json.Encode
import TestHelpers
    exposing
        ( aValidTokenWithCustomHeaders
        , correctSecret
        , encodePayload
        , payload
        , payloadDecoder
        , wrongSecret
        )


encodeWithHeaders hmacSha256 (\payload -> [ ( "kid", Json.Encode.int payload.iat) ]) encodePayload correctSecret payload
--> aValidTokenWithCustomHeaders

Algorithms

HMAC SHA224 digest algorithm.

HMAC SHA256 digest algorithm.

HMAC SHA384 digest algorithm.

HMAC SHA512 digest algorithm.

Errors

type DecodeError payload
= DecodeHeaderFailed payload String
| DecodePayloadFailed String
| InvalidSecret payload
| InvalidToken

Types of errors which can occur during decoding of a token.

Types

type Alg

Type of algoirthm to use for the digest

type alias Secret =
String

String used to sign or verify a token.

  • In the case of signing, this can also be a private key.
  • In the case of verifying, this can also be a public key.
type alias Token =
String

A JSON web token.

algDecoder : Decoder Alg

Algorithm decoder.