Überauth Patreon
Patreon OAuth2 strategy for Überauth.
Installation
Setup your application in Patreon Development Dashboard https://www.patreon.com/portal/registration/register-clients
Add
:ueberauth_patreonto your list of dependencies inmix.exs:def deps do[{:ueberauth_patreon, "~> 1.0"}]endAdd Patreon to your Überauth configuration:
config :ueberauth, Ueberauth,providers: [patreon: {Ueberauth.Strategy.Patreon, [default_scope: "identity[email] identity"]},]Update your provider configuration:
config :ueberauth, Ueberauth.Strategy.Patreon.OAuth,client_id: System.get_env("PATREON_CLIENT_ID"),client_secret: System.get_env("PATREON_CLIENT_SECRET"),redirect_uri: System.get_env("PATREON_REDIRECT_URI")Include the Überauth plug in your router pipeline:
defmodule TestPatreonWeb.Router douse TestPatreonWeb, :routerpipeline :browser doplug Ueberauth...endendAdd the request and callback routes:
scope "/auth", TestPatreonWeb dopipe_through :browserget "/:provider", AuthController, :requestget "/:provider/callback", AuthController, :callbackendCreate a new controller or use an existing controller that implements callbacks to deal with
Ueberauth.AuthandUeberauth.Failureresponses from Patreon.defmodule TestPatreonWeb.AuthController douse TestPatreonWeb, :controllerdef callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) doconn|> put_flash(:error, "Failed to authenticate.")|> redirect(to: "/")enddef callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) docase UserFromAuth.find_or_create(auth) do{:ok, user} ->conn|> put_flash(:info, "Successfully authenticated.")|> put_session(:current_user, user)|> configure_session(renew: true)|> redirect(to: "/"){:error, reason} ->conn|> put_flash(:error, reason)|> redirect(to: "/")endendend
Calling
Once your setup, you can initiate auth using the following URL, unless you changed the routes from the guide:
/auth/patreon
Documentation
The docs can be found at ueberauth_patreon on Hex Docs.