View Source Assent.Strategy behaviour (Assent v0.2.9)

Used for creating strategies.

Usage

Set up my_strategy.ex the following way:

defmodule MyStrategy do
  @behaviour Assent.Strategy

  alias Assent.Strategy, as: Helpers

  def authorize_url(config) do
    # Generate redirect URL

    {:ok, %{url: url, ...}}
  end

  def callback(config, params) do
    # Fetch user data

    user = Helpers.normalize_userinfo(userinfo)

    {:ok, %{user: user, ...}}
  end
end

Summary

Functions

Decode a JSON response to a map

Decodes a request response.

Normalize API user request response into standard claims

Recursively prunes map for nil values.

Callbacks

@callback authorize_url(Assent.Config.t()) ::
  {:ok, %{:url => binary(), optional(atom()) => any()}} | {:error, term()}
@callback callback(Assent.Config.t(), map()) ::
  {:ok, %{:user => map(), optional(atom()) => any()}} | {:error, term()}

Functions

Link to this function

decode_json(response, config)

View Source
@spec decode_json(binary(), Assent.Config.t()) :: {:ok, map()} | {:error, term()}

Decode a JSON response to a map

Link to this function

decode_response(any, config)

View Source
@spec decode_response(
  {:ok, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, term()},
  Assent.Config.t()
) ::
  {:ok, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, term()}

Decodes a request response.

Link to this function

normalize_userinfo(claims, extra \\ %{})

View Source
@spec normalize_userinfo(map(), map()) :: {:ok, map()}

Normalize API user request response into standard claims

Based on https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.1

@spec prune(map()) :: map()

Recursively prunes map for nil values.

Link to this function

request(method, url, body, headers, config)

View Source
@spec request(atom(), binary(), binary() | nil, list(), Assent.Config.t()) ::
  {:ok, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, term()}

Makes a HTTP request.

Link to this function

sign_jwt(claims, alg, secret, config)

View Source
@spec sign_jwt(map(), binary(), binary(), Assent.Config.t()) ::
  {:ok, binary()} | {:error, term()}

Signs a JWT

Link to this function

to_url(base_url, uri, params \\ [])

View Source
@spec to_url(binary(), binary(), Keyword.t()) :: binary()

Generates a URL

Link to this function

verify_jwt(token, secret, config)

View Source
@spec verify_jwt(binary(), binary() | map() | nil, Assent.Config.t()) ::
  {:ok, map()} | {:error, any()}

Verifies a JWT