Improve sign-in process (#12790) - #12791
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository 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:
WalkthroughThe identity flow now validates sign-in inputs, handles missing OTP timestamps, uses automatic sign-in links for confirmations, centralizes two-factor lockout handling, and applies stricter elevated-session refresh validation. ChangesIdentity authentication
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant IdentityController
participant PhoneProvider
participant AuthenticatorProvider
IdentityController->>PhoneProvider: Validate phone token
PhoneProvider-->>IdentityController: Return validation result
IdentityController->>AuthenticatorProvider: Validate authenticator token
AuthenticatorProvider-->>IdentityController: Return validation result
IdentityController->>IdentityController: Record failure or return lockout
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.cs (1)
145-155: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winGood consolidation; reuse the new helper in the confirmation flows too.
Centralizing lockout handling into
UserLockedOutExceptionandFailedTwoFactorSignInis a correct improvement. Two follow-ups worth considering, both enabled by this change:
IdentityController.EmailConfirmation.cs(lines 36-40) andIdentityController.PhoneConfirmation.cs(lines 38-42) still build the lockout message inline using(TimeProvider.GetUtcNow() - user.LockoutEnd!).Value.Humanize(...). That expression is the negative oftryAgainIn, while theirWithExtensionData("TryAgainIn", tryAgainIn)uses the positive value.UserLockedOutExceptioncomputes both consistently from the positivetryAgainIn. Since both files are partial classes ofIdentityController, they can call the shared private helper directly and drop the duplicated, inconsistent logic.OtpSignIninSignInManagerExtensions.cs(lines 65-69) still returnsSignInResult.FailedafterAccessFailedAsyncwithout checkingIsLockedOutAsync, unlike the newFailedTwoFactorSignIn. If a failed OTP attempt is the one that crosses the lockout threshold, the caller reports a generic invalid-credentials error instead of the lockout message until the next request.Neither point is required by this PR, but both are low-effort follow-ups that remove duplication and fix a real display bug.
Also applies to: 172-217
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.cs` around lines 145 - 155, Update the email and phone confirmation flows in IdentityController to call the shared UserLockedOutException helper instead of constructing lockout messages and tryAgainIn values inline. Update OtpSignIn in SignInManagerExtensions to check IsLockedOutAsync after AccessFailedAsync and return the same FailedTwoFactorSignIn lockout result when the failed OTP attempt triggers lockout; preserve the existing failed-sign-in result otherwise.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.cs`:
- Around line 316-321: Update the refresh-token reuse logic in
IdentityController to reject stale tokens based on the presented iat claim
relative to the session’s allowed rotation state, rather than requiring both the
issued-at gap and 30 seconds since lastRotatedOn. Remove the post-rotation
time-window dependency while preserving acceptance of the current legitimate
refresh token.
---
Nitpick comments:
In
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.cs`:
- Around line 145-155: Update the email and phone confirmation flows in
IdentityController to call the shared UserLockedOutException helper instead of
constructing lockout messages and tryAgainIn values inline. Update OtpSignIn in
SignInManagerExtensions to check IsLockedOutAsync after AccessFailedAsync and
return the same FailedTwoFactorSignIn lockout result when the failed OTP attempt
triggers lockout; preserve the existing failed-sign-in result otherwise.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 551b3944-2e97-45c6-a780-c0402001f4c9
📒 Files selected for processing (5)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/Extensions/SignInManagerExtensions.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/Extensions/UserManagerExtensions.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.EmailConfirmation.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.PhoneConfirmation.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Features/Identity/IdentityController.cs
closes #12790
Summary by CodeRabbit