Ueberauth Passwordless v0.3.2 Ueberauth.Strategy.Passwordless View Source

Passwordless Strategy for Ueberauth

Setup

Create a Module which implements the behaviour specified in Ueberauth.Strategy.Passwordless.Mailer.

Include the provider in your configuration for Ueberauth

config :ueberauth, Ueberauth,
  providers: [
    passwordless: {Ueberauth.Strategy.Passwordless, []}
  ]

Then include the configuration for this strategy

config :ueberauth, Ueberauth.Strategy.Passwordless,
  token_secret: System.get_env("PASSWORDLESS_TOKEN_SECRET"),
  mailer: MyApp.MyMailerModule,
  # (Optional) Specify how long a login token should be valid (here 30 minutes)
  ttl: 30 * 60,
  # (Optional) Specify a default path or url to which Passwordless should redirect
  # after the request phase is completed (i.e. the Email was sent)
  redirect_url: "/login-link-sent"

If you haven't already, create a pipeline and setup routes for your callback handler

pipeline :auth do
  Ueberauth.plug "/auth"
end

scrope "/auth" do
  pipe_through [:browser, :auth]

  get "/:provider", AuthController, :request
  get "/:provider/callback", AuthController, :callback
end

Create an endpoint for the callback where you handle the Ueberauth.Auth struct

defmodule MyApp.AuthController do
  use MyApp.Web, :controller

  def callback(%{assigns: %{ueberauth_failure: errors}} = conn, _params) do
    # do things with the failure
  end

  def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
    # do things with the auth
  end
end

How to use

Use in a login form like this

<%= form_for @conn, Routes.auth_path(@conn, :request, "passwordless"), [method: get], fn f -> %>
  <%= text_input f, :email %>
  <%= submit "Submit" %>
<% end %>

You can optionally specify a redirect_url (URL or Path) to which Passwordless will redirect after the request phase was completed (i.e. the Email was sent)

<%= form_for @conn, Routes.auth_path(@conn, :request, "passwordless"), [method: get], fn f -> %>
  <%= hidden_input f, :redirect_url, value: "/my-redirect-path"%>
  <%= text_input f, :email %>
  <%= submit "Submit" %>
<% end %>

Per default, Passwordless will redirect to "/" after the request phase is completed.

Link to this section Summary

Functions

Creates a callback link which has a token as a parameter.

Stores the raw information (including the token) obtained from the callback.

Stores the information obtained from the callback.

Callback implementation for Ueberauth.Strategy.uid/1.

Link to this section Functions

Link to this function

create_link(conn, email, opts \\ [])

View Source

Creates a callback link which has a token as a parameter.

The token contains a unforgeable HMAC token that expire after a TTL (Time-to-live).

Link to this function

create_token(email, opts \\ [])

View Source

Callback implementation for Ueberauth.Strategy.credentials/1.

Stores the raw information (including the token) obtained from the callback.

This sturct is available in your callback function with ueberauth_auth.extra

Stores the information obtained from the callback.

This sturct is available in your callback function with ueberauth_auth.info

Callback implementation for Ueberauth.Strategy.uid/1.