Phoenix.Token
Phoenix.Token
Tokens provide a way to generate and verify bearer tokens for use in Channels or API authentication.
The data can be read by clients, but the message is signed to prevent tampering.
Example
When generating a unique token for usage in an API or Channel it is advised to use a unique identifier for the user typically the id from a database. For example:
iex> user_id = 1
iex> token = Phoenix.Token.sign(MyApp.Endpoint, "user", user_id)
iex> Phoenix.Token.verify(MyApp.Endpoint, "user", token)
{:ok, 1}
In that example we have a user’s id, we generate a token and verify it using the secret key base configured in the given endpoint
.
The first argument to both sign/4
and verify/4
can be one of:
- the m