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 douse MyApp.Web, :controllerpipeline :browser doplug Ueberauth...endendCreate the request and callback routes if you haven't already:
scope "/auth", MyApp dopipe_through :browserget "/:provider", AuthController, :requestget "/:provider/callback", AuthController, :callbackendYour 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/hpid
Or with options:
/auth/hpid?scope=openid+profile+email
Or 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.