View Source JWT (yajwt v1.4.1)
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
Link to this section Summary
Functions
Return a JSON Web Token (JWT), a string representing a set of claims as a JSON object that is encoded in a JWS
Given an options map, return a map of header options
Return a tuple {:ok, claims (map)} if the JWT signature is verified, or {:error, exception} otherwise
Link to this section Functions
Return a JSON Web Token (JWT), a string representing a set of claims as a JSON object that is encoded in a JWS
example
Example
iex> claims = %{iss: "joe", exp: 1300819380, "http://example.com/is_root": true}
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JWT.sign(claims, key: key)
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlLCJpc3MiOiJqb2UifQ.C5kby-t7W1CM1VB_avPCCHbtOXsNsywYAKYex8rHZh8"
Given an options map, return a map of header options
example
Example
iex> JWT.unify_header(alg: "RS256", key: "key")
%{typ: "JWT", alg: "RS256"}
Filters out unsupported claims options and ignores any encryption keys
Return a tuple {:ok, claims (map)} if the JWT signature is verified, or {:error, exception} otherwise
example
Example
iex> jwt ="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiam9lIiwiaHR0cDovL2V4YW1wbGUuY29tL2lzX3Jvb3QiOnRydWUsImRhdGV0aW1lIjoxMzAwODE5MzgwfQ.8CbXtOJ51MfPLlNTDpMMBHExFZGmqIC2c_hjuY0Dp24"
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JWT.verify(jwt, %{key: key})
{:ok, %{"name" => "joe", "datetime" => 1300819380, "http://example.com/is_root" => true}}
iex> jwt ="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiam9lIiwiaHR0cDovL2V4YW1wbGUuY29tL2lzX3Jvb3QiOnRydWUsImRhdGV0aW1lIjoxMzAwODE5MzgwfQ.8CbXtOJ51MfPLlNTDpMMBHExFZGmqIC2c_hjuY0Dp24"
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JWT.verify(jwt, %{key: key, decode: [keys: :atoms]})
{:ok, %{datetime: 1300819380, "http://example.com/is_root": true, name: "joe"}}