Alternera.Plugin.Provisional.Credentials (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

Provisional: added for Authorize, and a change to it needs a changelog line but no new major (docs/USER_PLUGINS_DESIGN.md).

The credentials the application sends a request with, through Alternera.Plugin.Host. authorization/3 asks for the Authorization value of the tenant's credentials for the URL a request goes to (target_url); the application picks them, fetches the token or reuses the one it holds, and answers:

  • {:ok, %{value:, profile:, directives:, outbound_us:}}: the header's value, the name of what it came from (the proxy's auth profile), the directives that go with it (authorization_renewal, which the door renews the token by when the upstream answers 401), and the time the fetch waited on the token service, in µs (0 for a held token);
  • {:token_request, profile}: request_url is that profile's own token URL, so the request is the token request itself and goes on as it came;
  • {:error, message}: no credentials apply to target_url, and nothing was fetched; the message names the URL's scheme, host and port, never its query;
  • {:error, message, outbound_us}: the token could not be fetched; the message names the profile, never the credentials.

The host reads the tenant, the trace and dry_run? from the context: a preview fetches nothing, and its value names the profile instead of holding a token.

for_call/3 is the same for a call the step makes itself (Provisional.Outbound.call/3, a Request step's authorize): the host refuses a call made while the exchange is that profile's own token request, which could only wait for itself. It answers {:ok, %{value:, profile:, outbound_us:}}, {:error, message} (nothing was fetched: no credentials for the URL, the exchange is the profile's token request) or {:error, message, outbound_us} (the fetch failed). renew: value, the Authorization value a first call was answered 401 with, drops the token that value holds and fetches a new one, as an OAuth client refreshes on a 401.

Summary

Functions

The Authorization value for a request to target_url (see the module doc).

The Authorization value for a call the step makes to url (see the module doc).

Types

answer()

@type answer() ::
  {:ok,
   %{
     value: String.t(),
     profile: String.t(),
     directives: map(),
     outbound_us: non_neg_integer()
   }}
  | {:token_request, String.t()}
  | {:error, String.t()}
  | {:error, String.t(), non_neg_integer()}

call_answer()

@type call_answer() ::
  {:ok,
   %{value: String.t(), profile: String.t(), outbound_us: non_neg_integer()}}
  | {:error, String.t()}
  | {:error, String.t(), non_neg_integer()}

Functions

authorization(context, target_url, request_url)

@spec authorization(map(), String.t() | nil, String.t() | nil) :: answer()

The Authorization value for a request to target_url (see the module doc).

for_call(context, url, opts \\ [])

@spec for_call(map(), String.t(), keyword()) :: call_answer()

The Authorization value for a call the step makes to url (see the module doc).