aegis v0.1.0 Aegis View Source
Lightweight, flexible authorization.
Link to this section Summary
Functions
Returns scope for a resource for a user for a given action as dictated by the resource’s corresponding policy definition
Returns true
if a user is authorized to perform an action on a given resource as dictated by the resource’s corresponding policy definition
Link to this section Functions
Returns scope for a resource for a user for a given action as dictated by the resource’s corresponding policy definition.
Example
defmodule Puppy do
defstruct [id: nil, user_id: nil, hungry: false]
end
defmodule Puppy.Policy do
@behaviour Aegis.Policy
def scope(_user, _scope, :index), do: :index_scope
def scope(_user, _scope, :show), do: :show_scope
end
defmodule Kitten do
defstruct [id: nil, user_id: nil, hungry: false]
end
iex> user = :user iex> scope = %{from: {“puppies”, Puppy}} iex> Aegis.auth_scope(user, scope, :index) :index_scope iex> Aegis.auth_scope(user, scope, :show) :show_scope
iex> user = :user iex> scope = %{from: {“kittens”, Kitten}} iex> Aegis.auth_scope(user, scope, :index) ** (RuntimeError) Policy not found: Elixir.Kitten.Policy
Returns true
if a user is authorized to perform an action on a given resource as dictated by the resource’s corresponding policy definition.
Example
defmodule Puppy do
defstruct [id: nil, user_id: nil, hungry: false]
end
defmodule Puppy.Policy do
@behaviour Aegis.Policy
def authorize(_user, :index, _puppy), do: true
end
defmodule Kitten do
defstruct [id: nil, user_id: nil, hungry: false]
end
iex> user = :user iex> resource = Puppy iex> Aegis.authorized?(user, :index, resource) true iex> Aegis.authorized?(user, :show, resource) false
iex> user = :user iex> action = :index iex> resource = Kitten iex> Aegis.authorized?(user, action, resource) ** (RuntimeError) Policy not found: Elixir.Kitten.Policy