feat: allow deleting the code credential via the admin API - #4592
Draft
walter-hostaway wants to merge 1 commit into
Draft
feat: allow deleting the code credential via the admin API#4592walter-hostaway wants to merge 1 commit into
walter-hostaway wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5 tasks
The admin endpoint DELETE /admin/identities/{id}/credentials/{type}
handled every credential type except code, which fell through to the
default branch and returned 400 "Credentials type code cannot be
deleted." This made it impossible to detach an email/phone code
credential from an identity in place.
Handle CredentialsTypeCodeAuth in the delete switch. Because code is a
first factor only when passwordless login with code is enabled, apply
the last-first-factor guard only in that case; as a pure MFA second
factor it is freely removable like TOTP or lookup secrets.
Resolves ory#4462
walter-hostaway
force-pushed
the
feat/delete-code-credential
branch
from
August 13, 2026 13:11
7f80a83 to
8408528
Compare
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.
The admin endpoint
DELETE /admin/identities/{id}/credentials/{type}handlesevery credential type except
code:totp,lookup_secret,webauthn,oidc,saml,password, anddeviceauthnare all removable, butcodefalls through to the
defaultbranch of the switch indeleteIdentityCredentialsand returns400 "Credentials type code cannot be deleted."Combined with the fact that removing the sourcing trait does not dropthe derived
codecredential, there is no way to detach an email/phonecodecredential from an identity in place (see #4462).
This change handles
CredentialsTypeCodeAuthin the delete switch. Becausecodeis a first factor only when passwordless code login is enabled, theexisting "last first factor" guard is applied only when
SelfServiceCodeStrategy.PasswordlessEnabledis true; as a pure MFA secondfactor
codeis freely removable, matchingtotp/lookup_secret. Routing itthrough the
password/oidcguard unconditionally would wrongly block removalin MFA-only deployments, where
CountActiveFirstFactorCredentialsreturns 1.Related issue(s)
Resolves #4462
Checklist
identity/handler_test.go,TestHandlerpassing).Further Comments
Design note: the naive fix (routing
codethrough the existing password/oidcguarded branch) is incorrect for MFA-only setups, where the guard would block
removing a purely-second-factor
code. Gating the guard onPasswordlessEnabledavoids that while still protecting passwordless-code-only identities from losing
their last first factor. Happy to adjust the guard semantics to maintainer
preference.
AI assistance: the analysis, patch, and tests were prepared with Claude Code;
the change is human-reviewed, built (
go build ./...,go vet ./identity/), andtested (
go test ./identity/ -run TestHandler).