Skip to content

Unify Native Auth V2 authentication method selection - #8899

Merged
Yongdi Wang (yongdiw) merged 16 commits into
yongdi/native-auth-v2-fixesfrom
yongdi/native-auth-v2-method-selection
Oct 19, 2026
Merged

Yongdi Wang (yongdiw) merged 16 commits into
yongdi/native-auth-v2-fixesfrom
yongdi/native-auth-v2-method-selection

Conversation

@yongdiw

@yongdiw Yongdi Wang (yongdiw) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Unifies Native Auth V2 authentication-method selection and makes challenge transitions result-driven.

  • Replaces separate primary and MFA selection surfaces with AuthMethodSelectionRequiredStateV2.selectAuthMethod() and one public request-challenge result.
  • Maps the trusted returned challenge to the correct state: selected single-factor password to PasswordRequiredStateV2, selected email/SMS code to CodeRequiredStateV2, and selected MFA code to MFAVerificationRequiredStateV2; unsupported combinations fail explicitly.
  • Preserves the sign-in transition handler through selected primary password and code states so verification can complete sign-in or advance to MFA.
  • Centralizes sign-in state transitions, adds the shared first-factor resend result, and removes redundant MFA-specific selection state and result exports.
  • Reorganizes the V2 sign-in/reset integration suites and adds focused state and transition regression coverage.

if (result.type === FLOW_MFA_REQUIRED_V2) {
return new CustomAuthResultV2(
new MFARequiredStateV2({
new AuthMethodSelectionRequiredStateV2({

Choose a reason for hiding this comment

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

Could we also expose this selection state when primary sign-in returns multiple supported methods? MSAL iOS dev lets the app choose in that case, but JS still calls selectSignInMethod() and automatically picks email or password before reaching this controller. As a result, the unified state is available for MFA here, but not for choosing the primary sign-in method. This behavior predates this PR; flagging it as a remaining iOS parity gap rather than a regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ea8ae5096. Primary sign-in now returns AuthMethodSelectionRequiredStateV2 whenever the server provides multiple supported Email, SMS, or Password methods, regardless of whether an initial password was supplied. A sole supported method is still selected automatically, and the initial password is not retained through multi-method selection. Unit and integration coverage was added for zero, one, and multiple supported methods.


const expectedChallenge =
authenticationFactor === AuthenticationFactorV2.SINGLE_FACTOR
? "an email or SMS code challenge for single-factor authentication"

Choose a reason for hiding this comment

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

Could we support a password-required result for primary sign-in selection, while keeping password reset restricted to email/SMS codes? MSAL iOS dev routes primary sign-in method selection to either code-required or password-required. This shared state still rejects password challenges, and RequestChallengeResultStateV2 cannot represent a password-required state. This restriction predates this PR and is not a failure in the currently wired reset/MFA paths; it is a remaining gap if this API is intended to cover primary sign-in selection too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ea8ae5096. Selecting Password during primary single-factor sign-in now returns PasswordRequiredStateV2 through the sign-in transition handler. Password challenges remain unsupported for password reset and MFA. RequestChallengeResultV2 now represents the Password-required state, while CodeRequiredStateV2.resendCode() uses a dedicated ResendCodeResultV2 so its public return type remains code-only. Unit and integration coverage was added for both the Password and code-method paths.

Yongdi Wang (yongdiw) and others added 5 commits October 14, 2026 14:10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Stop carrying entry scopes and claims through continuation state or the authorization-code token request. Use the token response scope for cache processing and update V2 flow coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Return method selection for multiple supported first-factor methods, map selected Password challenges to PasswordRequiredStateV2, and keep resend-code result typing narrow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
@yongdiw
Yongdi Wang (yongdiw) force-pushed the yongdi/native-auth-v2-method-selection branch from 2d419bf to ea8ae50 Compare October 14, 2026 16:17
Yongdi Wang (yongdiw) and others added 5 commits October 15, 2026 19:33
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Yongdi Wang (yongdiw) and others added 2 commits October 19, 2026 14:39
## Summary

Unifies Native Auth V2 failures behind `AuthFlowErrorV2` while
preserving the distinct service error contracts needed for
classification and diagnostics.

- Replaces flow-specific V2 error types across start, submit, resend,
method-selection, and continuation results with one public error model
and stable classifiers for invalid input, credentials, codes, passwords,
usernames, missing or existing users, missing attributes, and browser
fallback.
- Normalizes both flat OAuth and nested HAL error payloads while keeping
OAuth `subError` separate from HAL `innerErrorCode`;
`web_redirect_required` remains an OAuth suberror used by
`isBrowserRequired()`.
- Exposes ordered, deduplicated `requiredAttributes` and
`invalidAttributes` from attribute-validation details and safely ignores
malformed external values.
- Correctly distinguishes invalid credentials from password-policy
failures and supports user-not-found, invalid-code, weak-password,
existing-user, and password-targeted validation responses.
- Preserves raw descriptions, error codes, correlation data, and flow
scenario for diagnostics, documents browser fallback, and expands unit
and integration coverage for the unified model and normalized API
payloads.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
@yongdiw
Yongdi Wang (yongdiw) requested a review from a team as a code owner October 19, 2026 13:42
## Summary

Unifies Native Auth V2 failures behind `AuthFlowErrorV2` while
preserving the distinct service error contracts needed for
classification and diagnostics.

- Replaces flow-specific V2 error types across start, submit, resend,
method-selection, and continuation results with one public error model
and stable classifiers for invalid input, credentials, codes, passwords,
usernames, missing or existing users, missing attributes, and browser
fallback.
- Normalizes both flat OAuth and nested HAL error payloads while keeping
OAuth `subError` separate from HAL `innerErrorCode`;
`web_redirect_required` remains an OAuth suberror used by
`isBrowserRequired()`.
- Exposes ordered, deduplicated `requiredAttributes` and
`invalidAttributes` from attribute-validation details and safely ignores
malformed external values.
- Correctly distinguishes invalid credentials from password-policy
failures and supports user-not-found, invalid-code, weak-password,
existing-user, and password-targeted validation responses.
- Preserves raw descriptions, error codes, correlation data, and flow
scenario for diagnostics, documents browser fallback, and expands unit
and integration coverage for the unified model and normalized API
payloads.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
@yongdiw
Yongdi Wang (yongdiw) merged commit c8b7661 into yongdi/native-auth-v2-fixes Oct 19, 2026
@yongdiw
Yongdi Wang (yongdiw) deleted the yongdi/native-auth-v2-method-selection branch October 19, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants