JsonWebToken.Jwt
Encode claims for transmission as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure, enabling the claims to be integrity protected with a Message Authentication Code (MAC), to be later verified
Summary↑
| config_header(options) | Given an options map, return a map of header options |
| sign(claims, options) | Return a JSON Web Token (JWT), a string representing a set of claims as a JSON object that is encoded in a JWS |
| verify(jwt, options) | Return a JWT claims map if the JWT signature does verify, or an “Invalid” string otherwise |
Functions
Given an options map, return a map of header options
Example
iex> JsonWebToken.Jwt.config_header(alg: "RS256", key: "key")
%{typ: "JWT", alg: "RS256"}
Filters out unsupported claims options and ignores any encryption keys
Return a JSON Web Token (JWT), a string representing a set of claims as a JSON object that is encoded in a JWS
Example
iex> claims = %{iss: "joe", exp: 1300819380, "http://example.com/is_root": true}
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jwt.sign(claims, %{key: key})
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLCJodHRwOi8vZXhhbXBsZS5jb20vaXNfcm9vdCI6dHJ1ZSwiZXhwIjoxMzAwODE5MzgwfQ.Ktfu3EdLz0SpuTIMpMoRZMtZsCATWJHeDEBGrsZE6LI"
Return a JWT claims map if the JWT signature does verify, or an “Invalid” string otherwise
Example
iex> jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLCJodHRwOi8vZXhhbXBsZS5jb20vaXNfcm9vdCI6dHJ1ZSwiZXhwIjoxMzAwODE5MzgwfQ.Ktfu3EdLz0SpuTIMpMoRZMtZsCATWJHeDEBGrsZE6LI"
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jwt.verify(jwt, %{key: key})
%{iss: "joe", exp: 1300819380, "http://example.com/is_root": true}