Coherence v0.5.1 Coherence.Authentication.IpAddress

Implements ip address based authentication. To use add

plug Coherence.Authentication.IpAddress, allow: ~w(127.0.0.1 192.168.1.200)

to your pipeline.

IP addresses can be specified in a list as either IP or IP/subnet_mask, where subnet_mask can be an integer or dot format.

If you would like access to the current user you must set each authorized IP address like:

Coherence.CredentialStore.Server.put_credentials({127.0.0.1}, %{role: :admin})

or use a custom store like:

defmodule MyProject.Store do
  def get_user_data(ip) do
    Repo.one from u in User, where: u.ip_address == ^id
  end
end

plug Coherence.Authentication.IpAddress, allow: ~w(127.0.0.1 192.168.1.0/24), store: &MyProject.Store/1

IP Format Examples:

allow: ~w(127.0.0.1 192.169.1.0/255.255.255.0)
allow: ~w(127.0.0.1 192.169.1.0/24)
deny: ~w(10.10.0.0/16)

Options

  • :allow - list of allowed IPs
  • :deny - list of denied IPs
  • :error - error to be displayed if the IP is not allowed
  • :store - the user_data store
  • :assign_key - the assigns key to store the user_data

Link to this section Summary

Functions

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

Callback implementation for Plug.call/2

Callback implementation for Plug.init/1

Link to this section Types

Link to this section Functions

Link to this function add_credentials(ip, 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 init(opts)
init(Keyword.t()) :: [tuple()]

Callback implementation for Plug.init/1.

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

Remove the credentials for a token.