Skip to content

feat: list and delete an identity's OAuth clients, scoped to the tenant - #452

Merged
KunalJavelin merged 2 commits into
mainfrom
feat/identity-oauth-clients
Oct 22, 2026
Merged

KunalJavelin merged 2 commits into
mainfrom
feat/identity-oauth-clients

Conversation

@KunalJavelin

@KunalJavelin KunalJavelin commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

An IdP app bound to one identity cannot be bound to another identity.

  • POST /external-issuers/{id}/bindings with oauth_client creates a private_key_jwt client linked to the identity (ensurePresentingClient).
  • client_id is unique, and DELETE /external-issuers/{id}/bindings/{binding_id} keeps the client. So binding the same app to a second identity with oauth_client is 409 client_conflict.
  • Deactivating the first identity does not help: it is a soft delete, so oauth_clients.identity_id is not cleared and the client keeps its id.
  • The only delete is DELETE /oauth/clients/{id}. It is an operator route: it takes any client UUID and has no tenant scope, because a client carries no tenant of its own. A tenant admin cannot be given that route.

Fix

Two admin routes that reach a client only through an identity resolved in the caller's tenant (GetTenant, then GetIdentity(id, account, project)):

  • GET /identities/{id}/oauth-clients lists the clients whose identity_id is that identity.
  • DELETE /identities/{id}/oauth-clients/{client_uuid} deletes the client only while it is linked to that identity, in one conditional DELETE ... WHERE id = ? AND identity_id = ?. A client linked to another identity, or to none, is 404. An identity outside the tenant is 404. An approval-channel client keeps the trusted-context rule of DeleteClient (403 otherwise).

Unchanged on purpose:

  • One client per identity: bindAgent still requires the presenting client to be linked to the bound identity.
  • At most one enabled binding per issuer and subject key.
  • Deactivating an identity keeps its clients, because deactivation can be undone. The new delete works on a deactivated identity, so its client id can still be freed.

docs/external-issuers.md gets a "Moving an IdP app to another identity" section, and the README route table lists both routes.

Alignment with #450

#450 scopes the /oauth/clients routes to the caller's tenant. Both PRs use one rule: a client linked to an identity is reachable only through an identity in the caller's tenant.

Tests

  • TestIdentityOAuthClients (8 cases): lists only the identity's own clients; an empty list is []; delete frees the client_id for another identity; another identity's client and an unlinked client are refused and stay; another tenant gets 404 for list and delete; a deactivated identity's client can be listed and deleted; an approval-channel client is deleted only from a trusted context.
  • TestIdentityOAuthClients_MoveIdPAppToAnotherAgent: bind an app to A with oauth_client, remove the binding, binding B is 409 client_conflict, delete A's client through the new route, bind B with oauth_client (created), then the ID-token exchange with B's key mints a token whose actor is B, and A's key is refused (401).
  • With the route registration removed, 6 of the 8 cases fail. The two refusal cases pass either way, because a missing route also answers 404.
  • make test and make test-integration pass locally (integration: 1479 passed, 0 failed).

An IdP app bound to one identity could not be bound to another. The
binding's oauth_client is created linked to the identity, client_id is
unique, and deleting the binding keeps the client, so a second binding
with oauth_client is 409 client_conflict. The only delete is the
operator route DELETE /oauth/clients/{id}, which has no tenant scope
and so cannot be offered to a tenant admin.

Add two routes on the admin API that reach a client only through an
identity resolved in the caller's tenant:

- GET /identities/{id}/oauth-clients lists the identity's clients.
- DELETE /identities/{id}/oauth-clients/{client_uuid} deletes one only
  while it is linked to that identity (a single conditional DELETE), and
  is 404 for a client linked to another identity or to none. An
  approval-channel client keeps its trusted-context rule.

Deactivating an identity still keeps its clients, because deactivation
can be undone; the delete route works on a deactivated identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KunalJavelin
KunalJavelin merged commit bea206f into main Oct 22, 2026
11 checks passed
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.

2 participants