Skip to content

fix(resources): authenticate token exchange and key cache per user - #47

Open
gaokevin1 wants to merge 2 commits into
mainfrom
fix/resource-token-exchange-client-auth
Open

gaokevin1 wants to merge 2 commits into
mainfrom
fix/resource-token-exchange-client-auth

Conversation

@gaokevin1

Copy link
Copy Markdown
Member

Description

Resource token exchange (resources.get_token / getToken) could not work against Descope, so an agent could not act on behalf of a user. It also cached user-scoped tokens without the user in the key, so one shared agent client could hand user A's Resource token to user B.

Checked against a live project's discovery documents and the token endpoints:

  • /v1/apps/<projectId>/.well-known/openid-configuration lists token_endpoint: /oauth2/v1/apps/token, with token-exchange and client_credentials among its grant types.
  • /oauth2/v1/apps/token rejects a token exchange without client authentication (E074130 Invalid client id).
  • /oauth2/v1/token (what the SDK used) doesn't resolve Agentic Client IDs (E071001 Project does not exist).

In a Nutshell

  • Send the Resource token exchange to /oauth2/v1/apps/token with client_id + client_secret, so the minted token has act.sub = the agent
  • New provider hook, token_exchange_client_auth() / tokenExchangeClientAuth(): ClientCredentialsProvider and CibaProvider (with a secret) supply client auth, and other providers return none
  • Fail fast with a clear error, before any request or approval prompt, when there's no confidential client to authenticate the exchange (for example AccessTokenProvider alone)
  • Key the Resource token cache by a SHA-256 of act_as_user_token (the raw token never goes in a store key), so users and the agent each get their own entry
  • ClientCredentialsProvider now acquires and refreshes on /oauth2/v1/apps/token
  • Drop the "RESOURCE token endpoint shape" UNVERIFIED note
  • Same changes in Python and TypeScript, with tests for each

Behaviour changes

  • resources.get_token on a client built with only AccessTokenProvider now raises AgentAuthError instead of sending a request. Descope would reject that request anyway. Use a ClientCredentialsProvider client with act_as_user_token.
  • ClientCredentialsProvider moves from /oauth2/v1/token to /oauth2/v1/apps/token. This rests on the discovery document and the endpoint probes; it hasn't been run end to end with a real Agentic Client yet.

Must

  • Tests
  • Documentation (if applicable)

🤖 Generated with Claude Code

Resource token exchange posted to /oauth2/v1/token without client auth.
Descope serves agentic token exchange only on the inbound-apps server
(/oauth2/v1/apps/token, per /v1/apps/<projectId> discovery) and requires
the exchanging client to authenticate; that client becomes act.sub.

- Send the exchange to /oauth2/v1/apps/token with client_id/client_secret
  from the configured provider (ClientCredentialsProvider, or CibaProvider
  with a secret)
- Fail fast, before any request or approval prompt, when the provider has
  no confidential client to authenticate the exchange
- Key the Resource token cache by a SHA-256 of act_as_user_token so a
  shared client never serves one user's token to another (or to the agent)
- Acquire and refresh ClientCredentialsProvider tokens on
  /oauth2/v1/apps/token, the Agentic Client token endpoint
- Same changes in Python and TypeScript

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shuni-bot

shuni-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🐕 Shuni Review

No new issues found.

🤖 Model: claude-opus-5.5 · Effort: medium


Review scope: Partial incremental re-review

Reviewed new changes (13)
  • AGENTS.md
  • README.md
  • docs/quickstart.md
  • python/descope_agent_auth/_http.py
  • python/descope_agent_auth/providers/access_token.py
  • python/descope_agent_auth/vault/resources.py
  • python/tests/test_exchange.py
  • python/tests/test_redaction.py
  • typescript/src/httpClient.ts
  • typescript/src/providers/accessToken.ts
  • typescript/src/redaction.test.ts
  • typescript/src/resources.test.ts
  • typescript/src/vault/resources.ts
Previously reviewed and unchanged: 17 files.

🐕 Review complete — View session on Shuni Portal 🐾

🤖 Model: claude-opus-5.5 · Effort: medium

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 2 inline findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

…ange tokens

Address review on #47:

- Key the Resource token cache by the authenticating client_id (act.sub)
  plus a SHA-256 of the subject token actually exchanged (the user's
  act_as_user_token or the phase-1 credential). The constant "agent"
  bucket let two clients, or two CIBA login_hints, share a token on a
  shared TokenStore. The subject is now resolved before the cache lookup.
- Redact subject_token, actor_token and client_assertion in debug logs;
  a user's JWT on the act_as_user_token path was logged in clear text.
- Docs: Resource tokens need a ClientCredentialsProvider client with
  act_as_user_token per call; AccessTokenProvider raises AgentAuthError.
  Updated README, AGENTS.md, quickstart and the AccessTokenProvider
  docstrings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant