Packages
phauxth
2.0.1
2.5.1
retired
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
2.0.0-beta.1
2.0.0-beta.0
2.0.0-alpha.5
2.0.0-alpha.4
retired
2.0.0-alpha.3
retired
2.0.0-alpha.2
retired
2.0.0-alpha.1
retired
2.0.0-alpha.0
retired
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.17.1
0.17.0
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0-rc.1
0.13.0-rc.0
0.12.1-rc.1
0.12.1-rc.0
0.12.0-rc
0.11.0
0.10.3
0.10.2
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
Authentication library for Phoenix, and other Plug-based, web applications
Current section
Files
Jump to
Current section
Files
lib/phauxth/token.ex
defmodule Phauxth.Token do
@moduledoc """
Behaviour for signing and verifying tokens.
If you are using Phauxth for token authentication, email confirmation
or password resetting, you will need to define a module in your app
that uses this behaviour (see the examples section below).
After you have created the token module, add the `token_module`
value to the phauxth config:
config phauxth, token_module: MyAppWeb.Auth.Token
Use the token module to sign the tokens, and then Phauxth will use
this module to verify the tokens.
## Examples
The following is an example token module using Phoenix tokens.
defmodule MyAppWeb.Auth.Token do
@behaviour Phauxth.Token
alias Phoenix.Token
alias MyAppWeb.Endpoint
@token_salt "JaKgaBf2"
@impl true
def sign(data, opts \\ []) do
Token.sign(Endpoint, @token_salt, data, opts)
end
@impl true
def verify(token, opts \\ []) do
Token.verify(Endpoint, @token_salt, token, opts)
end
end
"""
@type data :: map | keyword | binary | integer
@type opts :: keyword
@doc """
Signs a token.
"""
@callback sign(data, opts) :: binary
@doc """
Verifies a token.
"""
@callback verify(binary, opts) :: {:ok, map} | {:error, atom | binary}
end