OfflineTokenManager
Defined in: packages/core/src/auth/OfflineTokenManager.ts:51
Manages offline user impersonation tokens for Forge Containers.
Fetches short-lived user access tokens through the Forge egress proxy and caches them until they are close to expiry. This allows a Forge Container to make API calls on behalf of specific users without a live user session.
Example
Section titled “Example”import { ForgeContainerAdapter, OfflineTokenManager, asOfflineUser } from '@forge-clients/core';import { getIssue } from '@forge-clients/jira/v3';
const adapter = new ForgeContainerAdapter({ product: 'jira', proxyUrl, installationId });const tokenManager = new OfflineTokenManager({ proxyUrl, installationId });
const token = await tokenManager.getToken('atlassian-account-id');const client = asOfflineUser(adapter, token.accountId, token.accessToken);const issue = await getIssue(client, { path: { issueIdOrKey: 'PROJ-1' } });Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OfflineTokenManager(
opts):OfflineTokenManager
Defined in: packages/core/src/auth/OfflineTokenManager.ts:59
Create a new OfflineTokenManager.
Parameters
Section titled “Parameters”Configuration including the proxy URL and installation ID
Returns
Section titled “Returns”OfflineTokenManager
Methods
Section titled “Methods”boundClient()
Section titled “boundClient()”boundClient(
adapter,accountId):Promise<BoundClient>
Defined in: packages/core/src/auth/OfflineTokenManager.ts:99
Convenience method — fetch a valid token and return a BoundClient for offline user impersonation. Caches the token internally.
Parameters
Section titled “Parameters”adapter
Section titled “adapter”accountId
Section titled “accountId”string
Returns
Section titled “Returns”Promise<BoundClient>
Example
Section titled “Example”const client = await tokenManager.boundClient(adapter, accountId);const issue = await getIssue(client, { issueIdOrKey: 'PROJ-1' });getToken()
Section titled “getToken()”getToken(
accountId):Promise<OfflineUserToken>
Defined in: packages/core/src/auth/OfflineTokenManager.ts:68
Get a valid offline user token for the given accountId. Automatically fetches a new token if none is cached or if the cached token is within refreshBufferSeconds of expiry.
Parameters
Section titled “Parameters”accountId
Section titled “accountId”string
Returns
Section titled “Returns”Promise<OfflineUserToken>
invalidate()
Section titled “invalidate()”invalidate(
accountId):void
Defined in: packages/core/src/auth/OfflineTokenManager.ts:82
Remove a cached token, forcing a fresh fetch on next getToken() call
Parameters
Section titled “Parameters”accountId
Section titled “accountId”string
Returns
Section titled “Returns”void
invalidateAll()
Section titled “invalidateAll()”invalidateAll():
void
Defined in: packages/core/src/auth/OfflineTokenManager.ts:87
Remove all cached tokens
Returns
Section titled “Returns”void