json_web_token v0.2.10 JsonWebToken.Jws

Represent content to be secured with digital signatures or Message Authentication Codes (MACs)

see http://tools.ietf.org/html/rfc7515

Link to this section Summary

Functions

Return a JSON Web Signature (JWS), a string representing a digitally signed payload

Return a JWS that provides no integrity protection (i.e. lacks a signature)

Return a tuple {:ok, jws (string)} if the signature is verified, or {:error, “invalid”} otherwise

Link to this section Functions

Link to this function sign(header, payload, key)

Return a JSON Web Signature (JWS), a string representing a digitally signed payload

Example

iex> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jws.sign(%{alg: "HS256"}, "payload", key)
"eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"
Link to this function unsecured_message(header, payload)

Return a JWS that provides no integrity protection (i.e. lacks a signature)

Example

iex> JsonWebToken.Jws.unsecured_message(%{alg: "none"}, "payload")
"eyJhbGciOiJub25lIn0.cGF5bG9hZA."

see http://tools.ietf.org/html/rfc7515#page-47

Link to this function verify(jws, algorithm, key \\ nil)

Return a tuple {:ok, jws (string)} if the signature is verified, or {:error, “invalid”} otherwise

Example

iex> jws = "eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jws.verify(jws, "HS256", key)
{:ok, "eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"}