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

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

Link to this section 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.

Link to this section Callbacks

Specs

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

Specs

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

Link to this section Functions

Link to this function

decode_json(response, config)

View Source

Specs

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

Decode a JSON response to a map

Link to this function

decode_response(arg, config)

View Source

Specs

decode_response(
  {:ok, Assent.HTTPResponse.t()}
  | {:error, Assent.HTTPResponse.t()}
  | {:error.term()},
  Assent.Config.t()
) ::
  {:ok, Assent.HTTPResponse.t()}
  | {:error, Assent.HTTPResponse.t()}
  | {:error, term()}

Decodes a request response.

Link to this function

normalize_userinfo(claims, extra \\ %{})

View Source

Specs

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

Specs

prune(map()) :: map()

Recursively prunes map for nil values.

Link to this function

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

View Source

Specs

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

Makes a HTTP request.

Link to this function

sign_jwt(claims, alg, secret, config)

View Source

Specs

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

Signs a JWT

Link to this function

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

View Source

Specs

to_url(binary(), binary(), Keyword.t()) :: binary()

Generates a URL

Link to this function

verify_jwt(token, secret, config)

View Source

Specs

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

Verifies a JWT