Repository navigation
Surface failed updates from the Identity API /manage/2fa endpoint - #69966
GrantTotinov wants to merge 1 commit into
Conversation
Check the IdentityResult from SetTwoFactorEnabledAsync and ResetAuthenticatorKeyAsync, and treat a null result from GenerateNewTwoFactorRecoveryCodesAsync as a failure, so the endpoint returns a validation problem instead of HTTP 200 with settings that were not persisted. Fixes dotnet#69941
|
Thanks for your PR, @GrantTotinov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
There was a problem hiding this comment.
🟡 Changes recommended
The failure-path test stops before the authenticator-key reset, leaving unverified that a reset failure returns HTTP 400 while preserving the original key and the successfully persisted disabled state.
1 open issue
Review effort: Balanced
| await AssertValidationProblemAsync(await client.PostAsJsonAsync("/identity/manage/2fa", new { ResetSharedKey = true }), | ||
| "ConcurrencyFailure"); |
Youssef1313
left a comment
There was a problem hiding this comment.
LGTM
@halter73 if you want to do a second review pass.

Surface failed updates from the Identity API /manage/2fa endpoint
Description
The
/manage/2fahandler registered byMapIdentityApiignored theIdentityResultreturned bySetTwoFactorEnabledAsyncandResetAuthenticatorKeyAsync, and treated anullresult fromGenerateNewTwoFactorRecoveryCodesAsyncas "no new codes". When the user update failed (for example an EF Core optimistic concurrency conflict caused by a concurrent update to the same user), the tracked user entity still held the modified values, so the endpoint returned HTTP 200 with a shared key, 2FA state or recovery codes that were never persisted.Changes in
IdentityApiEndpointRouteBuilderExtensions:SetTwoFactorEnabledAsyncandResetAuthenticatorKeyAsynccall is checked, including the reset that initializes a missing authenticator key. A failure is returned as a validation problem built from theIdentityResult(e.g.ConcurrencyFailure), the same way the other endpoints in this file already handle failed results.nullresult fromGenerateNewTwoFactorRecoveryCodesAsyncreturns aRecoveryCodeGenerationFailedvalidation problem instead of HTTP 200 withrecoveryCodes: null.A successful response is now only built after every update in the request has been persisted. The response shape for successful requests is unchanged, and there are no public API changes.
Behavior change to call out: a request that previously got HTTP 200 while its update silently failed now gets HTTP 400. If the request changes more than one setting (for example
ResetSharedKey, which disables 2FA and then resets the key), the steps that succeeded before the failure stay saved, the same as before this change. The client is now told that the request failed and can retry it.Tests
Added
TwoFactorReturnsValidationProblemWhenUserUpdateFailstoMapIdentityApiTests. It uses aUserManagerwhose user updates can be made to fail withConcurrencyFailure, and verifies that:ResetSharedKey,ResetRecoveryCodesandEnableeach return a 400 validation problem while updates fail, andThe test fails without the fix (the first request returns 200). All
Identity.FunctionalTestspass locally.Fixes #69941