Packages
phauxth
2.3.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/authenticate_token.ex
defmodule Phauxth.AuthenticateToken do
@moduledoc """
Authenticates the user by verifying a Phauxth token.
This module looks for a token in the request headers,
checks to see if the token is valid and then sets the `current_user`
value accordingly.
If you want to store the token in a cookie, or customize this Plug
in any other way, see the documentation for Phauxth.Authenticate.Token.
## Configuration / setup
Add the `user_context` module (the module you are using to handle
user data) to the config:
config :phauxth, user_context: MyApp.Accounts
The user_context module (in this case, MyApp.Accounts) needs to have a
`get_by(attrs)` function, which returns either a user struct or nil.
You also need to define a token module that implements the Phauxth.Token
behaviour. See the documentation for the Phauxth.Token module for details.
## Options
There are four main options:
* `:user_context` - the user_context module
* this can also be set in the config
* `:token_module` - the token module
* this can also be set in the config
* `:log_meta` - additional custom metadata for Phauxth.Log
* this should be a keyword list
* `:max_age` - the maximum age for the token
* the default is 14_400 seconds - 4 hours
The options keyword list is also passed to the token verify function.
See the documentation for Phauxth.Token for information about defining
and setting the token module.
## Examples
Add the following line to the pipeline you want to authenticate in
the `web/router.ex` file:
plug Phauxth.AuthenticateToken
To set the max_age to two hours:
plug Phauxth.AuthenticateToken, max_age: 7200
"""
use Phauxth.Authenticate.Token
end