Skip to content

Fix Native Auth V2 error classification - #8961

Merged
Yongdi Wang (yongdiw) merged 11 commits into
devfrom
yongdi/native-auth-v2-error-contract
Nov 6, 2026
Merged

Yongdi Wang (yongdiw) merged 11 commits into
devfrom
yongdi/native-auth-v2-error-contract

Conversation

@yongdiw

@yongdiw Yongdi Wang (yongdiw) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Correct the public Native Auth V2 error classifiers without changing V1 behavior or adding new flow states.

  • Classify missing accounts using invalidRequest plus userNotFound, without the message-only AADSTS50034 fallback.
  • Include incorrect sign-in credentials and all six supported reset-password policy subcodes in isInvalidPassword(), and use named constants for password-policy codes.
  • Add isPasswordResetNotEnabled() for invalidRequest plus passwordResetNotEnabledForUser, distinct from invalid-password failures.
  • Remove the obsolete V2 isUserAlreadyExists() helper while preserving required/invalid profile-attribute diagnostics.

Use structured user-not-found errors, expand invalid-password classification, add reset-disabled detection, and remove the obsolete existing-account helper while preserving attribute diagnostics and V1 behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 98356c16-fd1b-49ee-a94d-78da2f637100

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change still lacks the required PR link in its changelog entry and documentation explaining the exported V2 error-contract changes and caller migration guidance.

2 open issues
What changed in this PR

This PR corrects Native Auth V2 error classification in MSAL Browser without changing V1 behavior or introducing new flow states.

Changes:

  • Uses structured codes for missing-account errors and expands invalid-password classification to include incorrect credentials and six password-policy subcodes.
  • Adds reset-disabled detection and removes the obsolete existing-account helper while preserving attribute diagnostics.
  • Updates unit and integration coverage and adds a patch changefile.
File Description
lib/​msal-browser/​test/​custom_auth/​sign_up/​auth_flow/​v2/​state/​AttributesRequiredStateV2.spec.ts Verifies required-attribute diagnostics remain available.
lib/​msal-browser/​test/​custom_auth/​integration_tests/​SignUpV2.spec.ts Checks preservation of sign-up validation details.
lib/​msal-browser/​test/​custom_auth/​integration_tests/​SignInV2.spec.ts Expects incorrect credentials to classify as invalid passwords.
lib/​msal-browser/​test/​custom_auth/​integration_tests/​ResetPasswordV2.spec.ts Covers reset-disabled errors and six password-policy subcodes.
lib/​msal-browser/​test/​custom_auth/​core/​auth_flow/​v2/​state/​CodeRequiredStateV2.spec.ts Verifies unclassified sign-up errors retain their diagnostics.
lib/​msal-browser/​test/​custom_auth/​core/​auth_flow/​v2/​error/​AuthFlowErrorV2.spec.ts Expands classifier coverage and negative cases.
lib/​msal-browser/​test/​custom_auth/​core/​auth_flow/​v2/​CustomAuthResultV2.spec.ts Removes the obsolete helper assertion.
lib/​msal-browser/​src/​custom_auth/​core/​auth_flow/​v2/​error/​AuthFlowErrorV2.ts Corrects classifiers and adds reset-disabled detection.
lib/​msal-browser/​src/​custom_auth/​core/​auth_flow/​v2/​error/​AuthFlowErrorSubcodesV2.ts Adds named password-related subcode constants.
change/​@azure-msal-browser-native-auth-v2-error-contract.json Records the fixes as a patch release entry.

Review effort: Balanced

Yongdi Wang (yongdiw) and others added 3 commits November 4, 2026 11:47
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c9919841-191b-4570-a62e-cccb22f641b4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c9919841-191b-4570-a62e-cccb22f641b4
Retain exhaustive policy-code coverage in the classifier unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c9919841-191b-4570-a62e-cccb22f641b4

