Coherence.Authentication.IpAddress (Coherence v0.8.0)

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

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.

Types

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

Functions

Link to this function

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

@spec 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)

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

Callback implementation for Plug.call/2.

@spec init(keyword()) :: map()

Callback implementation for Plug.init/1.

Link to this function

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

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

Remove the credentials for a token.