Skip to content

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.

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' } });

new OfflineTokenManager(opts): OfflineTokenManager

Defined in: packages/core/src/auth/OfflineTokenManager.ts:59

Create a new OfflineTokenManager.

OfflineTokenManagerOptions

Configuration including the proxy URL and installation ID

OfflineTokenManager

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.

ForgeAdapter

string

Promise<BoundClient>

const client = await tokenManager.boundClient(adapter, accountId);
const issue = await getIssue(client, { issueIdOrKey: 'PROJ-1' });

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.

string

Promise<OfflineUserToken>


invalidate(accountId): void

Defined in: packages/core/src/auth/OfflineTokenManager.ts:82

Remove a cached token, forcing a fresh fetch on next getToken() call

string

void


invalidateAll(): void

Defined in: packages/core/src/auth/OfflineTokenManager.ts:87

Remove all cached tokens

void