Skip to content

Support shared mode lookup by id for two-factor authentication#25304

Merged
ismcagdas merged 13 commits intorel-10.2from
maliming/fix-shared-mode-two-factor-login-10604
Apr 24, 2026
Merged

Support shared mode lookup by id for two-factor authentication#25304
ismcagdas merged 13 commits intorel-10.2from
maliming/fix-shared-mode-two-factor-login-10604

Conversation

@maliming
Copy link
Copy Markdown
Member

@maliming maliming commented Apr 21, 2026

Fix shared-mode 2FA: AbpSignInManager now resolves the user via the new FindSharedUserByIdAsync and switches CurrentTenant + IdentityOptions before calling base sign-in methods, so tenant users can complete 2FA from host context. Covers TwoFactorSignInAsync, TwoFactorRecoveryCodeSignInAsync, PasswordSignInAsync and ExternalLoginSignInAsync.

Adds AspNetCore integration tests for each path, revert-verified. Isolated mode unchanged.

- Add IdentityUserManager.FindSharedUserByIdAsync to resolve a user by id across tenants in shared user sharing strategy
- Override AbpSignInManager.GetTwoFactorAuthenticationUserAsync to use it so the 2FA mid-flow can still find a tenant-scoped user when CurrentTenant is host
- Cover the new method with unit tests
Copilot AI review requested due to automatic review settings April 21, 2026 13:09
@maliming maliming added this to the 10.2-patch-final milestone Apr 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a 2FA mid-flow failure in Shared tenant user sharing strategy by ensuring user lookup by ID can bypass the default IMultiTenant filter when CurrentTenant is null, aligning the 2FA user resolution with existing FindSharedUserBy* patterns.

Changes:

  • Added IdentityUserManager.FindSharedUserByIdAsync(string userId) for Shared-mode cross-tenant user lookup by ID.
  • Overrode AbpSignInManager.GetTwoFactorAuthenticationUserAsync() to use FindSharedUserByIdAsync instead of the default FindByIdAsync path.
  • Added domain tests covering Shared-mode host/tenant context lookups for the new FindSharedUserByIdAsync method.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs Adds Shared-mode-safe user lookup by ID (disables IMultiTenant filter and re-resolves under the user’s tenant).
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs Routes 2FA user resolution through the new Shared-mode lookup to prevent null results when CurrentTenant is null.
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs Adds unit tests validating the new Shared-mode ID lookup behavior across host/tenant contexts.

…d mode

Exercises the full cookie round-trip: writes a TwoFactorUserId cookie carrying a tenant user id, then verifies that AbpSignInManager.GetTwoFactorAuthenticationUserAsync returns the tenant user when CurrentTenant is null.
Guards against regressing the data-access contract behind the 2FA redirect bug: login must find a tenant user by user name from a host context, and the 2FA mid-flow must then resolve the same tenant user by id from the same host context.
- Override IdentityUserManager.FindByIdAsync to fall back to a cross-tenant lookup in shared user sharing strategy so any caller that hits FindByIdAsync from a non-matching tenant context (including base SignInManager internals for TwoFactorSignInAsync and TwoFactorRecoveryCodeSignInAsync) can still resolve a tenant user by id
- Drop the now-redundant AbpSignInManager.GetTwoFactorAuthenticationUserAsync override; the base implementation works automatically through the new FindByIdAsync behavior
- Cover the new FindByIdAsync behavior with unit tests
Switching CurrentTenant to user.TenantId in PasswordSignInAsync without refreshing IdentityOptions meant that lockout, password policy and other tenant-scoped options used host values during the base sign-in call. Call IdentityOptions.SetAsync inside the tenant switch so downstream checks use the user's tenant configuration.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

maliming and others added 3 commits April 22, 2026 17:03
…Abp/Identity/AspNetCore/Isolated_TwoFactor_Tests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Abp/Identity/AspNetCore/Shared_SignIn_Tests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Abp/Identity/AspNetCore/GetTwoFactorAuthenticationUser_Tests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@maliming maliming requested a review from ismcagdas April 23, 2026 06:35
@ismcagdas ismcagdas merged commit e754b20 into rel-10.2 Apr 24, 2026
3 checks passed
@ismcagdas ismcagdas deleted the maliming/fix-shared-mode-two-factor-login-10604 branch April 24, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants