Assent.Strategy.OAuth2.Base behaviour (Assent v0.1.27) View Source

OAuth 2.0 strategy base.

Usage

defmodule MyApp.MyOAuth2Strategy do
  use Assent.Strategy.OAuth2.Base

  def default_config(_config) do
    [
      site: "https://api.example.com",
      user_url: "/authorization.json"
    ]
  end

  @impl true
  def normalize(_config, user) do
    {:ok,
      # Conformed to https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.1
      %{
        "sub"   => user["id"],
        "name"  => user["name"],
        "email" => user["email"]
      # },
      # # Provider specific data not part of the standard claims spec
      # %{
      #  "bio" => user["bio"]
      }
    }
  end
end

Link to this section Summary

Link to this section Callbacks

Specs

default_config(Keyword.t()) :: Keyword.t()

Specs

fetch_user(Keyword.t(), map()) :: {:ok, map()} | {:error, term()}

Specs

normalize(Keyword.t(), map()) ::
  {:ok, map()} | {:ok, map(), map()} | {:error, term()}

Link to this section Functions

Link to this function

authorize_url(config, strategy)

View Source

Specs

authorize_url(Keyword.t(), module()) ::
  {:ok, %{session_params: %{state: binary()}, url: binary()}}
Link to this function

callback(config, params, strategy)

View Source

Specs

callback(Keyword.t(), map(), module()) ::
  {:ok, %{user: map(), token: map()}} | {:error, term()}