adk_token_manager (erlang_adk v0.7.0)
View SourceConcurrent, scoped access-token cache and refresh coordinator.
A request is keyed by principal, provider, credential reference, scopes, and audience. The credential-consuming module and its base context come only from immutable, operator-supplied provider profiles; callers cannot choose either value. Concurrent callers for the same key share one supervised refresh. Access tokens and pending provider context are retained only in owner-private ETS tables, never in inspectable gen_server state.
Summary
Functions
Resolve a cached token or join/start a refresh. The caller-side alias is explicitly disabled on timeout, so a late token can never remain in the caller's mailbox.
Invalidate cached tokens and cancel matching in-flight refreshes.
Types
-type error_reason() :: invalid_request | manager_unavailable | caller_timeout | credential_not_found | credential_store_unavailable | credential_rotation_conflict | credential_rotation_failed | invalid_provider_response | refresh_timeout | refresh_worker_failed | refresh_start_failed | unknown_provider | scope_not_allowed | audience_not_allowed | refresh_capacity_reached | waiter_capacity_reached | token_invalidated | provider_process_failed | invalid_refresh_work | {provider_error, term()} | {provider_exception, atom(), term()}.
-type token_request() :: #{principal := adk_credential_store:principal(), provider := adk_credential_store:provider_id(), credential_ref := adk_credential_store:credential_ref(), scopes => [binary()], audience => undefined | binary(), provider_module => term(), context => map()}.
Functions
-spec child_spec(map()) -> supervisor:child_spec().
-spec get_token(server(), token_request()) -> {ok, token()} | {error, error_reason()}.
-spec get_token(server(), token_request(), pos_integer()) -> {ok, token()} | {error, error_reason()}.
Resolve a cached token or join/start a refresh. The caller-side alias is explicitly disabled on timeout, so a late token can never remain in the caller's mailbox.
-spec invalidate(server(), map()) -> {ok, non_neg_integer()} | {error, invalid_request | manager_unavailable}.
Invalidate cached tokens and cancel matching in-flight refreshes.
The selector must contain principal, provider, and the opaque credential_ref. Requiring the capability-like reference prevents a caller from evicting every token for a guessed tenant/provider pair. The count includes both deleted cache entries and cancelled refreshes. Waiters on a cancelled refresh receive {error, token_invalidated}.
-spec start_link() -> gen_server:start_ret().
-spec start_link(map()) -> gen_server:start_ret().