@azure/identity 3.3.2-alpha.20231013.2 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/dist/index.js +216 -103
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.js +2 -2
- package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +2 -2
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js +2 -2
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +2 -2
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.js +2 -2
- package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +3 -3
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js +3 -3
- package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.js +2 -2
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.js +2 -2
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +5 -5
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +2 -2
- package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +14 -4
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +11 -3
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.js +3 -3
- package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +2 -2
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.js +2 -2
- package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js +2 -2
- package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist-esm/src/errors.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +2 -2
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +2 -2
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +142 -16
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
- package/dist-esm/src/msal/utils.js +4 -3
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/dist-esm/src/plugins/provider.js.map +1 -1
- package/dist-esm/src/util/scopeUtils.js +1 -1
- package/dist-esm/src/util/scopeUtils.js.map +1 -1
- package/dist-esm/src/util/tenantIdUtils.js +3 -3
- package/dist-esm/src/util/tenantIdUtils.js.map +1 -1
- package/package.json +15 -14
- package/types/identity.d.ts +4 -6
- package/dist-esm/src/msal/utils.browser.js +0 -236
- package/dist-esm/src/msal/utils.browser.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/identity",
|
|
3
3
|
"sdk-type": "client",
|
|
4
|
-
"version": "3.3.2
|
|
4
|
+
"version": "3.3.2",
|
|
5
5
|
"description": "Provides credential implementations for Azure SDK libraries that can authenticate with Azure Active Directory",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist-esm/src/index.js",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"./dist-esm/src/credentials/azureApplicationCredential.js": "./dist-esm/src/credentials/azureApplicationCredential.browser.js",
|
|
27
27
|
"./dist-esm/src/credentials/onBehalfOfCredential.js": "./dist-esm/src/credentials/onBehalfOfCredential.browser.js",
|
|
28
28
|
"./dist-esm/src/credentials/workloadIdentityCredential.js": "./dist-esm/src/credentials/workloadIdentityCredential.browser.js",
|
|
29
|
-
"./dist-esm/src/msal/utils.js": "./dist-esm/src/msal/utils.browser.js",
|
|
30
29
|
"./dist-esm/src/util/authHostEnv.js": "./dist-esm/src/util/authHostEnv.browser.js",
|
|
31
30
|
"./dist-esm/src/util/processMultiTenantRequest.js": "./dist-esm/src/util/processMultiTenantRequest.browser.js",
|
|
32
31
|
"./dist-esm/src/tokenCache/TokenCachePersistence.js": "./dist-esm/src/tokenCache/TokenCachePersistence.browser.js",
|
|
@@ -84,7 +83,7 @@
|
|
|
84
83
|
]
|
|
85
84
|
},
|
|
86
85
|
"engines": {
|
|
87
|
-
"node": ">=
|
|
86
|
+
"node": ">=14.0.0"
|
|
88
87
|
},
|
|
89
88
|
"repository": "github:Azure/azure-sdk-for-js",
|
|
90
89
|
"keywords": [
|
|
@@ -113,32 +112,34 @@
|
|
|
113
112
|
"@azure/core-tracing": "^1.0.0",
|
|
114
113
|
"@azure/core-util": "^1.0.0",
|
|
115
114
|
"@azure/logger": "^1.0.0",
|
|
116
|
-
"@azure/msal-browser": "^
|
|
117
|
-
"@azure/msal-
|
|
115
|
+
"@azure/msal-browser": "^2.37.1",
|
|
116
|
+
"@azure/msal-common": "^13.1.0",
|
|
117
|
+
"@azure/msal-node": "^1.17.3",
|
|
118
118
|
"events": "^3.0.0",
|
|
119
119
|
"jws": "^4.0.0",
|
|
120
120
|
"open": "^8.0.0",
|
|
121
121
|
"stoppable": "^1.1.0",
|
|
122
|
-
"tslib": "^2.2.0"
|
|
122
|
+
"tslib": "^2.2.0",
|
|
123
|
+
"uuid": "^8.3.0"
|
|
123
124
|
},
|
|
124
125
|
"devDependencies": {
|
|
125
126
|
"@azure-tools/test-recorder": "^3.0.0",
|
|
126
|
-
"@azure/dev-tool": "
|
|
127
|
-
"@azure/eslint-plugin-azure-sdk": "
|
|
127
|
+
"@azure/dev-tool": "^1.0.0",
|
|
128
|
+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
128
129
|
"@azure/keyvault-keys": "^4.2.0",
|
|
129
|
-
"@azure/test-utils": "
|
|
130
|
+
"@azure/test-utils": "^1.0.0",
|
|
130
131
|
"@microsoft/api-extractor": "^7.31.1",
|
|
131
132
|
"@types/chai": "^4.1.6",
|
|
132
133
|
"@types/jsonwebtoken": "^9.0.0",
|
|
133
134
|
"@types/jws": "^3.2.2",
|
|
134
|
-
"@types/mocha": "^
|
|
135
|
+
"@types/mocha": "^7.0.2",
|
|
135
136
|
"@types/ms": "^0.7.31",
|
|
136
|
-
"@types/node": "^
|
|
137
|
+
"@types/node": "^14.0.0",
|
|
137
138
|
"@types/sinon": "^10.0.0",
|
|
138
139
|
"@types/stoppable": "^1.1.0",
|
|
139
140
|
"@types/uuid": "^8.0.0",
|
|
140
141
|
"chai": "^4.2.0",
|
|
141
|
-
"cross-env": "^7.0.
|
|
142
|
+
"cross-env": "^7.0.2",
|
|
142
143
|
"dotenv": "^16.0.0",
|
|
143
144
|
"eslint": "^8.0.0",
|
|
144
145
|
"inherits": "^2.0.3",
|
|
@@ -151,7 +152,7 @@
|
|
|
151
152
|
"karma-mocha": "^2.0.1",
|
|
152
153
|
"karma-mocha-reporter": "^2.2.5",
|
|
153
154
|
"karma-sourcemap-loader": "^0.3.8",
|
|
154
|
-
"mocha": "^
|
|
155
|
+
"mocha": "^7.1.1",
|
|
155
156
|
"mocha-junit-reporter": "^2.0.0",
|
|
156
157
|
"ms": "^2.1.3",
|
|
157
158
|
"nyc": "^15.0.0",
|
|
@@ -162,6 +163,6 @@
|
|
|
162
163
|
"ts-node": "^10.0.0",
|
|
163
164
|
"typescript": "~5.0.0",
|
|
164
165
|
"util": "^0.12.1",
|
|
165
|
-
"
|
|
166
|
+
"uuid": "^8.3.2"
|
|
166
167
|
}
|
|
167
168
|
}
|
package/types/identity.d.ts
CHANGED
|
@@ -470,7 +470,7 @@ export declare interface ClientAssertionCredentialOptions extends MultiTenantTok
|
|
|
470
470
|
* certificate that is assigned to an App Registration. More information
|
|
471
471
|
* on how to configure certificate authentication can be found here:
|
|
472
472
|
*
|
|
473
|
-
* https://
|
|
473
|
+
* https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad
|
|
474
474
|
*
|
|
475
475
|
*/
|
|
476
476
|
export declare class ClientCertificateCredential implements TokenCredential {
|
|
@@ -950,7 +950,7 @@ export declare interface EnvironmentCredentialOptions extends MultiTenantTokenCr
|
|
|
950
950
|
/**
|
|
951
951
|
* See the official documentation for more details:
|
|
952
952
|
*
|
|
953
|
-
* https://
|
|
953
|
+
* https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1
|
|
954
954
|
*
|
|
955
955
|
* NOTE: This documentation is for v1 OAuth support but the same error
|
|
956
956
|
* response details still apply to v2.
|
|
@@ -1053,7 +1053,6 @@ export declare interface InteractiveBrowserCredentialInBrowserOptions extends In
|
|
|
1053
1053
|
/**
|
|
1054
1054
|
* Gets the redirect URI of the application. This should be same as the value
|
|
1055
1055
|
* in the application registration portal. Defaults to `window.location.href`.
|
|
1056
|
-
* This field is no longer required for Node.js.
|
|
1057
1056
|
*/
|
|
1058
1057
|
redirectUri?: string | (() => string);
|
|
1059
1058
|
/**
|
|
@@ -1086,7 +1085,6 @@ export declare interface InteractiveBrowserCredentialNodeOptions extends Interac
|
|
|
1086
1085
|
/**
|
|
1087
1086
|
* Gets the redirect URI of the application. This should be same as the value
|
|
1088
1087
|
* in the application registration portal. Defaults to `window.location.href`.
|
|
1089
|
-
* This field is no longer required for Node.js.
|
|
1090
1088
|
*/
|
|
1091
1089
|
redirectUri?: string | (() => string);
|
|
1092
1090
|
/**
|
|
@@ -1137,7 +1135,7 @@ export declare const logger: AzureLogger;
|
|
|
1137
1135
|
* Azure Kubernetes Services, Azure Service Fabric instances and inside of the Azure Cloud Shell.
|
|
1138
1136
|
*
|
|
1139
1137
|
* More information about configuring managed identities can be found here:
|
|
1140
|
-
* https://
|
|
1138
|
+
* https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
|
|
1141
1139
|
*/
|
|
1142
1140
|
export declare class ManagedIdentityCredential implements TokenCredential {
|
|
1143
1141
|
private identityClient;
|
|
@@ -1228,7 +1226,7 @@ export declare interface MultiTenantTokenCredentialOptions extends TokenCredenti
|
|
|
1228
1226
|
}
|
|
1229
1227
|
|
|
1230
1228
|
/**
|
|
1231
|
-
* Enables authentication to
|
|
1229
|
+
* Enables authentication to Microsoft Entra ID using the [On Behalf Of flow](https://learn.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
|
|
1232
1230
|
*/
|
|
1233
1231
|
export declare class OnBehalfOfCredential implements TokenCredential {
|
|
1234
1232
|
private options;
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
import * as msalCommon from "@azure/msal-browser";
|
|
4
|
-
import { AuthenticationRequiredError, CredentialUnavailableError } from "../errors";
|
|
5
|
-
import { formatError, formatSuccess } from "../util/logging";
|
|
6
|
-
import { DefaultAuthorityHost, DefaultTenantId } from "../constants";
|
|
7
|
-
import { AbortError } from "@azure/abort-controller";
|
|
8
|
-
import { isNode, randomUUID } from "@azure/core-util";
|
|
9
|
-
/**
|
|
10
|
-
* Latest AuthenticationRecord version
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const LatestAuthenticationRecordVersion = "1.0";
|
|
14
|
-
/**
|
|
15
|
-
* Ensures the validity of the MSAL token
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export function ensureValidMsalToken(scopes, logger, msalToken, getTokenOptions) {
|
|
19
|
-
const error = (message) => {
|
|
20
|
-
logger.getToken.info(message);
|
|
21
|
-
return new AuthenticationRequiredError({
|
|
22
|
-
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
23
|
-
getTokenOptions,
|
|
24
|
-
message,
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
if (!msalToken) {
|
|
28
|
-
throw error("No response");
|
|
29
|
-
}
|
|
30
|
-
if (!msalToken.expiresOn) {
|
|
31
|
-
throw error(`Response had no "expiresOn" property.`);
|
|
32
|
-
}
|
|
33
|
-
if (!msalToken.accessToken) {
|
|
34
|
-
throw error(`Response had no "accessToken" property.`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Generates a valid authority by combining a host with a tenantId.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
export function getAuthority(tenantId, host) {
|
|
42
|
-
if (!host) {
|
|
43
|
-
host = DefaultAuthorityHost;
|
|
44
|
-
}
|
|
45
|
-
if (new RegExp(`${tenantId}/?$`).test(host)) {
|
|
46
|
-
return host;
|
|
47
|
-
}
|
|
48
|
-
if (host.endsWith("/")) {
|
|
49
|
-
return host + tenantId;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return `${host}/${tenantId}`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Generates the known authorities.
|
|
57
|
-
* If the Tenant Id is `adfs`, the authority can't be validated since the format won't match the expected one.
|
|
58
|
-
* For that reason, we have to force MSAL to disable validating the authority
|
|
59
|
-
* by sending it within the known authorities in the MSAL configuration.
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
export function getKnownAuthorities(tenantId, authorityHost, disableInstanceDiscovery) {
|
|
63
|
-
if ((tenantId === "adfs" && authorityHost) || disableInstanceDiscovery) {
|
|
64
|
-
return [authorityHost];
|
|
65
|
-
}
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Generates a logger that can be passed to the MSAL clients.
|
|
70
|
-
* @param logger - The logger of the credential.
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
export const defaultLoggerCallback = (logger, platform = isNode ? "Node" : "Browser") => (level, message, containsPii) => {
|
|
74
|
-
if (containsPii) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
switch (level) {
|
|
78
|
-
case msalCommon.LogLevel.Error:
|
|
79
|
-
logger.info(`MSAL ${platform} V2 error: ${message}`);
|
|
80
|
-
return;
|
|
81
|
-
case msalCommon.LogLevel.Info:
|
|
82
|
-
logger.info(`MSAL ${platform} V2 info message: ${message}`);
|
|
83
|
-
return;
|
|
84
|
-
case msalCommon.LogLevel.Verbose:
|
|
85
|
-
logger.info(`MSAL ${platform} V2 verbose message: ${message}`);
|
|
86
|
-
return;
|
|
87
|
-
case msalCommon.LogLevel.Warning:
|
|
88
|
-
logger.info(`MSAL ${platform} V2 warning: ${message}`);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* @internal
|
|
94
|
-
*/
|
|
95
|
-
export function getMSALLogLevel(logLevel) {
|
|
96
|
-
switch (logLevel) {
|
|
97
|
-
case "error":
|
|
98
|
-
return msalCommon.LogLevel.Error;
|
|
99
|
-
case "info":
|
|
100
|
-
return msalCommon.LogLevel.Info;
|
|
101
|
-
case "verbose":
|
|
102
|
-
return msalCommon.LogLevel.Verbose;
|
|
103
|
-
case "warning":
|
|
104
|
-
return msalCommon.LogLevel.Warning;
|
|
105
|
-
default:
|
|
106
|
-
// default msal logging level should be Info
|
|
107
|
-
return msalCommon.LogLevel.Info;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The common utility functions for the MSAL clients.
|
|
112
|
-
* Defined as a class so that the classes extending this one can have access to its methods and protected properties.
|
|
113
|
-
*
|
|
114
|
-
* It keeps track of a logger and an in-memory copy of the AuthenticationRecord.
|
|
115
|
-
*
|
|
116
|
-
* @internal
|
|
117
|
-
*/
|
|
118
|
-
export class MsalBaseUtilities {
|
|
119
|
-
constructor(options) {
|
|
120
|
-
this.logger = options.logger;
|
|
121
|
-
this.account = options.authenticationRecord;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Generates a UUID
|
|
125
|
-
*/
|
|
126
|
-
generateUuid() {
|
|
127
|
-
return randomUUID();
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Handles the MSAL authentication result.
|
|
131
|
-
* If the result has an account, we update the local account reference.
|
|
132
|
-
* If the token received is invalid, an error will be thrown depending on what's missing.
|
|
133
|
-
*/
|
|
134
|
-
handleResult(scopes, clientId, result, getTokenOptions) {
|
|
135
|
-
if (result === null || result === void 0 ? void 0 : result.account) {
|
|
136
|
-
this.account = msalToPublic(clientId, result.account);
|
|
137
|
-
}
|
|
138
|
-
ensureValidMsalToken(scopes, this.logger, result, getTokenOptions);
|
|
139
|
-
this.logger.getToken.info(formatSuccess(scopes));
|
|
140
|
-
return {
|
|
141
|
-
token: result.accessToken,
|
|
142
|
-
expiresOnTimestamp: result.expiresOn.getTime(),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Handles MSAL errors.
|
|
147
|
-
*/
|
|
148
|
-
handleError(scopes, error, getTokenOptions) {
|
|
149
|
-
if (error.name === "AuthError" ||
|
|
150
|
-
error.name === "ClientAuthError" ||
|
|
151
|
-
error.name === "BrowserAuthError") {
|
|
152
|
-
const msalError = error;
|
|
153
|
-
switch (msalError.errorCode) {
|
|
154
|
-
case "endpoints_resolution_error":
|
|
155
|
-
this.logger.info(formatError(scopes, error.message));
|
|
156
|
-
return new CredentialUnavailableError(error.message);
|
|
157
|
-
case "device_code_polling_cancelled":
|
|
158
|
-
return new AbortError("The authentication has been aborted by the caller.");
|
|
159
|
-
case "consent_required":
|
|
160
|
-
case "interaction_required":
|
|
161
|
-
case "login_required":
|
|
162
|
-
this.logger.info(formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`));
|
|
163
|
-
break;
|
|
164
|
-
default:
|
|
165
|
-
this.logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (error.name === "ClientConfigurationError" ||
|
|
170
|
-
error.name === "BrowserConfigurationAuthError" ||
|
|
171
|
-
error.name === "AbortError") {
|
|
172
|
-
return error;
|
|
173
|
-
}
|
|
174
|
-
return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// transformations.ts
|
|
178
|
-
export function publicToMsal(account) {
|
|
179
|
-
const [environment] = account.authority.match(/([a-z]*\.[a-z]*\.[a-z]*)/) || [""];
|
|
180
|
-
return Object.assign(Object.assign({}, account), { localAccountId: account.homeAccountId, environment });
|
|
181
|
-
}
|
|
182
|
-
export function msalToPublic(clientId, account) {
|
|
183
|
-
const record = {
|
|
184
|
-
authority: getAuthority(account.tenantId, account.environment),
|
|
185
|
-
homeAccountId: account.homeAccountId,
|
|
186
|
-
tenantId: account.tenantId || DefaultTenantId,
|
|
187
|
-
username: account.username,
|
|
188
|
-
clientId,
|
|
189
|
-
version: LatestAuthenticationRecordVersion,
|
|
190
|
-
};
|
|
191
|
-
return record;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Serializes an `AuthenticationRecord` into a string.
|
|
195
|
-
*
|
|
196
|
-
* The output of a serialized authentication record will contain the following properties:
|
|
197
|
-
*
|
|
198
|
-
* - "authority"
|
|
199
|
-
* - "homeAccountId"
|
|
200
|
-
* - "clientId"
|
|
201
|
-
* - "tenantId"
|
|
202
|
-
* - "username"
|
|
203
|
-
* - "version"
|
|
204
|
-
*
|
|
205
|
-
* To later convert this string to a serialized `AuthenticationRecord`, please use the exported function `deserializeAuthenticationRecord()`.
|
|
206
|
-
*/
|
|
207
|
-
export function serializeAuthenticationRecord(record) {
|
|
208
|
-
return JSON.stringify(record);
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Deserializes a previously serialized authentication record from a string into an object.
|
|
212
|
-
*
|
|
213
|
-
* The input string must contain the following properties:
|
|
214
|
-
*
|
|
215
|
-
* - "authority"
|
|
216
|
-
* - "homeAccountId"
|
|
217
|
-
* - "clientId"
|
|
218
|
-
* - "tenantId"
|
|
219
|
-
* - "username"
|
|
220
|
-
* - "version"
|
|
221
|
-
*
|
|
222
|
-
* If the version we receive is unsupported, an error will be thrown.
|
|
223
|
-
*
|
|
224
|
-
* At the moment, the only available version is: "1.0", which is always set when the authentication record is serialized.
|
|
225
|
-
*
|
|
226
|
-
* @param serializedRecord - Authentication record previously serialized into string.
|
|
227
|
-
* @returns AuthenticationRecord.
|
|
228
|
-
*/
|
|
229
|
-
export function deserializeAuthenticationRecord(serializedRecord) {
|
|
230
|
-
const parsed = JSON.parse(serializedRecord);
|
|
231
|
-
if (parsed.version && parsed.version !== LatestAuthenticationRecordVersion) {
|
|
232
|
-
throw Error("Unsupported AuthenticationRecord version");
|
|
233
|
-
}
|
|
234
|
-
return parsed;
|
|
235
|
-
}
|
|
236
|
-
//# sourceMappingURL=utils.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.browser.js","sourceRoot":"","sources":["../../../src/msal/utils.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,UAAU,MAAM,qBAAq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AAU,YAAY,CAAC,OAA6B;IACxD,MAAM,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClF,uCACK,OAAO,KACV,cAAc,EAAE,OAAO,CAAC,aAAa,EACrC,WAAW,IACX;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,OAAwB;IACrE,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC;QAC9D,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,eAAe;QAC7C,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,QAAQ;QACR,OAAO,EAAE,iCAAiC;KAC3C,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAA4B;IACxE,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,+BAA+B,CAAC,gBAAwB;IACtE,MAAM,MAAM,GAAgD,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEzF,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,iCAAiC,EAAE;QAC1E,MAAM,KAAK,CAAC,0CAA0C,CAAC,CAAC;KACzD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalCommon from \"@azure/msal-browser\";\nimport { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport { AuthenticationRecord, MsalAccountInfo, MsalResult, MsalToken } from \"./types\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../errors\";\nimport { CredentialLogger, formatError, formatSuccess } from \"../util/logging\";\nimport { DefaultAuthorityHost, DefaultTenantId } from \"../constants\";\nimport { AbortError } from \"@azure/abort-controller\";\nimport { MsalFlowOptions } from \"./flows\";\nimport { isNode, randomUUID } from \"@azure/core-util\";\nimport { AzureLogLevel } from \"@azure/logger\";\n\nexport interface ILoggerCallback {\n (level: msalCommon.LogLevel, message: string, containsPii: boolean): void;\n}\n\n/**\n * Latest AuthenticationRecord version\n * @internal\n */\nconst LatestAuthenticationRecordVersion = \"1.0\";\n\n/**\n * Ensures the validity of the MSAL token\n * @internal\n */\nexport function ensureValidMsalToken(\n scopes: string | string[],\n logger: CredentialLogger,\n msalToken?: MsalToken,\n getTokenOptions?: GetTokenOptions\n): void {\n const error = (message: string): Error => {\n logger.getToken.info(message);\n return new AuthenticationRequiredError({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n getTokenOptions,\n message,\n });\n };\n if (!msalToken) {\n throw error(\"No response\");\n }\n if (!msalToken.expiresOn) {\n throw error(`Response had no \"expiresOn\" property.`);\n }\n if (!msalToken.accessToken) {\n throw error(`Response had no \"accessToken\" property.`);\n }\n}\n\n/**\n * Generates a valid authority by combining a host with a tenantId.\n * @internal\n */\nexport function getAuthority(tenantId: string, host?: string): string {\n if (!host) {\n host = DefaultAuthorityHost;\n }\n if (new RegExp(`${tenantId}/?$`).test(host)) {\n return host;\n }\n if (host.endsWith(\"/\")) {\n return host + tenantId;\n } else {\n return `${host}/${tenantId}`;\n }\n}\n\n/**\n * Generates the known authorities.\n * If the Tenant Id is `adfs`, the authority can't be validated since the format won't match the expected one.\n * For that reason, we have to force MSAL to disable validating the authority\n * by sending it within the known authorities in the MSAL configuration.\n * @internal\n */\nexport function getKnownAuthorities(\n tenantId: string,\n authorityHost: string,\n disableInstanceDiscovery?: boolean\n): string[] {\n if ((tenantId === \"adfs\" && authorityHost) || disableInstanceDiscovery) {\n return [authorityHost];\n }\n return [];\n}\n\n/**\n * Generates a logger that can be passed to the MSAL clients.\n * @param logger - The logger of the credential.\n * @internal\n */\nexport const defaultLoggerCallback: (\n logger: CredentialLogger,\n platform?: \"Node\" | \"Browser\"\n) => msalCommon.ILoggerCallback =\n (logger: CredentialLogger, platform: \"Node\" | \"Browser\" = isNode ? \"Node\" : \"Browser\") =>\n (level, message, containsPii): void => {\n if (containsPii) {\n return;\n }\n switch (level) {\n case msalCommon.LogLevel.Error:\n logger.info(`MSAL ${platform} V2 error: ${message}`);\n return;\n case msalCommon.LogLevel.Info:\n logger.info(`MSAL ${platform} V2 info message: ${message}`);\n return;\n case msalCommon.LogLevel.Verbose:\n logger.info(`MSAL ${platform} V2 verbose message: ${message}`);\n return;\n case msalCommon.LogLevel.Warning:\n logger.info(`MSAL ${platform} V2 warning: ${message}`);\n return;\n }\n };\n\n/**\n * @internal\n */\nexport function getMSALLogLevel(logLevel: AzureLogLevel | undefined): msalCommon.LogLevel {\n switch (logLevel) {\n case \"error\":\n return msalCommon.LogLevel.Error;\n case \"info\":\n return msalCommon.LogLevel.Info;\n case \"verbose\":\n return msalCommon.LogLevel.Verbose;\n case \"warning\":\n return msalCommon.LogLevel.Warning;\n default:\n // default msal logging level should be Info\n return msalCommon.LogLevel.Info;\n }\n}\n\n/**\n * The common utility functions for the MSAL clients.\n * Defined as a class so that the classes extending this one can have access to its methods and protected properties.\n *\n * It keeps track of a logger and an in-memory copy of the AuthenticationRecord.\n *\n * @internal\n */\nexport class MsalBaseUtilities {\n protected logger: CredentialLogger;\n protected account: AuthenticationRecord | undefined;\n\n constructor(options: MsalFlowOptions) {\n this.logger = options.logger;\n this.account = options.authenticationRecord;\n }\n\n /**\n * Generates a UUID\n */\n generateUuid(): string {\n return randomUUID();\n }\n\n /**\n * Handles the MSAL authentication result.\n * If the result has an account, we update the local account reference.\n * If the token received is invalid, an error will be thrown depending on what's missing.\n */\n protected handleResult(\n scopes: string | string[],\n clientId: string,\n result?: MsalResult,\n getTokenOptions?: GetTokenOptions\n ): AccessToken {\n if (result?.account) {\n this.account = msalToPublic(clientId, result.account);\n }\n ensureValidMsalToken(scopes, this.logger, result, getTokenOptions);\n this.logger.getToken.info(formatSuccess(scopes));\n return {\n token: result!.accessToken!,\n expiresOnTimestamp: result!.expiresOn!.getTime(),\n };\n }\n\n /**\n * Handles MSAL errors.\n */\n protected handleError(scopes: string[], error: Error, getTokenOptions?: GetTokenOptions): Error {\n if (\n error.name === \"AuthError\" ||\n error.name === \"ClientAuthError\" ||\n error.name === \"BrowserAuthError\"\n ) {\n const msalError = error as msalCommon.AuthError;\n switch (msalError.errorCode) {\n case \"endpoints_resolution_error\":\n this.logger.info(formatError(scopes, error.message));\n return new CredentialUnavailableError(error.message);\n case \"device_code_polling_cancelled\":\n return new AbortError(\"The authentication has been aborted by the caller.\");\n case \"consent_required\":\n case \"interaction_required\":\n case \"login_required\":\n this.logger.info(\n formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`)\n );\n break;\n default:\n this.logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));\n break;\n }\n }\n if (\n error.name === \"ClientConfigurationError\" ||\n error.name === \"BrowserConfigurationAuthError\" ||\n error.name === \"AbortError\"\n ) {\n return error;\n }\n return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });\n }\n}\n\n// transformations.ts\n\nexport function publicToMsal(account: AuthenticationRecord): msalCommon.AccountInfo {\n const [environment] = account.authority.match(/([a-z]*\\.[a-z]*\\.[a-z]*)/) || [\"\"];\n return {\n ...account,\n localAccountId: account.homeAccountId,\n environment,\n };\n}\n\nexport function msalToPublic(clientId: string, account: MsalAccountInfo): AuthenticationRecord {\n const record = {\n authority: getAuthority(account.tenantId, account.environment),\n homeAccountId: account.homeAccountId,\n tenantId: account.tenantId || DefaultTenantId,\n username: account.username,\n clientId,\n version: LatestAuthenticationRecordVersion,\n };\n return record;\n}\n\n/**\n * Serializes an `AuthenticationRecord` into a string.\n *\n * The output of a serialized authentication record will contain the following properties:\n *\n * - \"authority\"\n * - \"homeAccountId\"\n * - \"clientId\"\n * - \"tenantId\"\n * - \"username\"\n * - \"version\"\n *\n * To later convert this string to a serialized `AuthenticationRecord`, please use the exported function `deserializeAuthenticationRecord()`.\n */\nexport function serializeAuthenticationRecord(record: AuthenticationRecord): string {\n return JSON.stringify(record);\n}\n\n/**\n * Deserializes a previously serialized authentication record from a string into an object.\n *\n * The input string must contain the following properties:\n *\n * - \"authority\"\n * - \"homeAccountId\"\n * - \"clientId\"\n * - \"tenantId\"\n * - \"username\"\n * - \"version\"\n *\n * If the version we receive is unsupported, an error will be thrown.\n *\n * At the moment, the only available version is: \"1.0\", which is always set when the authentication record is serialized.\n *\n * @param serializedRecord - Authentication record previously serialized into string.\n * @returns AuthenticationRecord.\n */\nexport function deserializeAuthenticationRecord(serializedRecord: string): AuthenticationRecord {\n const parsed: AuthenticationRecord & { version?: string } = JSON.parse(serializedRecord);\n\n if (parsed.version && parsed.version !== LatestAuthenticationRecordVersion) {\n throw Error(\"Unsupported AuthenticationRecord version\");\n }\n\n return parsed;\n}\n"]}
|