Amazon Bedrock AgentCore
Amazon Bedrock AgentCore runs agents on AWS. Descope gives each of those agents its own identity, and Policies decide what each agent can reach.
An agent on AgentCore Runtime usually makes three kinds of calls. It calls your API as itself, it calls your API for the signed-in user, and it calls a third-party API such as Google Drive with the user's own token. Descope issues a separate, narrowly scoped token for each call, so your API always knows which agent is calling and for whom.
Select any step to see what happens.
Setting Up Descope
You can create everything below in the Agentic Identity Hub, or with the Management API if you register agents from a deploy pipeline.
- Resource: Create a Resource for your API, for example
ops-apiwith the identifierhttps://ops-api.example.comand the scopesfleet:readandtickets:read. - Agent client: Create a confidential client with the Client Credentials grant type, and copy its client ID. Token exchange is allowed by the Delegated access rule in step 4, not by a client setting. A tag such as
agentlets Policies and reports find it. Under Session Management, shorten Access key session token timeout (tokens the agent gets as itself) and Session token timeout (tokens it gets for users). Five minutes is a reasonable start. Every Resource the agent calls gets tokens with these lifetimes. - Sign-in client: Create a client for the app users sign in with, such as a CLI, with the authorization code grant, PKCE, and its redirect URI.
- Policy rules: Add one rule for each kind of request the agent makes, as described in Choosing the Rule for a Request. In this example, a Machine-to-Machine (M2M) access rule grants the agent client
fleet:readonops-api, and a Delegated access (token exchange) rule grants ittickets:read. If the agent reads third-party tokens, add a rule with the Connection as its target.
To automate this setup, Terraform's descope_inbound_app resource manages clients, but not Policy rules. You can manage the rules with the Policy Rules Management API instead. When you list clients with the Load all third party applications (v2) endpoint, the response returns them in apps, with a total count.
Agentic clients have their own discovery document, issuer, and token endpoint:
| Endpoint | URL |
|---|---|
| Discovery document | https://api.descope.com/v1/apps/<project-id>/.well-known/openid-configuration |
| Issuer | https://api.descope.com/v1/apps/<project-id> |
| Token endpoint | https://api.descope.com/oauth2/v1/apps/token |
| Signing keys | https://api.descope.com/<project-id>/.well-known/jwks.json |
Signing the User In
Your app signs the user in with the authorization code flow and PKCE, using the sign-in client. On the authorization request, pass the agent client's ID as resource. Descope then adds the agent client ID to the token's aud, which is the claim AgentCore checks:
| Claim | Value |
|---|---|
iss | https://api.descope.com/v1/apps/<project-id> |
sub | The user's ID |
aud | The sign-in client ID, the project ID, and the agent client ID |
azp | The sign-in client ID |
Your app then sends this token to the agent as Authorization: Bearer <token>.
Configuring the AgentCore Authorizer
AgentCore Runtime validates inbound tokens with a custom JWT authorizer. The following AgentCore CLI command creates a runtime whose authorizer trusts Descope and accepts only tokens from your sign-in client:
agentcore add runtime \
--name ops_assistant \
--language python \
--protocol HTTP \
--authorizer-type CUSTOM_JWT \
--authorizer-configuration '{"customJwtAuthorizer":{
"discoveryUrl":"https://api.descope.com/v1/apps/<project-id>/.well-known/openid-configuration",
"allowedAudience":["<agent client ID>"],
"customClaims":[{
"inboundTokenClaimName":"azp",
"inboundTokenClaimValueType":"STRING",
"authorizingClaimMatchValue":{
"claimMatchOperator":"EQUALS",
"claimMatchValue":{"matchValueString":"<sign-in client ID>"}}}]}}' \
--request-header-allowlist AuthorizationThree settings matter here:
allowedAudienceis the agent client ID, which the sign-in step put inaud.customClaimsrequiresazpto be the sign-in client. The authorizer'sallowedClientsoption checks aclient_idclaim, which Descope user tokens don't carry, soazpis the claim to match.--request-header-allowlist Authorizationforwards the user's token to your agent code, which needs it for token exchange and Connections.
The same customJwtAuthorizer settings work for an AgentCore Gateway in front of your tools.
Your agent code should validate the token again (signature, iss, exp, aud, and azp), so it stays safe when it runs without the authorizer, such as locally. Descope's key endpoint can return HTTP 403 when a request has a library's default User-Agent, such as Python urllib's, so set your own User-Agent when you fetch the signing keys.
Authenticating the Agent Client
The agent client's authentication method can be a Client Secret, Private Key JWT, Workload Identity Federation, or an mTLS Certificate on a project with a custom domain. Each method changes only the authentication parameters of a token request, so the requests below stay the same.
With Workload Identity Federation, the agent presents a token that its platform already issued, from an OIDC issuer you trust. That token's aud must be your project's issuer URL and nothing else, so the issuer has to let you choose the audience.
On AWS, IAM outbound identity federation issues such a token. Once outbound identity federation is enabled for the account, the runtime's execution role calls the STS GetWebIdentityToken API with Audience set to your project's issuer URL, and Descope trusts your account's STS issuer. The execution role needs permission for sts:GetWebIdentityToken.
Every role in the account gets its token from the same STS issuer, so set Allowed Subjects to the execution role's ARN, such as arn:aws:iam::123456789012:role/AgentRuntimeRole, and nothing broader. STS puts that ARN in the token's sub claim.
If you keep a client secret, store it in AWS Secrets Manager rather than in the runtime's plain configuration.
Getting Tokens in the Agent
The agent gets its own tokens and delegated tokens from the token endpoint, https://api.descope.com/oauth2/v1/apps/token. Each request authenticates as the agent client. The examples use a client secret with HTTP Basic, and client_id and client_secret in the form body also work. The Claims in Agent Tokens table shows how each token identifies the agent.
The Agent Acting as Itself
When no user is involved, the agent sends a client_credentials request that names the Resource. The M2M access rule decides which scopes the token gets:
curl -s https://api.descope.com/oauth2/v1/apps/token \
-u "$AGENT_CLIENT_ID:$AGENT_CLIENT_SECRET" \
-d grant_type=client_credentials \
-d resource=https://ops-api.example.com \
-d scope=fleet:readThe token's sub is the agent client's app ID, not its client ID, and azp is the client ID. Its aud includes https://ops-api.example.com.
Include resource
Without resource, a request for a Resource's scope fails with Requested invalid scope which is not known to the application, even when an M2M rule grants that scope.
The Agent Acting for the User
To act for the user, the agent exchanges the user's token with token exchange. The Delegated access rule decides which scopes the token gets:
curl -s https://api.descope.com/oauth2/v1/apps/token \
-u "$AGENT_CLIENT_ID:$AGENT_CLIENT_SECRET" \
-d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
-d subject_token="$USER_TOKEN" \
-d subject_token_type=urn:ietf:params:oauth:token-type:access_token \
-d resource=https://ops-api.example.com \
-d scope=tickets:readThe new token's sub is the user and act is {"sub": "<agent client ID>"}. Your API checks aud and the scope as usual, and can read act.sub to see which agent is acting for the user.
The User's Third-Party Token
To call a third-party API as the user, such as Google Drive, the agent fetches a Connection token with the user's access token. Descope stores and refreshes the third-party token, and the agent holds it only for the call.
The Agent Auth SDK makes this request for you. One client, signed in as the agent, can fetch tokens for each user by passing that user's token with the call:
from descope_agent_auth import AgentAuthClient, ClientCredentialsProvider
from descope_agent_auth.errors import ConnectionAuthorizationRequired
client = AgentAuthClient(
project_id=PROJECT_ID,
credential=ClientCredentialsProvider(client_id=AGENT_CLIENT_ID, client_secret=AGENT_CLIENT_SECRET),
)
try:
drive = client.connections.get_token(
connection="google-drive", identifier=user_id, act_as_user_token=user_token
)
except ConnectionAuthorizationRequired as e:
... # The user hasn't connected the account yet. Send them the connect URL in e.Operating Agents
After the agent is live, you manage it through its Policy rules and the audit trail:
- Turning an agent off: When you disable the agent's rules, give them an expiration date, or revoke the agent, Descope issues no new tokens to it. Your APIs validate tokens locally against Descope's signing keys, so a token the agent already holds stays valid until it expires. Short agent token lifetimes keep that window small.
- Removing users: With SCIM provisioning from your IdP, Descope marks a deactivated user inactive, and their sessions can't refresh.
- Finding agents: The Agent Directory lists every agent that has a Descope client. With Agent Governance, employees can request a client for a new agent.
- Auditing: Descope always counts the tokens each client gets in the
ClientIdExchangeevent. The per-requestClientCredentialsGrantSuccessandTokenExchangeSuccessevents are off by default, and Descope Support can turn them on for your project. These events record the client, the user, the Resource, the audience, and the scopes, and a delegated exchange also records the actor chain. - Connection fetches: Descope doesn't record a successful Connection token fetch in the audit trail. Descope logs a denied fetch as a policy violation.
- Streaming to a SIEM: The Splunk connector forwards these audit events with the same fields, which the audit events reference lists for each event.
Troubleshooting
Most failures come from a mismatch between the token and the authorizer, or from a request that doesn't match a Policy rule. Choosing the Rule for a Request lists the Policy errors.
| Symptom | Likely cause |
|---|---|
| AgentCore returns 401 before your code runs | The token's iss doesn't match the discovery document, aud doesn't contain the agent client ID (check resource on sign-in), or azp isn't the sign-in client. |
Your code gets no Authorization header | Authorization isn't in the runtime's request header allowlist. |
| Every token fails while fetching signing keys (HTTP 403) | The JWKS request has no User-Agent header, or sends a library's default, such as Python urllib's. |
Project does not exist from the token endpoint | Agentic clients use /oauth2/v1/apps/token, not /oauth2/v1/token. |
Invalid client id on a token exchange | The exchange wasn't authenticated with the agent's client ID and secret. |