package jwto

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

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.5.tar.gz
md5=9e3dacf9428266df7c37376ae4ebf4dd
sha512=82da5a4a06c9716396cfad274f708d1f6b4639a9789dae9c95a16a66aed9c095bca6497c659abb2e95a8761251932855e6688f696793e8843c7b7c559d2beda1

Description

Published: 17 Nov 2018

README

Ocaml JWT

Create a token

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

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

Jwt.make Jwt.HS256 "secret" payload

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

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

Encode token

Jwt.encode Jwt.HS256 "secret" payload

-->

"eyJhbGciOiJIUzI1NiJ9...."

Decode token

Just decode the token, doesn't verify.

Jwt.decode "eyJhbGciOiJIUzI1NiJ9...."

-->

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

Decode and verify

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

Jwt.decode_and_verify "secret" "eyJhbGciOiJIUzI1NiJ9...."

-->

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

Verify only

Jwt.is_valid "secet" "eyJhbGciOiJIUzI1NiJ9...."

-->

true

Dev Dependencies (1)

  1. alcotest with-test

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.