Monzo.TokenStore (monzo_client v1.0.0)

Copy Markdown View Source

A supervised GenServer holding the current access/refresh token pair for one Monzo user, and performing the actual refresh call.

You normally don't interact with this module directly - Monzo.Client starts and owns one automatically. It's exposed publicly for advanced use cases: sharing a single token store across multiple clients, or wiring it into your own supervision tree with a registered :name.

Summary

Functions

Returns the current access token, or nil.

Refreshes the access token using the stored refresh token and client credentials. Returns {:error, :no_refresh_credentials} without making any request if they aren't configured.

Manually sets new tokens (e.g. after completing the OAuth flow).

Starts a token store process directly (e.g. under your own supervision tree).

Starts a token store under Monzo.TokenStore.Supervisor, unlinked from the caller.

Types

t()

@type t() :: %Monzo.TokenStore{
  access_token: String.t() | nil,
  adapter: module(),
  base_url: String.t(),
  client_id: String.t() | nil,
  client_secret: String.t() | nil,
  on_refresh: (String.t(), String.t() | nil -> any()) | nil,
  refresh_token: String.t() | nil
}

Functions

access_token(server)

@spec access_token(GenServer.server()) :: String.t() | nil

Returns the current access token, or nil.

refresh(server)

@spec refresh(GenServer.server()) :: {:ok, String.t()} | {:error, term()}

Refreshes the access token using the stored refresh token and client credentials. Returns {:error, :no_refresh_credentials} without making any request if they aren't configured.

set_tokens(server, access_token, refresh_token \\ nil)

@spec set_tokens(GenServer.server(), String.t(), String.t() | nil) :: :ok

Manually sets new tokens (e.g. after completing the OAuth flow).

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a token store process directly (e.g. under your own supervision tree).

start_supervised(opts)

@spec start_supervised(keyword()) :: DynamicSupervisor.on_start_child()

Starts a token store under Monzo.TokenStore.Supervisor, unlinked from the caller.