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.
Makes a HTTP request.
Signs a JWT
Generates a URL
Verifies a JWT
Callbacks
@callback authorize_url(Assent.Config.t()) :: {:ok, %{:url => binary(), optional(atom()) => any()}} | {:error, term()}
Functions
@spec decode_json(binary(), Assent.Config.t()) :: {:ok, map()} | {:error, term()}
Decode a JSON response to a map
@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.
Normalize API user request response into standard claims
Based on https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.1
Recursively prunes map for nil values.
@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.
Signs a JWT
Generates a URL
@spec verify_jwt(binary(), binary() | map() | nil, Assent.Config.t()) :: {:ok, map()} | {:error, any()}
Verifies a JWT