AuthShield v0.0.2 AuthShield View Source
AuthShield is an simple implementation that was created to be used with other frameworks (as Phoenix) or applications in order to provide an simple authentication and authorization management to the services.
Installation
To install the dependency set {:auth_shield, "~> 0.0.1"}
on your mix deps.
You can configure AuthX to use you database by setting on your config.exs
:
Configuration
config :auth_shield, AuthShield.Repo,
database: "authx_ex_dev",
username: "postgres",
password: "postgres",
hostname: "localhost",
port: 5432
The default session expiration is 15 minutes but you can change it setting on your config.exs
:
config :auth_shield, AuthShield,
# 15 minutes (in seconds)
session_expiration: 60 * 15
Link to this section Summary
Types
Session options used on authentication plug
Functions
Login the user by its password credential.
Logout the authenticated user session.
Refresh the authenticated user session.
Creates a new user on the system.
Link to this section Types
Session options used on authentication plug
Link to this section Functions
login(params, opts \\ [])
View Sourcelogin(params :: AuthShield.Validations.Login.t(), opts :: session_options()) :: {:ok, AuthShield.Authentication.Schemas.Session.t()} | {:error, :user_not_found} | {:error, :unauthenticated} | {:error, Ecto.Changeset.t()}
Login the user by its password credential.
If the user and its credential is authenticated it will return {:ok, AuthShield.Authentication.Schemas.Session.t()}
.
This session should be stored and used on authentication to keep users logged.
Exemples:
AuthShield.login(
%{"email" => "lucas@gmail.com", "password" => "Mypass@rd23"},
remote_ip: "172.31.4.1",
user_agent: "Mozilla/5.0 (Windows NT x.y; rv:10.0) Gecko/20100101 Firefox/10.0"
)
logout(session_id)
View Sourcelogout(session_id :: String.t() | AuthShield.Authentication.Schemas.Session.t()) :: {:ok, AuthShield.Authentication.Schemas.Session.t()} | {:error, :session_not_exist} | {:error, Ecto.Changeset.t()}
Logout the authenticated user session.
If the user is authenticated and has an active session it will
return {:ok, AuthShield.Authentication.Schemas.Session.t()}
.
This session can be ignored because use is not active anymore.
Exemples:
AuthShield.logout("ecb4c67d-6380-4984-ae04-1563e885d59e")
refresh_session(session_id)
View Sourcerefresh_session( session_id :: String.t() | AuthShield.Authentication.Schemas.Session.t() ) :: {:ok, AuthShield.Authentication.Schemas.Session.t()} | {:error, :session_expired} | {:error, :session_not_exist} | {:error, Ecto.Changeset.t()}
Refresh the authenticated user session.
If the user is authenticated and has an active session it will
return {:ok, AuthShield.Authentication.Schemas.Session.t()}
.
This session should be stored and used on authentication to keep users logged.
Exemples:
AuthShield.refresh_session("ecb4c67d-6380-4984-ae04-1563e885d59e")
signup(params)
View Sourcesignup(params :: AuthShield.Validations.SignUp.t()) :: {:ok, AuthShield.Resources.Schemas.User.t()} | {:error, map()} | {:error, Ecto.Changeset.t()}
Creates a new user on the system.
Exemples:
AuthShield.signup(%{
first_name: "Lucas",
last_name: "Mesquita",
email: "lucas@gmail.com",
password: "My_passw@rd2"
})