OAuth authorization-code, refresh-token and device-code helpers, following the official Go and TypeScript SDKs. JSON bodies are used, not HTTP Basic auth.
Call authorization_url/2 with a fresh generate_state/0; persist it in the
user's server session and validate the callback with validate_state/2 before
exchanging the code. Tokens are returned as OAuth.Token structs. Save the new
refresh token after every successful refresh. These functions do not store
credentials; ExFattureincloud.OAuth.TokenManager optionally coordinates
renewal and application-provided persistence callbacks.
Device authorization requires provider enablement. device_token/2 performs
exactly one poll: schedule subsequent polls using the returned interval and
handle authorization_pending/slow_down through Error.code.
Summary
Functions
Builds the URL for the Authorization Code Flow browser redirect.
Requests a device code using :client_id and :scope, returning the provider's data as a map.
Makes one device-token poll using :client_id and :device_code.
Exchanges an authorization code using :client_id, :client_secret, :redirect_uri, and :code.
Generates a cryptographically random URL-safe state value.
Refreshes the access token using :client_id and :refresh_token.
Constant-time comparison; rejects missing or empty state values.
Functions
@spec authorization_url(ExFattureincloud.Client.t(), keyword()) :: String.t()
Builds the URL for the Authorization Code Flow browser redirect.
Requires :client_id, the registered :redirect_uri, a :scope string or
list, and the :state returned by generate_state/0.
@spec device_code(ExFattureincloud.Client.t(), keyword()) :: {:ok, map()} | {:error, ExFattureincloud.Error.t()}
Requests a device code using :client_id and :scope, returning the provider's data as a map.
@spec device_token(ExFattureincloud.Client.t(), keyword()) :: {:ok, ExFattureincloud.OAuth.Token.t()} | {:error, ExFattureincloud.Error.t()}
Makes one device-token poll using :client_id and :device_code.
@spec exchange_code(ExFattureincloud.Client.t(), keyword()) :: {:ok, ExFattureincloud.OAuth.Token.t()} | {:error, ExFattureincloud.Error.t()}
Exchanges an authorization code using :client_id, :client_secret, :redirect_uri, and :code.
@spec generate_state() :: String.t()
Generates a cryptographically random URL-safe state value.
@spec refresh_token(ExFattureincloud.Client.t(), keyword()) :: {:ok, ExFattureincloud.OAuth.Token.t()} | {:error, ExFattureincloud.Error.t()}
Refreshes the access token using :client_id and :refresh_token.
Pass :client_secret for Authorization Code Flow. If the response omits a
refresh token, keep the previous refresh token when persisting the result.
Constant-time comparison; rejects missing or empty state values.