package jwto

  1. Overview
  2. Docs
JWT encoding, decoding and verification

Install

Dune Dependency

Authors

Maintainers

Sources

0.3.0.tar.gz
md5=cc238a4a7d319d37579a930912a68d04
sha512=cd89bc9d2fedc483329ca328fd8895bd49b24f171d8cef27fe34a28612cbbdc88eff7babc810c7967c310aa8056fdfef08bf0693c27e6541a649507b8c7963bb

Description

Published: 16 Jun 2020

README

Ocaml JWT

Create a token

A payload is a list of tuples (string, string):

let payload =
  [
    ("user", "sam);
    ("age", "17");
  ]

Jwto.make Jwto.HS256 "secret" payload

Jwto.make returns a signed token (type Jwto.t):

{
  header = ...;
  payload = [...]; 
  signature = ...;
}

Encode token

Jwto.encode Jwto.HS256 "secret" payload

-->

"eyJhbGciOiJIUzI1NiJ9...."

Decode token

Just decode the token, doesn't verify.

Jwto.decode "eyJhbGciOiJIUzI1NiJ9...."

-->

Ok { header = ...; payload = [...]; signature = ... }	

Decode and verify

Verify and decode. If the verification fails you will get an Error.

Jwto.decode_and_verify "secret" "eyJhbGciOiJIUzI1NiJ9...."

-->

Ok { header = ...; payload = [...]; signature = ... }

Verify only

Jwto.is_valid "secet" "eyJhbGciOiJIUzI1NiJ9...."

-->

true

Dependencies (8)

  1. ppx_deriving >= "4.2"
  2. re >= "1.8"
  3. base64 >= "3.1"
  4. yojson >= "1.6"
  5. fmt >= "0.8"
  6. cryptokit >= "1.10"
  7. dune >= "1.7"
  8. ocaml >= "4.05"

Dev Dependencies (1)

  1. alcotest with-test

Used by (2)

  1. sihl < "0.2.0" | >= "0.3.0~rc2"
  2. sihl-core

Conflicts

None

OCaml

Innovation. Community. Security.