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 is access_token.

    plug AccessToken, param: "token"
  • :http_header - The name of the HTTP request header to check for the access token. Default value is authorization.

    plug AccessToken, http_header: "custom-authorization"
  • :http_header_prefix - The prefix of the HTTP request authorization header. Default value is Bearer.

    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 be nil, an integer or an atom. The list of allowed atoms is available in Plug.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 the conn followed by the list of args provided.

    plug AccessToken,
      error_handler: {Phoenix.Controller, :render, [MyAppWeb.ErrorView, "401.json"]}

Link to this section Summary

Functions

Callback implementation for Plug.call/2

Callback implementation for Plug.init/1

Link to this section Functions

Callback implementation for Plug.call/2.

Callback implementation for Plug.init/1.