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

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 string.

Normalize API user request response into standard claims.

Recursively prunes map for nil values.

Signs a JSON Web Token.

Verifies a JSON Web Token.

Callbacks

authorize_url(t)

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

callback(t, map)

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

Functions

decode_json(response, config)

@spec decode_json(binary(), Keyword.t()) :: {:ok, term()} | {:error, term()}

Decode a JSON string.

Options

  • :json_library - The JSON library to use, see Assent.json_library/1

decode_response(response, config)

This function is deprecated. Use Assent.HTTPAdapter.decode_response/2 instead.

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

Makes a HTTP request.

See Assent.HTTPAdapter.request/5.

normalize_userinfo(claims, extra \\ %{})

@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

prune(map)

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

Recursively prunes map for nil values.

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

This function is deprecated. Use http_request/4 instead.

sign_jwt(claims, alg, secret, config)

@spec sign_jwt(map(), binary(), binary(), Keyword.t()) ::
  {:ok, binary()} | {:error, term()}

Signs a JSON Web Token.

See Assent.JWTAdapter.sign/3 for options.

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

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

Generates a URL.

verify_jwt(token, secret, config)

@spec verify_jwt(binary(), binary() | map() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, any()}

Verifies a JSON Web Token.

See Assent.JWTAdapter.verify/3 for options.