return (
detail.code === "passwordPolicyViolation" &&
detail.code === PASSWORD_POLICY_VIOLATION &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we align this password-attribute classification with iOS as well?

Issue: iOS requires outer code invalidRequest and inner code attributeValidationError, then treats any validation detail targeting the exact attribute password as an invalid-password error, regardless of the detail code. This helper instead requires passwordPolicyViolation, does not check the outer/inner codes, and matches the attribute case-insensitively.

Impact: a password validation detail with invalidValue, an unknown code, or no detail code returns isInvalidPassword == true on iOS but false here. Conversely, a passwordPolicyViolation detail under an unrelated outer/inner error can return true here when iOS would leave it unclassified.

Recommendation: require invalidRequest + attributeValidationError, then check whether any detail’s attributeIds contains the exact string password, without requiring a particular detail code. Add coverage for missing/unknown detail codes and nonmatching outer/inner codes. This logic predates this PR, but it remains a parity gap in the classifier being updated.

iOS implementation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So it's basically if:

  • serverError.innerErrorCode is any of "passwordTooWeak", "passwordTooShort", "passwordTooLong", "passwordIsInvalid", "passwordRecentlyUsed", "passwordBanned"
    or
  • serverError.innerErrorCode is attributeValidationError and attributeIds contains password

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.

Updated in e6dd0c356. isInvalidPassword() now covers:

  • invalidGrant + invalidUserNameOrPassword.
  • invalidRequest + the existing password-policy subcodes: passwordTooWeak, passwordTooShort, passwordTooLong, passwordIsInvalid, passwordRecentlyUsed, and passwordBanned.
  • invalidRequest + attributeValidationError, where a detail contains the exact attribute ID "password", regardless of its detail code.

Only the passwordPolicyViolation detail-code prerequisite was removed, not the direct password-policy subcodes. Raw error and attribute diagnostics are preserved.

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.

Aligned with iOS: require invalidRequest + attributeValidationError, then match the exact attribute ID "password" without requiring a particular detail code. Password validation takes priority over other attribute details; coverage includes mixed details and nonmatching error codes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

there is a difference there around password check

Yongdi Wang (yongdiw) and others added 3 commits November 5, 2026 11:07
Add contextual MFA/JIT challenge and general attribute classifiers,
mark existing local username validation failures, and align browser
and password predicates with the V2 error contract.

Remove obsolete credentials and missing-attribute helpers while
preserving classified errors, scenarios, and diagnostic strings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 98356c16-fd1b-49ee-a94d-78da2f637100
Retain the updated error classifiers alongside the experimental API
warnings and explicit password-required-state sign-in behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 98356c16-fd1b-49ee-a94d-78da2f637100
*/
isMissingRequiredAttributes(): boolean {
return this.requiredAttributes.length > 0;
toString(): string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

developer can read from here attributes failing yes?

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.

Yes—invalidAttributes exposes IDs marked attributeValidationFailed, and requiredAttributes exposes IDs marked attributeRequired. The original API error retains the full validation details.

Yongdi Wang (yongdiw) and others added 2 commits November 5, 2026 17:20
Resolve sign-up integration conflicts and align merged tests with the V2 error contract. Keep existing local error-boundary edits outside this merge commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c9919841-191b-4570-a62e-cccb22f641b4
Preserve raw errors until existing controller/state result boundaries. Identify local username failures with readonly argName and distinguish MFA/registration verification using explicit error contexts, keeping default for ordinary operations. Cover propagation, logging and classification with regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 98356c16-fd1b-49ee-a94d-78da2f637100
Resolve reset-password MFA test conflicts while retaining original-error propagation regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 98356c16-fd1b-49ee-a94d-78da2f637100

/**
* Checks whether the flow must continue in the browser.
* Checks if the error requires the flow to continue in the browser. The

@spetrescu84 Silviu Petrescu (spetrescu84) Nov 6, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: previous comment was ok, this explain how code does what it does

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.

Simplified to describe the public behavior rather than the implementation: “Checks whether the flow must continue in the browser.”

/**
* Checks whether the service rejected the username parameter.
* @returns True when the username is invalid, otherwise false.
* Checks whether the supplied username failed local validation. Local username

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: comment should be Checks whether the supplied username failed local validation. then @returns

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.

Updated to the requested wording: “Checks whether the supplied username failed local validation.” Kept the @returns description.

/**
* Checks whether the service rejected a one-time code.
* @returns True when the one-time code is invalid, otherwise false.
* Checks whether the service rejected an ordinary one-time code. MFA and

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: previous comment was ok, this explain how code does what it does

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.

Simplified to “Checks whether the service rejected a one-time code,” followed by @returns.

/**
* Checks whether a new password violates password policy.
* @returns True when the new password is invalid, otherwise false.
* Checks whether the service rejected an MFA or registration challenge.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: comment should be Checks whether the service rejected an MFA or registration challenge. then @returns...

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.

Updated to “Checks whether the service rejected an MFA or registration challenge,” followed by @returns.

/**
* Checks whether the service requires attributes omitted from the request.
* @returns True when required attributes are missing, otherwise false.
* Checks whether the service rejected a supplied password. It recognizes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: comment should be Checks whether the service rejected a supplied password.

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.

Updated to the requested wording: “Checks whether the service rejected a supplied password.”


/**
* Creates a failed result from the supplied error.
* Optional error context identifies MFA verification or authentication-method registration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not sure it matters but should be ok

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.

Thanks—left this unchanged. The optional context distinguishes MFA/registration verification errors from ordinary code errors.

isUserAlreadyExists(): boolean {
return this.getAttributeValidationDetails().some(
(detail) => detail.code === "userAlreadyExists"
isInvalidAttributeError(): boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this should be isInvalidAttributes

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.

Renamed to isInvalidAttributes() and updated the test references. It now follows iOS’s password-first classification, so password and attribute detectors cannot both return true.

Rename the attribute detector, prioritize password-targeted validation, ignore empty attribute IDs, and simplify public error descriptions. Update unit and integration coverage while preserving raw validation diagnostics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8bc6a3d6-1f43-41f3-b067-69313f470741
@yongdiw
Yongdi Wang (yongdiw) merged commit 9b79aa4 into dev Nov 6, 2026
84 checks passed
@yongdiw
Yongdi Wang (yongdiw) deleted the yongdi/native-auth-v2-error-contract branch November 6, 2026 12:30
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