DomainConnect.Async (DomainConnect v0.5.0)

Copy Markdown View Source

The asynchronous (OAuth) Domain Connect flow, for Service Providers that apply templates programmatically rather than by redirecting the owner to a one-shot sync UX.

The round trip:

  1. consent_url/2 — build the URL the owner visits to grant consent. The provider redirects back to your redirect_uri with a code.
  2. get_token/2 — exchange that code for a DomainConnect.Token.
  3. apply/3 — apply your template(s) using the token. Re-runnable; on a record conflict it returns {:error, :conflict} unless force: true.
  4. refresh/2 — exchange a refresh token for a fresh access token.

Every request that this library makes server-side (get_token/2, apply/3, refresh/2) hits the provider's urlAPI, which is taken from the discovered settings and is therefore DNS-influenced — so its host is SSRF-guarded (DomainConnect.HostGuard), redirects are disabled, and timeouts are tight. consent_url/2 is a pure builder (the owner's browser makes that request).

Summary

Functions

Applies a template using an access token.

Builds the OAuth consent URL to redirect the domain owner to.

Exchanges an authorization code for a DomainConnect.Token.

Refreshes an access token.

Functions

apply(config, token, opts)

@spec apply(DomainConnect.Config.t(), DomainConnect.Token.t(), keyword()) ::
  :ok | {:error, term()}

Applies a template using an access token.

Required options

  • :provider_id, :service_id.

Optional options

  • :params (string-keyed map; reserved keys rejected), :group_ids (string or list), :force (boolean — override a record conflict).

Returns :ok, {:error, :conflict} (records already present; retry with force: true), or {:error, reason}.

get_token(config, opts)

@spec get_token(
  DomainConnect.Config.t(),
  keyword()
) :: {:ok, DomainConnect.Token.t()} | {:error, term()}

Exchanges an authorization code for a DomainConnect.Token.

Required options

  • :code, :client_id, :client_secret, :redirect_uri.

Returns {:ok, %DomainConnect.Token{}} or {:error, reason}.

refresh(config, opts)

@spec refresh(
  DomainConnect.Config.t(),
  keyword()
) :: {:ok, DomainConnect.Token.t()} | {:error, term()}

Refreshes an access token.

Required options

  • :refresh_token, :client_id, :client_secret.