Repository navigation
Fix Native Auth V2 error classification - #8961
Conversation
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
There was a problem hiding this comment.
🟡 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
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 && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
So it's basically if:
serverError.innerErrorCodeis any of"passwordTooWeak", "passwordTooShort", "passwordTooLong", "passwordIsInvalid", "passwordRecentlyUsed", "passwordBanned"
orserverError.innerErrorCodeisattributeValidationErrorand attributeIds containspassword
There was a problem hiding this comment.
Updated in e6dd0c356. isInvalidPassword() now covers:
invalidGrant+invalidUserNameOrPassword.invalidRequest+ the existing password-policy subcodes:passwordTooWeak,passwordTooShort,passwordTooLong,passwordIsInvalid,passwordRecentlyUsed, andpasswordBanned.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.
There was a problem hiding this comment.
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.
Silviu Petrescu (spetrescu84)
left a comment
There was a problem hiding this comment.
there is a difference there around password check
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 { |
There was a problem hiding this comment.
developer can read from here attributes failing yes?
There was a problem hiding this comment.
Yes—invalidAttributes exposes IDs marked attributeValidationFailed, and requiredAttributes exposes IDs marked attributeRequired. The original API error retains the full validation details.
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 |
There was a problem hiding this comment.
nit: previous comment was ok, this explain how code does what it does
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
nit: comment should be Checks whether the supplied username failed local validation. then @returns
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
nit: previous comment was ok, this explain how code does what it does
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
nit: comment should be Checks whether the service rejected an MFA or registration challenge. then @returns...
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
nit: comment should be Checks whether the service rejected a supplied password.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
not sure it matters but should be ok
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
this should be isInvalidAttributes
There was a problem hiding this comment.
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

Summary
Correct the public Native Auth V2 error classifiers without changing V1 behavior or adding new flow states.
invalidRequestplususerNotFound, without the message-only AADSTS50034 fallback.isInvalidPassword(), and use named constants for password-policy codes.isPasswordResetNotEnabled()forinvalidRequestpluspasswordResetNotEnabledForUser, distinct from invalid-password failures.isUserAlreadyExists()helper while preserving required/invalid profile-attribute diagnostics.