Solaris.Auth (Solaris v1.0.0)

Copy Markdown View Source

OAuth2 client-credentials token manager.

Fetches a Bearer token from the Solaris OAuth2 endpoint, caches it in :persistent_term for zero-serialization reads, and proactively refreshes it 60 seconds before expiry via an internal timer.

Started automatically by Solaris.Application. All Solaris API calls go through get_token/0 which returns the cached token if still valid.

Caching strategy

Tokens are stored under a single :persistent_term key. Reads are O(1) with no GenServer round-trip in the hot path. Only cache misses and forced refreshes serialise through the GenServer.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns a valid Bearer access token.

Force-refreshes the access token regardless of cache state.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_token()

@spec get_token() :: {:ok, String.t()} | {:error, term()}

Returns a valid Bearer access token.

Reads from the :persistent_term cache when possible (no GenServer call). Falls back to a synchronous token fetch on cache miss or near-expiry.

refresh_token()

@spec refresh_token() :: {:ok, String.t()} | {:error, term()}

Force-refreshes the access token regardless of cache state.