Repository navigation
feat: list and delete an identity's OAuth clients, scoped to the tenant - #452
Merged
Merged
Conversation
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>
rsharath
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An IdP app bound to one identity cannot be bound to another identity.
POST /external-issuers/{id}/bindingswithoauth_clientcreates aprivate_key_jwtclient linked to the identity (ensurePresentingClient).client_idis unique, andDELETE /external-issuers/{id}/bindings/{binding_id}keeps the client. So binding the same app to a second identity withoauth_clientis409 client_conflict.oauth_clients.identity_idis not cleared and the client keeps its id.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, thenGetIdentity(id, account, project)):GET /identities/{id}/oauth-clientslists the clients whoseidentity_idis that identity.DELETE /identities/{id}/oauth-clients/{client_uuid}deletes the client only while it is linked to that identity, in one conditionalDELETE ... 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 ofDeleteClient(403 otherwise).Unchanged on purpose:
bindAgentstill requires the presenting client to be linked to the bound identity.docs/external-issuers.mdgets a "Moving an IdP app to another identity" section, and the README route table lists both routes.Alignment with #450
#450 scopes the
/oauth/clientsroutes 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.DELETEanswers 404 when the client is not linked to the identity in the path, where fix: scope OAuth client admin routes to the caller's tenant #450's globalDELETE /oauth/clients/{id}keeps its legacy no-op 200 for a hidden client. The reason: the global route has existing callers that expect 200, so fix: scope OAuth client admin routes to the caller's tenant #450 keeps it. The new route has no such callers, and its caller must know whether aclient_idwas freed. 404 does not let tenants probe each other: it is the same answer for a missing client, a client linked to any other identity (in any tenant), and an unlinked client.tenantScopedClient,GetIdentitiesByIDs) where they fit, so there is one lookup path. The conditionalDELETE ... WHERE id = ? AND identity_id = ?stays, because it makes the "still linked to this identity" check atomic.docs/external-issuers.mdhere will say so. Deactivation still keeps the clients.ON DELETE SET NULLalready left unlinked are out of scope here. These routes cannot reach them, because they are linked to no identity. Follow-up: Decide what to do with OAuth clients that the old ON DELETE SET NULL left unlinked #453.Tests
TestIdentityOAuthClients(8 cases): lists only the identity's own clients; an empty list is[]; delete frees theclient_idfor 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 withoauth_client, remove the binding, binding B is409 client_conflict, delete A's client through the new route, bind B withoauth_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).make testandmake test-integrationpass locally (integration: 1479 passed, 0 failed).