/jwto

ocaml-jwt

Primary LanguageOCamlMIT LicenseMIT

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