Using Outbound Apps
For hands-on examples of outbound apps in action, check out our Examples Guide, which includes tool-calling examples for AI agents.
After configuring an Outbound App in Descope and connecting your users to it, you can start using the tokens to access third-party APIs on behalf of your users.
With Outbound Apps, you can fetch the tokens and use them to make authenticated requests to third-party provider APIs, enabling seamless integration without exposing sensitive credentials to your application.
Fetching Outbound Apps Tokens
To retrieve a user's token for an outbound app, you'll use Descope's Management API with your Project ID and Management Key.
Descope provides two methods for fetching user-level outbound app tokens, depending on whether you know the exact scopes you need:
Fetch Latest User Token (Recommended)
This method is recommended when you don't know the exact scopes or just need the most recent valid token, regardless of scopes.
Request Parameters
appId
(required): The ID of the outbound app.userId
(required): The user ID for whom to fetch the token.tenantId
(optional): The tenant ID of the user, if a user has multiple tokens associated with different tenants.options
(optional): Additional options for token fetching.withRefreshToken
: Defaults to false. Set this to true to include the refresh token in the response.forceRefresh
: Defaults to false. The API will return a refreshed token regardless of this value, but this will force our service to refresh the token on the client's behalf.
Fetch Token with Specific Scopes
Use this method when you need a token with specific scopes. Important: You must provide the exact scopes that were used when the token was created. Otherwise, you'll receive a 404 Token not found
error.
Request Parameters
appId
(required): The ID of the outbound app.userId
(required): The user ID for whom to fetch the token.tenantId
(optional, required if no userId): The tenant ID of the user, if a user has multiple tokens associated with different tenants.scopes
(required): An array of exact scopes that match the original token.options
(optional): Additional options for token fetching.withRefreshToken
: Defaults to false. Set this to true to include the refresh token in the response.forceRefresh
: Defaults to false. The API will return a refreshed token regardless of this value, but this will force our service to refresh the token on the client's behalf.
Fetching Tenant-Level Tokens
In addition to user-specific tokens, you can also fetch tenant-level tokens for outbound apps. These are useful when you need to access APIs on behalf of a tenant rather than a specific user.
Descope provides the same two methods for tenant-level outbound app tokens as user-level tokens. Depending on whether you know the exact scopes of the token you need, you can use the following methods:
Fetch Latest Tenant Token (Recommended)
This method is recommended when you don't know the exact scopes or want the most recent valid token for the tenant, regardless of scopes.
Latest Tenant Token Request Parameters
The tenant-level APIs use a similar request schema:
appId
(required): The ID of the outbound app.tenantId
(optional, required if no userId): The tenant ID if you're fetching a tenant-level token.options
(optional): Additional options for token fetching.withRefreshToken
: Defaults to false. Set this to true to include the refresh token in the response.forceRefresh
: Defaults to false. The API will return a refreshed token regardless of this value, but this will force our service to refresh the token on the client's behalf.
Fetch Tenant Token with Specific Scopes
Use this method when you need a tenant token with specific scopes. Important: You must provide the exact scopes that were used when the token was created. Otherwise, you'll receive a 404 Token not found
error.
Specific Tenant Token Request Parameters
The tenant-level APIs use a similar request schema:
appId
(required): The ID of the outbound app.tenantId
(optional, required if no userId): The tenant ID if you're fetching a tenant-level token.scopes
(required): An array of exact scopes that match the original token.options
(optional): Additional options for token fetching.withRefreshToken
: Defaults to false. Set this to true to include the refresh token in the response.forceRefresh
: Defaults to false. The API will return a refreshed token regardless of this value, but this will force our service to refresh the token on the client's behalf.
Outbound App Token Response
The refresh_token
will not be returned unless withRefreshToken
is set to true in the request.
The response will include the user/tenant token details, similar to the example below:
Using Tokens with Third-Party APIs
Once you have the access token, you can use it to make authenticated requests to the third-party provider's API.
Example: Google Contacts API
The following example shows how to fetch a user's contacts using the Google Contacts API with a token obtained from an outbound app.
For more detailed examples and AI agent implementations, see our Examples Guide.
Token Management Best Practices
Error Handling
When working with outbound app tokens, you may encounter different types of errors. Here's what each error code means and how to handle them:
Common Error Codes
Status Code | Meaning | Common Causes |
---|---|---|
401 | Unauthorized | Invalid management key or project ID |
403 | Forbidden | Insufficient permissions or invalid tenant access |
404 | Token not found | User never connected to the app, token was cleared, or wrong scopes provided |
500 | Server error | Invalid HTTP method (not POST) or malformed JSON payload |
Example Error Handling
Scope Management
When connecting to outbound apps, ensure you only request the scopes your application/agent actually needs.