Überauth Zapier
Zapier OAuth2 strategy for Überauth.
Installation
-
Setup your application ntegration in Zapier Development Dashboard https://developer.zapier.com/
-
Add
:ueberauth_zapierto your list of dependencies inmix.exs:def deps do [{:ueberauth_zapier, "~> 0.1.0"}] end -
Add Zapier to your Überauth configuration:
config :ueberauth, Ueberauth, providers: [ zapier: {Ueberauth.Strategy.Zapier, [default_scope: "profile"]}, ] -
Update your provider configuration:
config :ueberauth, Ueberauth.Strategy.Zapier.OAuth, client_id: System.get_env("ZAPIER_CLIENT_ID"), client_secret: System.get_env("ZAPIER_CLIENT_SECRET") -
Include the Überauth plug in your router pipeline:
defmodule TestZapierWeb.Router do use TestZapierWeb, :router pipeline :browser do plug Ueberauth ... end end -
Add the request and callback routes:
scope "/auth", TestZapierWeb do pipe_through :browser get "/:provider", AuthController, :request get "/:provider/callback", AuthController, :callback end -
Create a new controller or use an existing controller that implements callbacks to deal with
Ueberauth.AuthandUeberauth.Failureresponses from Zapier.defmodule TestZapierWeb.AuthController do use TestZapierWeb, :controller def callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) do conn |> put_flash(:error, "Failed to authenticate.") |> redirect(to: "/") end def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do case 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: "/") end end end
Calling
Once your setup, you can initiate auth using the following URL, unless you changed the routes from the guide:
/auth/zapier
Documentation
The docs can be found at ueberauth_zapier on Hex Docs.