Packages

A compliant and complete implementation of PASETO and PASERK.

Current section

Files

Jump to
pasexto README.md
Raw

README.md

# PASExTO
[![Hex.pm](https://img.shields.io/hexpm/v/pasexto.svg)](https://hex.pm/packages/pasexto) [![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/pasexto/)
A compliant and complete implementation of [PASETO](https://github.com/paseto-standard/paseto-rfc) and [PASERK](https://github.com/paseto-standard/paserk).
## Requirements
This library makes use of OTP's `:crypto` module where applicable, and fills in any gaps using Zig's standard library.
As a result, Zig's build tools are required in order to use this library.
## Installation
Add `:pasexto` to the list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:pasexto, "~> 0.1.0"}
]
end
```
## Usage
Below are some examples of how to use this library:
```elixir
# Building and parsing a local token
key = Pasexto.Key.new(:v4, :local)
claims = %{"hello" => "world"}
footer = <<>>
{:ok, paseto, claims} = Pasexto.build(:v4, :local, key, claims, footer)
{:ok, ^claims, ^footer} = Pasexto.parse(:v4, :local, key, paseto)
# Building and parsing a public token
key = Pasexto.Key.new(:v4, :public)
claims = %{"hello" => "world"}
footer = <<>>
{:ok, paseto, claims} = Pasexto.build(:v4, :public, key, claims, footer)
{:ok, ^claims, ^footer} = Pasexto.parse(:v4, :public, key, paseto)
# Using a keyring
key = Pasexto.Key.new(:v4, :local)
keyring = Pasexto.Keyring.new(:v4, :local) |> Pasexto.Keyring.put("key1", key)
claims = %{"hello" => "world"}
footer = %{"kid" => "key1"}
{:ok, paseto, claims} = Pasexto.build(:v4, :local, keyring, claims, footer)
{:ok, ^claims, ^footer} = Pasexto.parse(:v4, :local, keyring, paseto)
# Using PASERK
key = Pasexto.Key.new(:v4, :local)
{:ok, kid} = Pasexto.Paserk.build(:k4, :lid, key)
keyring = Pasexto.Keyring.new(:v4, :local) |> Pasexto.Keyring.put(kid, key)
claims = %{"hello" => "world"}
footer = %{"kid" => kid}
{:ok, paseto, claims} = Pasexto.build(:v4, :local, keyring, claims, footer)
{:ok, ^claims, ^footer} = Pasexto.parse(:v4, :local, keyring, paseto)
```
## Running Tests
Clone the repo and fetch its dependencies:
```bash
$ git clone https://github.com/alexkornitzer/pasexto.git
$ cd pasexto
$ mix deps.get
$ mix test
```