View Source Ueberauth.Strategy.Mollie (ueberauth_mollie v1.0.0)

Provides an Ueberauth strategy for authenticating with Mollie.

Setup

Create an application in Mollie for you to use. Register a new application at: Dashboard and get the client_id and client_secret.

Include the provider in your configuration for Ueberauth:

config :ueberauth, Ueberauth,
  providers: [
    mollie: { Ueberauth.Strategy.Mollie, [
      scopes: "organizations.read payments.read"
    ] }
  ]

You can use a tool like localtunnel to expose your local server to the internet for testing.

Then include the configuration for Mollie:

config :ueberauth, Ueberauth.Strategy.Mollie.OAuth,
  client_id: System.get_env("MOLLIE_CLIENT_ID"),
  client_secret: System.get_env("MOLLIE_CLIENT_SECRET"),
  redirect_uri: "https://gqgh.localtunnel.me/auth/mollie/callback" # <-- note that Mollie needs HTTPS for a callback URL scheme, even in test apps.

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

pipeline :auth do
  Ueberauth.plug "/auth"
end
scope "/auth" do
  pipe_through [:browser, :auth]
  get "/:provider/callback", AuthController, :callback
end

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

defmodule MyApp.AuthController do
  use MyApp.Web, :controller
  def callback_phase(%{ assigns: %{ ueberauth_failure: fails } } = conn, _params) do
    # do things with the failure
  end
  def callback_phase(%{ assigns: %{ ueberauth_auth: auth } } = conn, params) do
    # do things with the auth
  end
end

You can edit the behaviour of the Strategy by including some options when you register your provider.

To set the uid_field:

config :ueberauth, Ueberauth,
  providers: [
    mollie: { Ueberauth.Strategy.Mollie, [uid_field: :email] } # Default is `:id`, a string in the form of `org_12345678`."
  ]

Usage

Once you obtained a token, you may use the OAuth client directly:

Ueberauth.Strategy.Mollie.OAuth.get("/organizations/me")

See the Mollie API Docs for more information.

Summary

Functions

Includes the credentials from the Mollie Connect response.

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

Cleans up the private area of the connection used for passing the raw Mollie Connect response around during the callback.

Handles the initial redirect to the Mollie authentication page.

Fetches the fields to populate the info section of the Ueberauth.Auth struct.

Fetches the :uid field from the Mollie Connect response. This defaults to the option :uid_field which in-turn defaults to :id

Functions

Includes the credentials from the Mollie Connect response.

Callback implementation for Ueberauth.Strategy.default_options/0.

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

Cleans up the private area of the connection used for passing the raw Mollie Connect response around during the callback.

Handles the initial redirect to the Mollie authentication page.

Fetches the fields to populate the info section of the Ueberauth.Auth struct.

Fetches the :uid field from the Mollie Connect response. This defaults to the option :uid_field which in-turn defaults to :id