Skip to content

AuthContext

AuthContext = { type: "asApp"; } | { type: "asUser"; userId?: string; } | { accessToken: string; accountId: string; type: "offlineUser"; }

Defined in: packages/core/src/adapters/ForgeAdapter.ts:19

Discriminated union describing who is making an API request.

  • asApp — the Forge app itself (app-scoped permissions)
  • asUser — a live user session (the currently invoking user, or a specific userId)
  • offlineUser — a user impersonated without a live session via a pre-fetched access token

Create auth contexts with the helper functions asApp, asUser, or asOfflineUser rather than constructing this union type directly.

{ type: "asApp"; }


{ type: "asUser"; userId?: string; }


{ accessToken: string; accountId: string; type: "offlineUser"; }

accessToken: string

A short-lived access token for the given accountId. Obtain this via OfflineTokenManager.getToken() or ForgeRemoteTokenManager.getToken() before constructing the auth context. Token fetching is always the caller’s responsibility — the adapter uses the token as-is and never fetches one internally.

const token = await tokenManager.getToken(accountId);
const client = asOfflineUser(adapter, token.accountId, token.accessToken);

accountId: string

type: "offlineUser"