Outbound Apps with SDKs
You can use the Descope management SDK to fetch, delete, and manage Outbound App tokens. The management SDK requires a management key, which can be generated from the Company Settings page of the Descope console.
Install SDK
npm install @descope/node-sdkImport and initialize Management SDK
import DescopeClient from '@descope/node-sdk';
// Initialized using environment variables DESCOPE_PROJECT_ID and DESCOPE_MANAGEMENT_KEY
const descopeClient = DescopeClient();
// Or directly
const descopeClient = DescopeClient({
projectId: '__ProjectID__',
managementKey: 'management-key'
});Fetch Outbound App Token
Fetch an access token for a specific outbound app and user. This is useful when you need to make API calls to third-party services on behalf of a user.
// Args:
// appId (string): Outbound app ID (required)
// userId (string): User ID (required)
// tenantId (string): Optional tenant ID
// options (object): Optional request options
try {
const token = await descopeClient.management.outboundApplication.fetchToken(
'app-id',
'user-id'
);
const accessToken = token.data.accessToken;
} catch (error) {
// Handle the error
}Fetch Outbound App Token by Scopes
Fetch an access token with specific scopes for a user.
// Args:
// appId (string): Outbound app ID (required)
// userId (string): User ID (required)
// scopes (string[]): List of scopes to request (required)
// options (object): Optional request options
// tenantId (string): Optional tenant ID
try {
const token = await descopeClient.management.outboundApplication.fetchTokenByScopes(
'app-id',
'user-id',
['read', 'write']
);
const accessToken = token.data.accessToken;
} catch (error) {
// Handle the error
}Delete Outbound App Token by Token ID
This operation deletes a specific outbound app token by its token ID.
// Args:
// id (string): The token ID to delete
try {
await descopeClient.management.outboundApplication.deleteTokenById('token-id');
} catch (error) {
// Handle the error
}Delete All Outbound App Tokens for a User
This operation deletes all outbound app tokens for a given user and app.
// Args:
// appId (string): Optional outbound app ID
// userId (string): Optional user ID
try {
// Delete this user's tokens for this app
await descopeClient.management.outboundApplication.deleteUserTokens('app-id', 'user-id');
// Delete all tokens for the app
await descopeClient.management.outboundApplication.deleteUserTokens('app-id');
// Delete all tokens for the user
await descopeClient.management.outboundApplication.deleteUserTokens(undefined, 'user-id');
} catch (error) {
// Handle the error
} Was this helpful?