Skip to content

Latest commit

 

History

History
120 lines (65 loc) · 3.35 KB

jwt.md

File metadata and controls

120 lines (65 loc) · 3.35 KB

Module jwt

JWT Library for Erlang.

Description

Written by Peter Hizalev at Kato (http://kato.im)

Rewritten by Yuri Artemev (http://artemff.com)

Data Types


expiration() = {hourly, non_neg_integer()} | {daily, non_neg_integer()} | non_neg_integer()

Function Index

decode/2Decodes a token, checks the signature and returns the content of the token.
decode/3Decode with an issuer key mapping.
encode/3Creates a token from given data and signs it with a given secret.
encode/4Creates a token from given data and signs it with a given secret.

Function Details

decode/2


decode(Token::binary(), Key::binary() | public_key:public_key() | public_key:private_key()) -> {ok, Claims::map()} | {error, any()}

Decodes a token, checks the signature and returns the content of the token

  • Token is a JWT itself

  • Key is a secret phrase or public/private key depend on encryption algorithm

decode/3


decode(Token::binary(), DefaultKey::binary() | public_key:public_key() | public_key:private_key(), IssuerKeyMapping::map()) -> {ok, Claims::map()} | {error, any()}

Decode with an issuer key mapping

Receives the issuer key mapping as the last parameter

encode/3


encode(Alg::binary(), ClaimsSet::map() | list(), Key::binary() | public_key:private_key()) -> {ok, Token::binary()} | {error, any()}

Creates a token from given data and signs it with a given secret

Parameters are

Alg is a binary one of

[HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512]

But only [HS256, HS384, HS512, RS256] are supported

  • ClaimsSet the payload of the token. Can be both map and proplist

  • Key binary in case of hmac encryption and private key if rsa

encode/4


encode(Alg::binary(), ClaimsSet::map() | list(), Expiration::expiration(), Key::binary() | public_key:private_key()) -> {ok, Token::binary()} | {error, any()}

Creates a token from given data and signs it with a given secret

and also adds exp claim to payload

Expiration can be one of the tuples: {hourly, SecondsAfterBeginningOfCurrentHour}, {daily, SecondsAfterBeginningOfCurrentDay} or can be just an integer representing the amount of seconds the token will live