HubIdentityElixir
An Elixir Package designed to make implementing HubIdentity authentication easy and fast. In order to use this package you need to have an account with HubIdentity
Currently this is only for Hivelocity uses. If you have a commercial interest please contact the Package Manager Erin Boeger through linkedIn or Github or through Hivelocity.
Installation
The package can be installed by adding hub_identity_elixir to your list of dependencies in mix.exs:
def deps do
[
{:hub_identity_elixir, "~> 0.1.0"}
]
endSetup
Setup your configuration in config.exs, dev.exs, prod.exs etc:
config :hub_identity_elixir, :url, # Either staging, production, or localhost
config :hub_identity_elixir, :public_key, # The public key from HubIdentityOptional config settings
config :hub_identity_elixir, :authenticated_redirect, # This will allow a redirect after authentication, default is: "/"
config :hub_identity_elixir, :login_path, # This will allow a redirect after authentication, default is: "/sessions/new"
config :hub_identity_elixir, :logged_out_redirect, # This will allow a redirect after authentication, default is: "/"
Inside your Router add use HubIdentityElixir.Phoenix.Router and include
the hub_identity_routes()
in router.exs:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
use HubIdentityElixir.Phoenix.Router # <- Add HubIdentity Router
# router stuff..
scope "/", MyAppWeb do
pipe_through :browser
hub_identity_routes() # <- Add HubIdentity routes
get "/", PageController, :index
endThis will add the following routes to your application:
- session_path DELETE /sessions/logout HubIdentityElixir.Phoenix.SessionController :delete
- session_path GET /sessions/new HubIdentityElixir.Phoenix.SessionController :new
- session_path GET /sessions/create HubIdentityElixir.Phoenix.SessionController :create
If you want a @current_user helper then add plug :fetch_current_user to your pipeline.
Restricted routes
For authentication required (restricted) routes add the plug require_authenticated_user
for example:
scope "/", MyAppWeb do
pipe_through [:browser, :require_authenticated_user]
get "/something/restricted", PageController, :something
get "/something_else/restricted", PageController, :something_else
endDocumentation
Documentation can be generated with ExDoc and published on HexDocs at hub_identity_elixir