Coherence v0.5.2 Coherence.Authentication.Token

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

Link to this section Summary

Link to this section Types

Link to this section Functions

Link to this function add_credentials(token, user_data, store \\ Coherence.CredentialStore.Server)
add_credentials(String.t(), t(), module()) :: t()

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

Link to this function call(conn, opts)
call(conn(), Keyword.t()) :: conn()

Callback implementation for Plug.call/2.

Link to this function check_token_from_session(arg, param)
Link to this function generate_token()
generate_token() :: String.t()

Utility function to generate a random authentication token.

Link to this function get_token_from_header(conn, param)
get_token_from_header(conn(), Map.t()) :: {conn(), Map.t() | String}
Link to this function get_token_from_params(conn, param)
get_token_from_params(conn(), Map.t()) :: {conn(), Map.t()}
Link to this function get_token_from_params_session(conn, param)
get_token_from_params_session(conn(), Map.t()) :: {conn(), nil | String.t()}
Link to this function get_token_from_session(conn, param)
get_token_from_session(conn(), Map.t()) :: {conn(), String.t()}
get_token_from_session({conn(), nil | String.t()}, Map.t()) ::
  String.t() | {conn(), String.t()}
Link to this function init(opts)
init(Keyword.t()) :: [tuple()]

Callback implementation for Plug.init/1.

Link to this function remove_credentials(token, store \\ Coherence.CredentialStore.Server)
remove_credentials(String.t(), module()) :: t()

Remove the credentials for a token.

Link to this function save_token_in_session(arg, param)
save_token_in_session({conn(), nil | String.t()}, Map.t()) ::
  {conn(), nil | String.t()}