@azure/identity 3.3.2-alpha.20231016.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/README.md +14 -14
- package/dist/index.js +260 -147
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/credentials/authorityValidationOptions.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.js +6 -6
- package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +3 -3
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js +6 -6
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +3 -3
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.js +5 -5
- package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +5 -5
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js +7 -7
- package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.js +7 -7
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.js +6 -6
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +3 -3
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +8 -8
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +8 -8
- 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 +12 -4
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.js +4 -4
- package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +6 -6
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.js +6 -6
- 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/credentials/workloadIdentityCredential.browser.js +2 -2
- package/dist-esm/src/credentials/workloadIdentityCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredential.js +5 -5
- package/dist-esm/src/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredentialOptions.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/tokenCredentialOptions.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 +70 -72
- package/dist-esm/src/msal/utils.browser.js +0 -236
- package/dist-esm/src/msal/utils.browser.js.map +0 -1
|
@@ -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,qBAAqB,CAAC;AAGlD,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,EAAoB,WAAW,EAAE,aA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C,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"]}
|