View Source Guardian.Plug.VerifySession (Guardian v2.3.2)
Looks for and validates a token found in the session.
In the case where either:
- The session is not loaded
- A token is already found for
:key
- No token is found on the session
This plug will not do anything.
This, like all other Guardian plugs, requires a Guardian pipeline to be setup. It requires an implementation module, an error handler and a key.
These can be set either:
- Upstream on the connection with
plug Guardian.Pipeline
- Upstream on the connection with
Guardian.Pipeline.{put_module, put_error_handler, put_key}
- Inline with an option of
:module
,:error_handler
,:key
If a token is found but is invalid, the error handler will be called with
auth_error(conn, {:invalid_token, reason}, opts)
.
Once a token has been found it will be decoded, the token and claims will be put onto the connection.
They will be available using Guardian.Plug.current_claims/2
and Guardian.Plug.current_token/2
.
Options:
:refresh_from_cookie
- Looks for and validates a token found in the request cookies. (defaultfalse
)
Refresh from cookie option
:key
- The location of the token (default:default
):exchange_from
- The type of the cookie (default"refresh"
):exchange_to
- The type of token to provide. Defaults to the implementation modulesdefault_type
:ttl
- The time to live of the exchanged token. Defaults to configured values.:halt
- Whether to halt the connection in case of error. Defaults totrue