gwt

Encode and decode JWTs.

Package Version Hex Docs

Quickstart

import gwt.{type Jwt, type Verified, type Unverified}

pub fn main() {
  let jwt_builder = 
    gwt.new()
    |> gwt.set_subject("1234567890")
    |> gwt.set_audience("0987654321")
    |> gwt.set_not_before(1_704_043_160)
    |> gwt.set_expiration(1_704_046_160)
    |> gwt.set_jwt_id("2468")

  let jwt_without_signature = gwt.to_string(jwt)
  let jwt_with_signature = gwt.to_signed_string(jwt, gwt.HS256, "lucy")

  let assert Ok(unverified_jwt) = 
    jwt_without_signature
    |> gwt.from_string()

  let assert Ok(verified_jwt) = 
    jwt_with_signature
    |>gwt.from_signed_string("lucy")
}

Installation

gleam add gwt 

The documentation can be found at https://hexdocs.pm/gwt.

Search Document