access_token v0.2.1 AccessToken View Source
A plug for extracting the access token from the request.
The token may be sent by the request either via the params with key access_token
or a
header with name Authorization
and content Bearer <access token>
.
To use it, just plug it into the desired module:
plug AccessToken
If present, the access token will be accessible through the assigns
map of the connection.
conn.assigns[:access_token]
Options
:param
- The name of the HTTP request parameter to check for the access token. Default value isaccess_token
.plug AccessToken, param: "token"
:http_header
- The name of the HTTP request header to check for the access token. Default value isauthorization
.plug AccessToken, http_header: "custom-authorization"
:http_header_prefix
- The prefix of the HTTP request authorization header. Default value isBearer
.plug AccessToken, http_header_prefix: "Token"
:assign_to
- The name of the key to assign the access token. Defaults to:access_token
plug AccessToken, assign_to: :token
:error_status
- The status code to be returned in case the access token is not present. The status can benil
, an integer or an atom. The list of allowed atoms is available inPlug.Conn.Status
. Defaults to:unauthorized
plug AccessToken, error_status: :bad_request
:error_handler
- The function to be called in case the access token is not present. The:error_handler
is set using a{module, function, args}
triple. The function will receive theconn
followed by the list ofargs
provided.plug AccessToken, error_handler: {Phoenix.Controller, :render, [MyAppWeb.ErrorView, "401.json"]}
Link to this section Summary
Link to this section Functions
Callback implementation for Plug.call/2
.
Callback implementation for Plug.init/1
.