The OAuth2 authentication flow: building the authorization URL, exchanging a code, refreshing tokens, logging out, and token introspection.
Most applications don't call exchange_code/2 or refresh_token/2
directly - Monzo.Client and its Monzo.TokenStore handle the token
lifecycle automatically. This module is here for the initial
authorization-code exchange (which necessarily happens before you have a
client with tokens) and for advanced manual control.
Summary
Functions
Builds the URL to send a user's browser to in order to begin the OAuth2 authorization-code flow.
Same as build_authorization_url/1 but raises on invalid input.
Exchanges a temporary authorization code (from the OAuth callback) for an
access token. client need not have any tokens configured yet.
Immediately invalidates the client's current access token server-side.
Exchanges a refresh token for a new access token. This is a one-time-use operation on the refresh token - Monzo issues a new one alongside the new access token.
Returns metadata about the client's currently configured access token.
Types
Functions
@spec build_authorization_url(authorization_url_params()) :: {:ok, String.t()} | {:error, Monzo.Error.ValidationError.t()}
Builds the URL to send a user's browser to in order to begin the OAuth2 authorization-code flow.
Always generate and persist a random :state value (see
Monzo.Security.generate_state/1) and verify it on callback with
Monzo.Security.constant_time_equal?/2.
@spec build_authorization_url!(authorization_url_params()) :: String.t()
Same as build_authorization_url/1 but raises on invalid input.
@spec exchange_code(Monzo.Client.t(), exchange_code_params()) :: {:ok, Monzo.Auth.Token.t()} | {:error, Exception.t()}
Exchanges a temporary authorization code (from the OAuth callback) for an
access token. client need not have any tokens configured yet.
@spec logout(Monzo.Client.t()) :: :ok | {:error, Exception.t()}
Immediately invalidates the client's current access token server-side.
@spec refresh_token(Monzo.Client.t(), refresh_token_params()) :: {:ok, Monzo.Auth.Token.t()} | {:error, Exception.t()}
Exchanges a refresh token for a new access token. This is a one-time-use operation on the refresh token - Monzo issues a new one alongside the new access token.
@spec who_am_i(Monzo.Client.t()) :: {:ok, Monzo.Auth.WhoAmI.t()} | {:error, Exception.t()}
Returns metadata about the client's currently configured access token.