Repository navigation
Fix Native Auth V2 error classification #8961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
9e176c2
e81b83a
59e2e58
ff76577
f8afe3f
e6dd0c3
be198e0
235b9c6
e3750b2
8ea5b3c
6022369
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Correct Native Auth V2 browser, user-not-found, password, and local-username error classification, add general attribute and MFA/JIT challenge classifiers, and remove obsolete error helpers. [#8961](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8961)", | ||
| "packageName": "@azure/msal-browser", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,25 @@ import { CustomAuthApiError } from "../../../error/CustomAuthApiError.js"; | |
| import { InvalidArgumentError } from "../../../error/InvalidArgumentError.js"; | ||
| import { WEB_REDIRECT_REQUIRED } from "../../../network_client/custom_auth_api/v2/ErrorCodesV2.js"; | ||
| import { | ||
|
spetrescu84 marked this conversation as resolved.
Resolved
|
||
| ATTRIBUTE_VALIDATION_ERROR, | ||
| INVALID_ONE_TIME_CODE, | ||
| INVALID_USERNAME_OR_PASSWORD, | ||
| PASSWORD_BANNED, | ||
| PASSWORD_IS_INVALID, | ||
| PASSWORD_RECENTLY_USED, | ||
| PASSWORD_TOO_LONG, | ||
| PASSWORD_TOO_SHORT, | ||
| PASSWORD_TOO_WEAK, | ||
| USER_NOT_FOUND, | ||
| } from "./AuthFlowErrorSubcodesV2.js"; | ||
| import { CustomAuthFlowScenarioV2 } from "../CustomAuthFlowScenarioV2.js"; | ||
| import type { AttributeValidationDetailV2 } from "../../../network_client/custom_auth_api/v2/response/ErrorResponsesV2.js"; | ||
|
|
||
| export type AuthFlowErrorContextV2 = | ||
| | "default" | ||
| | "mfaVerification" | ||
| | "authMethodRegistration"; | ||
|
|
||
| /** | ||
| * Error returned by a native authentication V2 operation. | ||
| * @warning This API is experimental. It may be changed in the future without notice. Do not use in production applications. | ||
|
|
@@ -25,7 +36,8 @@ export class AuthFlowErrorV2 { | |
|
|
||
| constructor( | ||
| public errorData: CustomAuthError, | ||
| scenario: CustomAuthFlowScenarioV2 = CustomAuthFlowScenarioV2.Unknown | ||
| scenario: CustomAuthFlowScenarioV2 = CustomAuthFlowScenarioV2.Unknown, | ||
| private readonly errorContext: AuthFlowErrorContextV2 = "default" | ||
| ) { | ||
| this.scenario = scenario; | ||
| } | ||
|
|
@@ -57,11 +69,17 @@ export class AuthFlowErrorV2 { | |
| } | ||
|
|
||
| /** | ||
| * 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. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.” |
||
| * server surfaces this as `invalid_grant` with the `web_redirect_required` | ||
| * OAuth suberror, so a browser hand-off arrives as a `FailedStateV2` on which | ||
| * this detector returns true. | ||
| * @returns True if the browser is required, false otherwise. | ||
| */ | ||
| isBrowserRequired(): boolean { | ||
| return this.errorData.subError === WEB_REDIRECT_REQUIRED; | ||
| return ( | ||
| this.errorData.error === "invalid_grant" && | ||
| this.errorData.subError === WEB_REDIRECT_REQUIRED | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -73,11 +91,15 @@ export class AuthFlowErrorV2 { | |
| } | ||
|
|
||
| /** | ||
| * 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| * failures also satisfy `isInvalidInput()`, unlike server attribute errors. | ||
| * @returns True when local username validation failed. | ||
| */ | ||
| isInvalidUsername(): boolean { | ||
| return this.isUserInvalidError(); | ||
| return ( | ||
| this.errorData instanceof InvalidArgumentError && | ||
| this.errorData.argName === "inputs.username" | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -89,67 +111,57 @@ export class AuthFlowErrorV2 { | |
| } | ||
|
|
||
| /** | ||
| * Checks whether the service rejected the supplied sign-in credentials. This | ||
| * classifier does not identify new-password policy failures. | ||
| * @returns True when the username or password is incorrect. | ||
| */ | ||
| isInvalidCredentials(): boolean { | ||
| return this.isPasswordIncorrectError(); | ||
| } | ||
|
|
||
| /** | ||
| * 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. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| * registration verification failures are identified by `isInvalidChallenge()`. | ||
| * @returns True when the ordinary one-time code is invalid. | ||
| */ | ||
| isInvalidCode(): boolean { | ||
| return this.isInvalidCodeError(); | ||
| return this.errorContext === "default" && this.isInvalidCodeError(); | ||
| } | ||
|
|
||
| /** | ||
| * 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| * Use it to distinguish challenge verification from ordinary code verification. | ||
| * @returns True when the verification challenge is invalid. | ||
| */ | ||
| isInvalidPassword(): boolean { | ||
| isInvalidChallenge(): boolean { | ||
| return ( | ||
| this.isInvalidPasswordError() || | ||
| this.isPasswordPolicyViolationError() | ||
| (this.errorContext === "mfaVerification" || | ||
| this.errorContext === "authMethodRegistration") && | ||
| this.isInvalidCodeError() | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether an account already exists for the supplied identifier. | ||
| * @returns True if the account already exists, otherwise false. | ||
| * Checks whether the service reports an attribute-validation error. It applies | ||
| * to all collected attributes, independently of the validation details. | ||
| * @returns True when the service reports an attribute-validation error. | ||
| */ | ||
| isUserAlreadyExists(): boolean { | ||
| return this.getAttributeValidationDetails().some( | ||
| (detail) => detail.code === "userAlreadyExists" | ||
| isInvalidAttributeError(): boolean { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
| return ( | ||
| this.errorData.error === "invalidRequest" && | ||
| this.innerErrorCode === ATTRIBUTE_VALIDATION_ERROR | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.” |
||
| * incorrect sign-in credentials, password-policy failures, and | ||
| * password-targeted validation details. | ||
| * @returns True when the supplied password is invalid, otherwise false. | ||
| */ | ||
| isMissingRequiredAttributes(): boolean { | ||
| return this.requiredAttributes.length > 0; | ||
| } | ||
|
|
||
| private isUserNotFoundError(): boolean { | ||
| isInvalidPassword(): boolean { | ||
| return ( | ||
| this.errorData.error === "invalidRequest" && | ||
| (this.innerErrorCode === USER_NOT_FOUND || | ||
| this.errorData.errorDescription?.includes("AADSTS50034") === | ||
| true) | ||
| this.isPasswordIncorrectError() || | ||
| this.isInvalidPasswordError() || | ||
| this.isPasswordAttributeValidationError() | ||
| ); | ||
| } | ||
|
|
||
| private isUserInvalidError(): boolean { | ||
| private isUserNotFoundError(): boolean { | ||
| return ( | ||
| this.errorData.error === "invalidRequest" && | ||
| this.errorData.errorDescription?.includes("AADSTS90100") === true && | ||
| this.errorData.errorDescription | ||
| .toLowerCase() | ||
| .includes("username parameter") | ||
| this.innerErrorCode === USER_NOT_FOUND | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -161,24 +173,29 @@ export class AuthFlowErrorV2 { | |
| } | ||
|
|
||
| private isInvalidPasswordError(): boolean { | ||
| const innerErrorCode = this.innerErrorCode; | ||
|
|
||
| return ( | ||
| this.errorData.error === "invalidRequest" && | ||
| this.innerErrorCode === PASSWORD_TOO_WEAK | ||
| (innerErrorCode === PASSWORD_TOO_WEAK || | ||
| innerErrorCode === PASSWORD_TOO_SHORT || | ||
| innerErrorCode === PASSWORD_TOO_LONG || | ||
| innerErrorCode === PASSWORD_IS_INVALID || | ||
| innerErrorCode === PASSWORD_RECENTLY_USED || | ||
| innerErrorCode === PASSWORD_BANNED) | ||
| ); | ||
| } | ||
|
|
||
| private isPasswordPolicyViolationError(): boolean { | ||
| private isPasswordAttributeValidationError(): boolean { | ||
| if (!this.isInvalidAttributeError()) { | ||
| return false; | ||
| } | ||
|
|
||
| return this.getAttributeValidationDetails().some((detail) => { | ||
| const attributeIds: unknown = detail.attributeIds; | ||
|
|
||
| return ( | ||
| detail.code === "passwordPolicyViolation" && | ||
| Array.isArray(attributeIds) && | ||
| attributeIds.some( | ||
| (attributeId: unknown) => | ||
| typeof attributeId === "string" && | ||
| attributeId.toLowerCase() === "password" | ||
| ) | ||
| Array.isArray(attributeIds) && attributeIds.includes("password") | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.