In-memory OAuth token storage.
Stores tokens in an ETS table owned by the first process that writes to it. Useful for tests, ephemeral CLI sessions, and long-running server processes that prefer in-process state over disk files.
Mirrors the in-memory TokenStorage patterns used by
longbridge/openapi Rust SDK tests (added in 4.2.0).
Usage
Longbridge.OAuth.authorize("client-id",
storage: Longbridge.OAuth.InMemoryTokenStorage
)The underlying ETS table is created lazily on first save and persists for the lifetime of the BEAM VM. There is no explicit start step.
Token lifetime
Tokens stored here are lost when the BEAM VM stops. Use
Longbridge.OAuth.FileTokenStorage for persistence across
restarts.
Table owner
The ETS table is created with :protected access mode: only the
owning process can write, anyone can read. The owner is the
first process that calls save/2. Make sure that process
outlives the storage lifetime (typically the application's
supervisor).
Summary
Functions
Deletes the stored token for client_id. Returns :ok whether
or not the client_id was present (idempotent).
Returns the list of client_ids currently stored. Useful for
diagnostics and tests.
Resets the storage. Clears all stored tokens. Useful for tests.
Functions
@spec delete(String.t()) :: :ok
Deletes the stored token for client_id. Returns :ok whether
or not the client_id was present (idempotent).
@spec list_client_ids() :: [String.t()]
Returns the list of client_ids currently stored. Useful for
diagnostics and tests.
Returns [] if no tokens have been saved yet.
@spec reset() :: :ok
Resets the storage. Clears all stored tokens. Useful for tests.
Returns :ok.