Ueberauth HPID
HP ID OAuth2 strategy for Überauth.
Installation
Add
:ueberauth_hpidto your list of dependencies inmix.exs:def deps do [{:ueberauth_hpid, "~> 1.0"}] endAdd the strategy to your applications:
def application do [applications: [:ueberauth_hpid]] endAdd HPID to your Überauth configuration:
config :ueberauth, Ueberauth, providers: [ hpid: {Ueberauth.Strategy.HPID, []} ]Update your provider configuration:
config :ueberauth, Ueberauth.Strategy.HPID.OAuth, client_id: System.get_env("HPID_CLIENT_ID"), client_secret: System.get_env("HPID_CLIENT_SECRET")Include the Überauth plug in your controller:
defmodule MyApp.AuthController do use MyApp.Web, :controller pipeline :browser do plug Ueberauth ... end endCreate the request and callback routes if you haven't already:
scope "/auth", MyApp do pipe_through :browser get "/:provider", AuthController, :request get "/:provider/callback", AuthController, :callback endYour controller needs to implement callbacks to deal with
Ueberauth.AuthandUeberauth.Failureresponses.
For an example implementation see the Überauth Example application.
Calling
Depending on the configured url you can initiate the request through:
/auth/hpidOr with options:
/auth/hpid?scope=openid+profile+emailOr if using token workflow:
/auth/hpid/callback?token=xyz
By default the requested scope is "openid+profile+email". This provides both read access to the HPID user profile. See more at HPID's OAuth Documentation. Scope can be configured either explicitly as a scope query value on the request path or in your configuration:
config :ueberauth, Ueberauth,
providers: [
hpid: {Ueberauth.Strategy.HPID, [
default_scope: "openid+profile+email",
redirect_uri: "https://yourdomain.com"
]}
]If you need to override the callback url (redirect_uri) at runtime, you can use the configuration in the Ueberauth.Strategy.HPID.OAuth:
config :ueberauth, Ueberauth.Strategy.HPID.OAuth,
client_id: System.get_env("HPID_CLIENT_ID"),
client_secret: System.get_env("HPID_CLIENT_SECRET"),
redirect_uri: "https://yourdomain.com/auth/hpid/callback"License
Please see LICENSE for licensing details.