Helpers for Mercury's OAuth2 authorization flow (partner integrations).
Unlike every other resource module, these functions do not send the
client's API key — authorize_url/2 and exchange_code/2 talk to the
public OAuth endpoints directly, using only the client's configured
:base_url and :timeout.
Summary
Functions
Builds the authorization redirect URL for the OAuth2 consent flow.
Redirect users to this URL to begin authorization. GET /oauth/authorize
Exchanges an authorization code for an access token. POST /oauth/token
Same as exchange_code/2 but raises on error.
Functions
@spec authorize_url(client :: Mercury.Client.t(), opts :: keyword()) :: String.t()
Builds the authorization redirect URL for the OAuth2 consent flow.
Redirect users to this URL to begin authorization. GET /oauth/authorize
Options
:client_id— required.:redirect_uri— required.:scope— optional space-separated scope string.:state— optional opaque state parameter for CSRF protection.
@spec exchange_code(client :: Mercury.Client.t(), opts :: keyword()) :: {:ok, Mercury.OAuth2Token.t()} | {:error, Exception.t()}
Exchanges an authorization code for an access token. POST /oauth/token
Options
:code— required, the authorization code received on your redirect URI.:redirect_uri— required, must match the one used inauthorize_url/2.:client_id— required.:client_secret— required.:grant_type— defaults to"authorization_code".
@spec exchange_code!(client :: Mercury.Client.t(), opts :: keyword()) :: Mercury.OAuth2Token.t()
Same as exchange_code/2 but raises on error.