From c0168e6a21df1cc9d0947b4deacd3bed77af333b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Tue, 6 Apr 2021 19:07:24 -0400 Subject: [PATCH 1/4] [Identity] Getting rid of instanceof I had some isntances of `instanceof`, which is causing issues once @azure/msal-common gets updated, since @azure/msal-node hasn't been released with the latest version of @azure/msal-common. I know that checking for `names` is the way to go, but I had forgotten to remove these before. This will fix `rush update --full`. --- sdk/identity/identity/src/msal/utils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/identity/identity/src/msal/utils.ts b/sdk/identity/identity/src/msal/utils.ts index ff2787caacdc..7b936089e2bb 100644 --- a/sdk/identity/identity/src/msal/utils.ts +++ b/sdk/identity/identity/src/msal/utils.ts @@ -149,8 +149,9 @@ export class MsalBaseUtilities { * Handles MSAL errors. */ protected handleError(scopes: string[], error: Error, getTokenOptions?: GetTokenOptions): Error { - if (error instanceof msalCommon.AuthError) { - switch (error.errorCode) { + if (error.name === "AuthError" || error.name === "ClientAuthError") { + const msalError = error as msalCommon.AuthError; + switch (msalError.errorCode) { case "endpoints_resolution_error": this.logger.info(formatError(scopes, error.message)); return new CredentialUnavailable(error.message); @@ -158,7 +159,7 @@ export class MsalBaseUtilities { case "interaction_required": case "login_required": this.logger.info( - formatError(scopes, `Authentication returned errorCode ${error.errorCode}`) + formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`) ); break; default: @@ -166,7 +167,7 @@ export class MsalBaseUtilities { break; } } - if (error instanceof msalCommon.ClientConfigurationError) { + if (error.name === "ClientConfigurationError") { return error; } if (error.name === "AbortError") { From 3479dcedde33b9222ad9bad214f9964fc7f7a098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Tue, 6 Apr 2021 19:19:09 -0400 Subject: [PATCH 2/4] Update CHANGELOG.md --- sdk/identity/identity/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/identity/identity/CHANGELOG.md b/sdk/identity/identity/CHANGELOG.md index 36862fe3969c..e05f408a431d 100644 --- a/sdk/identity/identity/CHANGELOG.md +++ b/sdk/identity/identity/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2.0.0-beta.2 (Unreleased) +- Bug fix: Replaced cases where `instanceof` was used to compare errors with comparisons on the error names. Uneven updates on our dependencies would cause `instanceof` to mismatch our error comparisons. Comparing by error name makes sure dependency changes won't alter our logic. - Added `clientId` to the `AuthenticationRecord` type. - `AuthenticationRecord` no longer has a `serialize` method. This method is now called `serializeAuthenticationRecord` and is a function exported at the top level of the Identity library, similar to `deserializeAuthenticationRecord`. - `serializeAuthenticationRecord` now serializes into a JSON string with camel case properties. This makes it re-usable across languages. From 5b01a8dda26b7aae14549e5bce3fd5a8876d564d Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 6 Apr 2021 23:34:52 +0000 Subject: [PATCH 3/4] CHANGELOG feedback --- sdk/identity/identity/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/identity/identity/CHANGELOG.md b/sdk/identity/identity/CHANGELOG.md index e05f408a431d..36862fe3969c 100644 --- a/sdk/identity/identity/CHANGELOG.md +++ b/sdk/identity/identity/CHANGELOG.md @@ -2,7 +2,6 @@ ## 2.0.0-beta.2 (Unreleased) -- Bug fix: Replaced cases where `instanceof` was used to compare errors with comparisons on the error names. Uneven updates on our dependencies would cause `instanceof` to mismatch our error comparisons. Comparing by error name makes sure dependency changes won't alter our logic. - Added `clientId` to the `AuthenticationRecord` type. - `AuthenticationRecord` no longer has a `serialize` method. This method is now called `serializeAuthenticationRecord` and is a function exported at the top level of the Identity library, similar to `deserializeAuthenticationRecord`. - `serializeAuthenticationRecord` now serializes into a JSON string with camel case properties. This makes it re-usable across languages. From d67b6453c346b2c8806970a987795b17646899ef Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 6 Apr 2021 23:35:24 +0000 Subject: [PATCH 4/4] more MSAL errors --- sdk/identity/identity/src/msal/utils.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sdk/identity/identity/src/msal/utils.ts b/sdk/identity/identity/src/msal/utils.ts index 7b936089e2bb..55d6df133f3e 100644 --- a/sdk/identity/identity/src/msal/utils.ts +++ b/sdk/identity/identity/src/msal/utils.ts @@ -149,7 +149,11 @@ export class MsalBaseUtilities { * Handles MSAL errors. */ protected handleError(scopes: string[], error: Error, getTokenOptions?: GetTokenOptions): Error { - if (error.name === "AuthError" || error.name === "ClientAuthError") { + if ( + error.name === "AuthError" || + error.name === "ClientAuthError" || + error.name === "BrowserAuthError" + ) { const msalError = error as msalCommon.AuthError; switch (msalError.errorCode) { case "endpoints_resolution_error": @@ -167,10 +171,11 @@ export class MsalBaseUtilities { break; } } - if (error.name === "ClientConfigurationError") { - return error; - } - if (error.name === "AbortError") { + if ( + error.name === "ClientConfigurationError" || + error.name === "BrowserConfigurationAuthError" || + error.name === "AbortError" + ) { return error; } return new AuthenticationRequired(scopes, getTokenOptions, error.message);