Guides and TutorialsAgent Platforms

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.

User's appCLI or web appAgentCoreJWT authorizerAgentyour agent codeDescopeauthz serverYour APIResourceThird-party APIe.g. Google DriveBefore the first callJWT authorizer configResource + clientsPolicy rules1. sign in (PKCE, resource = agent client ID)user token2. Bearer user tokencheck iss, aud, azpforward header3. client_credentialsM2M access ruleagent tokencall as the agent4. token exchangeDelegated access ruledelegated tokencall for the user5. Connection tokenuser's Google tokencall as the user

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.

  1. Resource: Create a Resource for your API, for example ops-api with the identifier https://ops-api.example.com and the scopes fleet:read and tickets:read.
  2. 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 agent lets 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.
  3. 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.
  4. 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:read on ops-api, and a Delegated access (token exchange) rule grants it tickets: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:

EndpointURL
Discovery documenthttps://api.descope.com/v1/apps/<project-id>/.well-known/openid-configuration
Issuerhttps://api.descope.com/v1/apps/<project-id>
Token endpointhttps://api.descope.com/oauth2/v1/apps/token
Signing keyshttps://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:

ClaimValue
isshttps://api.descope.com/v1/apps/<project-id>
subThe user's ID
audThe sign-in client ID, the project ID, and the agent client ID
azpThe 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 Authorization

Three settings matter here:

  • allowedAudience is the agent client ID, which the sign-in step put in aud.
  • customClaims requires azp to be the sign-in client. The authorizer's allowedClients option checks a client_id claim, which Descope user tokens don't carry, so azp is the claim to match.
  • --request-header-allowlist Authorization forwards 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:read

The 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:read

The 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 ClientIdExchange event. The per-request ClientCredentialsGrantSuccess and TokenExchangeSuccess events 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.

SymptomLikely cause
AgentCore returns 401 before your code runsThe 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 headerAuthorization 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 endpointAgentic clients use /oauth2/v1/apps/token, not /oauth2/v1/token.
Invalid client id on a token exchangeThe exchange wasn't authenticated with the agent's client ID and secret.
Was this helpful?

On this page