Coherence.Authentication.Token (Coherence v0.8.0)

Implements token based authentication. To use add

plug Coherence.Authentication.Token, source: :params, param: "auth_token"

or

plug Coherence.Authentication.Token, source: :session, param: "auth_token"

or

plug Coherence.Authentication.Token, source: :header, param: "x-auth-token"

or

plug Coherence.Authentication.Token, source: { module, function, ["my_param"]} end

or

plug Coherence.Authentication.Token, source: :params_session, param: "auth_token"

to your pipeline.

Options

  • source - where to locate the token
  • error - The error message if not authenticated
  • assigns_key - The key to user in assigns (:current_uer)
  • store - Where to store the token data

Summary

Types

@type conn() :: Plug.Conn.t()
@type t() :: Ecto.Schema.t() | map()

Functions

Link to this function

add_credentials(token, user_data, store \\ Coherence.CredentialStore.Server)

@spec add_credentials(String.t(), t(), module()) :: :ok

Add the credentials for a token. user_data can be any term but must not be nil.

Link to this function

call(conn, opts)

@spec call(
  conn(),
  keyword()
) :: conn()

Callback implementation for Plug.call/2.

Link to this function

check_token_from_session(arg, param)

@spec check_token_from_session(
  {conn(), nil | String.t()},
  atom() | binary()
) :: {conn(), nil | String.t()}
Link to this function

generate_token()

@spec generate_token() :: String.t()

Utility function to generate a random authentication token.

Link to this function

get_token_from_header(conn, param)

@spec get_token_from_header(conn(), binary()) :: {conn(), String.t()}
Link to this function

get_token_from_params(conn, param)

@spec get_token_from_params(conn(), atom() | binary()) :: {conn(), any()}
Link to this function

get_token_from_params_session(conn, param)

@spec get_token_from_params_session(conn(), atom() | binary()) ::
  {conn(), nil | String.t()}
Link to this function

get_token_from_session(conn, param)

@spec get_token_from_session(conn(), atom() | binary()) :: {conn(), nil | String.t()}
@spec init(keyword()) :: map()

Callback implementation for Plug.init/1.

Link to this function

remove_credentials(token, store \\ Coherence.CredentialStore.Server)

@spec remove_credentials(String.t(), module()) :: :ok

Remove the credentials for a token.

Link to this function

save_token_in_session(arg, param)

@spec save_token_in_session(
  {conn(), nil | String.t()},
  atom() | binary()
) :: {conn(), nil | String.t()}