Honor two-factor authentication on external-login sign-in - #69075
Open
GrantTotinov wants to merge 2 commits into
Open
Honor two-factor authentication on external-login sign-in#69075GrantTotinov wants to merge 2 commits into
GrantTotinov wants to merge 2 commits into
Conversation
GrantTotinov
requested review from
Youssef1313,
cincuranet,
davpetr and
rokonec
as code owners
September 6, 2026 01:18
Contributor
|
Thanks for your PR, @GrantTotinov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The UI change correctly enforces the existing 2FA policy for external logins and is covered by functional tests that exercise both V4 and V5 UI variants.
Pull request overview
This pull request updates the scaffolded ASP.NET Core Identity UI external-login callback flow to honor two-factor authentication (2FA) for accounts that have 2FA enabled, bringing it in line with the password sign-in behavior.
Changes:
- Update V4/V5
ExternalLogincallback to callExternalLoginSignInAsync(..., bypassTwoFactor: false)and handleRequiresTwoFactorby redirecting toLoginWith2fa. - Add functional test coverage to ensure external-login sign-in is challenged for 2FA-enabled accounts.
- Extend functional-test page objects/user stories to drive the external-login + 2FA flow.
File summaries
| File | Description |
|---|---|
| src/Identity/UI/src/Areas/Identity/Pages/V5/Account/ExternalLogin.cshtml.cs | Stops bypassing 2FA during external-login sign-in and redirects to LoginWith2fa when required. |
| src/Identity/UI/src/Areas/Identity/Pages/V4/Account/ExternalLogin.cshtml.cs | Same external-login 2FA enforcement behavior for the V4 (Bootstrap 4) UI. |
| src/Identity/test/Identity.FunctionalTests/UserStories.cs | Adds a user-story helper to perform external-login + 2FA sign-in. |
| src/Identity/test/Identity.FunctionalTests/Pages/Contoso/Login.cs | Adds a Contoso login helper that asserts the external-login flow redirects to LoginWith2fa. |
| src/Identity/test/Identity.FunctionalTests/LoginTests.cs | Adds a functional test verifying external login is challenged for 2FA when enabled. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
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.
Honor two-factor authentication on external-login sign-in
Description
The default scaffolded Identity UI completed an external-provider (OAuth/OIDC) sign-in with two-factor authentication bypassed unconditionally, even for accounts that had 2FA enabled. This diverged from the password sign-in path, which already honors 2FA.
In
ExternalLogin.cshtml.cs(both V4 and V5),ExternalLoginSignInAsyncis now called withbypassTwoFactor: falseinstead oftrue, and aresult.RequiresTwoFactorbranch was added that redirects to./LoginWith2fa, mirroring the existing pattern inLogin.cshtml.cs. No changes were needed inSignInManager:ExternalLoginSignInAsyncalready resolves the user internally and forwards the externalloginProviderthrough the two-factor round-trip, so the completed sign-in after the second factor still preserves the external login and the external sign-in cookie is cleaned up as part of the existing two-factor completion flow.Scope notes:
RedirectToPage("./LoginWith2fa", ...)call in the external-login callback intentionally omitsRememberMe, since external sign-in has no "remember me" concept on the login form; it defaults tofalse.ExternalLogin.cshtml.cswill not pick up this change automatically.ExternalLoginIsChallengedForTwoFactorWhenAccountHasTwoFactorEnabled, locks down that an external-login account with 2FA enabled is routed throughLoginWith2fabefore sign-in completes, and that an account without 2FA continues to sign in unchanged (covered by the existingCanLoginWithASocialLoginProvidertest).Fixes #68497