Process wrapper around an Exosphere.ATProto.OAuth.Session that keeps the
session fresh and makes DPoP-signed XRPC calls.
The GenServer serializes access to the rotating refresh token (concurrent
refresh attempts would burn it), refreshes eagerly when the access token
nears expiry, and retries once through a refresh when the server rejects an
expired token. Use Exosphere.ATProto.OAuth.Flow to produce the session,
then park it here:
{:ok, session} = Exosphere.ATProto.OAuth.Flow.callback(ctx, params)
{:ok, pid} = Exosphere.OAuth.Session.start_link(session: session, name: {:via, Registry, ...})
{:ok, %{"did" => did}} = Exosphere.OAuth.Session.query(pid, "com.atproto.identity.resolveHandle",
handle: "atproto.com")For persistence beyond the process lifetime, serialize with
Exosphere.ATProto.OAuth.Session.to_map/1 (e.g. into your database after
handle_call returns, or via the :on_refresh callback) and restore with
from_map/1.
Options for start_link/1
:session- the%Exosphere.ATProto.OAuth.Session{}(required):on_refresh-{m, f, a}or a 1-arity fun invoked with each refreshed session, so callers can persist rotated tokens:name- GenServer name
Summary
Functions
Returns a specification to start this module under a supervisor.
The current session struct.
An XRPC procedure (POST) through the session's DPoP-bound client, with the
same refresh handling as query/3.
An XRPC query (GET) through the session's DPoP-bound client, refreshing first when the access token has expired and retrying once through a refresh when the server reports an expired token.
Refresh now (rotates the refresh token).
Start a session process.
The XRPC client for the session — a plain data struct, useful for
Exosphere.ATProto.Repo and other direct consumers.
Types
@type server() :: GenServer.server()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get(server()) :: Exosphere.ATProto.OAuth.Session.t()
The current session struct.
An XRPC procedure (POST) through the session's DPoP-bound client, with the
same refresh handling as query/3.
An XRPC query (GET) through the session's DPoP-bound client, refreshing first when the access token has expired and retrying once through a refresh when the server reports an expired token.
@spec refresh(server()) :: {:ok, Exosphere.ATProto.OAuth.Session.t()} | {:error, term()}
Refresh now (rotates the refresh token).
@spec start_link(keyword() | Exosphere.ATProto.OAuth.Session.t()) :: GenServer.on_start()
Start a session process.
Accepts the options listed in the module documentation, or the session struct directly.
@spec xrpc_client(Exosphere.ATProto.OAuth.Session.t()) :: Exosphere.ATProto.XRPC.Client.t()
The XRPC client for the session — a plain data struct, useful for
Exosphere.ATProto.Repo and other direct consumers.