authable v0.10.0 Authable.Plug.Authenticate
Authable plug implementation to check authentications and to set resouce owner.
Link to this section Summary
Functions
Plug function to authenticate client for resource owner and assigns resource owner into conn.assigns[:current_user] key. If it fails, then it halts connection and returns :bad_request, :unauthorized or :forbidden status codes with error json
Link to this section Functions
Link to this function
call(conn, scopes)
Plug function to authenticate client for resource owner and assigns resource owner into conn.assigns[:current_user] key. If it fails, then it halts connection and returns :bad_request, :unauthorized or :forbidden status codes with error json.
There is one option:
- scopes - the function used to authorize the resource access
- the default is “”
Examples
defmodule SomeModule.AppController do
use SomeModule.Web, :controller
plug Authable.Plug.Authenticate, [scopes: ~w(read write)]
def index(conn, _params) do
# access to current user on successful authentication
current_user = conn.assigns[:current_user]
...
end
end
defmodule SomeModule.AppController do
use SomeModule.Web, :controller
plug Authable.Plug.Authenticate [scopes: ~w(read write)] when action in [:create]
def index(conn, _params) do
# anybody can call this action
...
end
def create(conn, _params) do
# only logged in users can access this action
current_user = conn.assigns[:current_user]
...
end
end
Link to this function
init(opts)