Usher.Token.Signature (Usher v0.5.1)

View Source

Helper functions to sign and verify user-supplied invitation tokens.

Signing tokens is optional and does not change how tokens are stored. Use it when you want to distribute a signature along with a token, so that you can later check for authenticity, before looking up the invitation in the DB.

Summary

Functions

Signs a token string using HMAC-SHA256 and returns a URL-encoded Base64 string.

Verifies a signature against the given token. Signature must've been generated using the given token.

Types

signature()

@type signature() :: String.t()

token()

@type token() :: String.t()

Functions

sign(token)

@spec sign(String.t()) :: String.t()

Signs a token string using HMAC-SHA256 and returns a URL-encoded Base64 string.

Requires config :usher, signing_secret: "..." to be set.

verify(token, signature)

@spec verify(token(), signature()) :: {:ok, token()} | {:error, :invalid_signature}

Verifies a signature against the given token. Signature must've been generated using the given token.