JWT Library for Erlang.
Written by Peter Hizalev at Kato (http://kato.im)
Rewritten by Yuri Artemev (http://artemff.com)
expiration() = {hourly, non_neg_integer()} | {daily, non_neg_integer()} | non_neg_integer()
decode/2 | Decodes a token, checks the signature and returns the content of the token. |
decode/3 | Decode with an issuer key mapping. |
encode/3 | Creates a token from given data and signs it with a given secret. |
encode/4 | Creates a token from given data and signs it with a given secret. |
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(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(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(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