@azure/msal-node 2.12.0 → 2.13.1

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.
Files changed (159) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +423 -423
  3. package/dist/cache/NodeStorage.d.ts +193 -193
  4. package/dist/cache/NodeStorage.mjs +423 -423
  5. package/dist/cache/TokenCache.cjs +265 -265
  6. package/dist/cache/TokenCache.d.ts +90 -90
  7. package/dist/cache/TokenCache.mjs +265 -265
  8. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  9. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  10. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  11. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  12. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  13. package/dist/cache/serializer/Deserializer.cjs +167 -167
  14. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  15. package/dist/cache/serializer/Deserializer.mjs +167 -167
  16. package/dist/cache/serializer/Serializer.cjs +137 -137
  17. package/dist/cache/serializer/Serializer.d.ts +39 -39
  18. package/dist/cache/serializer/Serializer.mjs +137 -137
  19. package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
  20. package/dist/client/ClientApplication.cjs +334 -334
  21. package/dist/client/ClientApplication.d.ts +143 -143
  22. package/dist/client/ClientApplication.mjs +334 -334
  23. package/dist/client/ClientAssertion.cjs +143 -143
  24. package/dist/client/ClientAssertion.d.ts +55 -55
  25. package/dist/client/ClientAssertion.mjs +143 -143
  26. package/dist/client/ClientCredentialClient.cjs +194 -194
  27. package/dist/client/ClientCredentialClient.d.ts +33 -33
  28. package/dist/client/ClientCredentialClient.mjs +194 -194
  29. package/dist/client/ConfidentialClientApplication.cjs +169 -169
  30. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  31. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  32. package/dist/client/ConfidentialClientApplication.mjs +169 -169
  33. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  34. package/dist/client/DeviceCodeClient.cjs +207 -207
  35. package/dist/client/DeviceCodeClient.d.ts +53 -53
  36. package/dist/client/DeviceCodeClient.mjs +207 -207
  37. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  38. package/dist/client/IPublicClientApplication.d.ts +42 -42
  39. package/dist/client/ManagedIdentityApplication.cjs +84 -84
  40. package/dist/client/ManagedIdentityApplication.d.ts +30 -30
  41. package/dist/client/ManagedIdentityApplication.mjs +84 -84
  42. package/dist/client/ManagedIdentityClient.cjs +60 -60
  43. package/dist/client/ManagedIdentityClient.d.ts +27 -27
  44. package/dist/client/ManagedIdentityClient.mjs +60 -60
  45. package/dist/client/ManagedIdentitySources/AppService.cjs +45 -45
  46. package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -17
  47. package/dist/client/ManagedIdentitySources/AppService.mjs +45 -45
  48. package/dist/client/ManagedIdentitySources/AzureArc.cjs +155 -120
  49. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  50. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +27 -23
  51. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  52. package/dist/client/ManagedIdentitySources/AzureArc.mjs +155 -122
  53. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  54. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +122 -122
  55. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
  56. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -30
  57. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +122 -122
  58. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  59. package/dist/client/ManagedIdentitySources/CloudShell.cjs +38 -38
  60. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -16
  61. package/dist/client/ManagedIdentitySources/CloudShell.mjs +38 -38
  62. package/dist/client/ManagedIdentitySources/Imds.cjs +43 -43
  63. package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
  64. package/dist/client/ManagedIdentitySources/Imds.mjs +43 -43
  65. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +54 -54
  66. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -17
  67. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +54 -54
  68. package/dist/client/OnBehalfOfClient.cjs +202 -202
  69. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  70. package/dist/client/OnBehalfOfClient.mjs +202 -202
  71. package/dist/client/PublicClientApplication.cjs +237 -237
  72. package/dist/client/PublicClientApplication.d.ts +72 -72
  73. package/dist/client/PublicClientApplication.mjs +237 -237
  74. package/dist/client/UsernamePasswordClient.cjs +95 -95
  75. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  76. package/dist/client/UsernamePasswordClient.mjs +95 -95
  77. package/dist/config/Configuration.cjs +106 -106
  78. package/dist/config/Configuration.d.ts +131 -131
  79. package/dist/config/Configuration.mjs +106 -106
  80. package/dist/config/ManagedIdentityId.cjs +48 -48
  81. package/dist/config/ManagedIdentityId.d.ts +11 -11
  82. package/dist/config/ManagedIdentityId.mjs +48 -48
  83. package/dist/config/ManagedIdentityRequestParameters.cjs +28 -28
  84. package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
  85. package/dist/config/ManagedIdentityRequestParameters.mjs +28 -28
  86. package/dist/crypto/CryptoProvider.cjs +89 -89
  87. package/dist/crypto/CryptoProvider.d.ts +62 -62
  88. package/dist/crypto/CryptoProvider.mjs +89 -89
  89. package/dist/crypto/GuidGenerator.cjs +22 -22
  90. package/dist/crypto/GuidGenerator.d.ts +14 -14
  91. package/dist/crypto/GuidGenerator.mjs +22 -22
  92. package/dist/crypto/HashUtils.cjs +13 -13
  93. package/dist/crypto/HashUtils.d.ts +8 -8
  94. package/dist/crypto/HashUtils.mjs +13 -13
  95. package/dist/crypto/PkceGenerator.cjs +49 -49
  96. package/dist/crypto/PkceGenerator.d.ts +22 -22
  97. package/dist/crypto/PkceGenerator.mjs +49 -49
  98. package/dist/error/ManagedIdentityError.cjs +41 -41
  99. package/dist/error/ManagedIdentityError.d.ts +30 -30
  100. package/dist/error/ManagedIdentityError.mjs +41 -41
  101. package/dist/error/ManagedIdentityErrorCodes.cjs +24 -24
  102. package/dist/error/ManagedIdentityErrorCodes.d.ts +22 -22
  103. package/dist/error/ManagedIdentityErrorCodes.mjs +24 -24
  104. package/dist/error/NodeAuthError.cjs +95 -95
  105. package/dist/error/NodeAuthError.d.ts +73 -73
  106. package/dist/error/NodeAuthError.mjs +95 -95
  107. package/dist/index.cjs +1 -1
  108. package/dist/index.d.ts +45 -45
  109. package/dist/index.mjs +1 -1
  110. package/dist/internals.cjs +8 -8
  111. package/dist/internals.d.ts +6 -6
  112. package/dist/internals.mjs +8 -8
  113. package/dist/network/HttpClient.cjs +281 -281
  114. package/dist/network/HttpClient.d.ts +25 -25
  115. package/dist/network/HttpClient.mjs +281 -281
  116. package/dist/network/HttpClientWithRetries.cjs +34 -34
  117. package/dist/network/HttpClientWithRetries.d.ts +11 -11
  118. package/dist/network/HttpClientWithRetries.mjs +34 -34
  119. package/dist/network/ILoopbackClient.d.ts +10 -10
  120. package/dist/network/LoopbackClient.cjs +81 -77
  121. package/dist/network/LoopbackClient.cjs.map +1 -1
  122. package/dist/network/LoopbackClient.d.ts +21 -21
  123. package/dist/network/LoopbackClient.d.ts.map +1 -1
  124. package/dist/network/LoopbackClient.mjs +81 -77
  125. package/dist/network/LoopbackClient.mjs.map +1 -1
  126. package/dist/packageMetadata.cjs +4 -4
  127. package/dist/packageMetadata.d.ts +2 -2
  128. package/dist/packageMetadata.mjs +4 -4
  129. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  130. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  131. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  132. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  133. package/dist/request/InteractiveRequest.d.ts +22 -22
  134. package/dist/request/ManagedIdentityRequest.d.ts +8 -8
  135. package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
  136. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  137. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  138. package/dist/request/SignOutRequest.d.ts +5 -5
  139. package/dist/request/SilentFlowRequest.d.ts +16 -16
  140. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  141. package/dist/response/ManagedIdentityTokenResponse.d.ts +34 -34
  142. package/dist/retry/IHttpRetryPolicy.d.ts +5 -5
  143. package/dist/retry/LinearRetryPolicy.cjs +40 -40
  144. package/dist/retry/LinearRetryPolicy.d.ts +11 -11
  145. package/dist/retry/LinearRetryPolicy.mjs +40 -40
  146. package/dist/utils/Constants.cjs +136 -136
  147. package/dist/utils/Constants.d.ts +141 -141
  148. package/dist/utils/Constants.mjs +136 -136
  149. package/dist/utils/EncodingUtils.cjs +44 -44
  150. package/dist/utils/EncodingUtils.d.ts +26 -26
  151. package/dist/utils/EncodingUtils.mjs +44 -44
  152. package/dist/utils/NetworkUtils.cjs +38 -38
  153. package/dist/utils/NetworkUtils.d.ts +5 -5
  154. package/dist/utils/NetworkUtils.mjs +38 -38
  155. package/package.json +2 -2
  156. package/src/client/ConfidentialClientApplication.ts +3 -3
  157. package/src/client/ManagedIdentitySources/AzureArc.ts +80 -25
  158. package/src/network/LoopbackClient.ts +7 -1
  159. package/src/packageMetadata.ts +1 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.12.0 2024-07-23 */
1
+ /*! @azure/msal-node v2.13.1 2024-08-29 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -10,242 +10,242 @@ var LoopbackClient = require('../network/LoopbackClient.cjs');
10
10
  var DeviceCodeClient = require('./DeviceCodeClient.cjs');
11
11
  var packageMetadata = require('../packageMetadata.cjs');
12
12
 
13
- /*
14
- * Copyright (c) Microsoft Corporation. All rights reserved.
15
- * Licensed under the MIT License.
16
- */
17
- /**
18
- * This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
19
- * are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
20
- * @public
21
- */
22
- class PublicClientApplication extends ClientApplication.ClientApplication {
23
- /**
24
- * Important attributes in the Configuration object for auth are:
25
- * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
26
- * - authority: the authority URL for your application.
27
- *
28
- * AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
29
- * - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
30
- * - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
31
- * - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
32
- * - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
33
- *
34
- * Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
35
- * its own authority. You will have to set the all of the knownAuthorities at the time of the client application
36
- * construction.
37
- *
38
- * ADFS authorities are of the form https://\{instance\}/adfs.
39
- */
40
- constructor(configuration) {
41
- super(configuration);
42
- if (this.config.broker.nativeBrokerPlugin) {
43
- if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
44
- this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
45
- this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
46
- }
47
- else {
48
- this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
49
- }
50
- }
51
- this.skus = msalCommon.ServerTelemetryManager.makeExtraSkuString({
52
- libraryName: Constants.Constants.MSAL_SKU,
53
- libraryVersion: packageMetadata.version,
54
- });
55
- }
56
- /**
57
- * Acquires a token from the authority using OAuth2.0 device code flow.
58
- * This flow is designed for devices that do not have access to a browser or have input constraints.
59
- * The authorization server issues a DeviceCode object with a verification code, an end-user code,
60
- * and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
61
- * instructed to use another device to navigate to the verification URI to input credentials.
62
- * Since the client cannot receive incoming requests, it polls the authorization server repeatedly
63
- * until the end-user completes input of credentials.
64
- */
65
- async acquireTokenByDeviceCode(request) {
66
- this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
67
- const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
68
- const serverTelemetryManager = this.initializeServerTelemetryManager(Constants.ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
69
- try {
70
- const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
71
- const deviceCodeClient = new DeviceCodeClient.DeviceCodeClient(deviceCodeConfig);
72
- this.logger.verbose("Device code client created", validRequest.correlationId);
73
- return await deviceCodeClient.acquireToken(validRequest);
74
- }
75
- catch (e) {
76
- if (e instanceof msalCommon.AuthError) {
77
- e.setCorrelationId(validRequest.correlationId);
78
- }
79
- serverTelemetryManager.cacheFailedRequest(e);
80
- throw e;
81
- }
82
- }
83
- /**
84
- * Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
85
- */
86
- async acquireTokenInteractive(request) {
87
- const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
88
- this.logger.trace("acquireTokenInteractive called", correlationId);
89
- const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
90
- if (this.nativeBrokerPlugin) {
91
- const brokerRequest = {
92
- ...remainingProperties,
93
- clientId: this.config.auth.clientId,
94
- scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
95
- redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
96
- authority: request.authority || this.config.auth.authority,
97
- correlationId: correlationId,
98
- extraParameters: {
99
- ...remainingProperties.extraQueryParameters,
100
- ...remainingProperties.tokenQueryParameters,
101
- [msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
102
- },
103
- accountId: remainingProperties.account?.nativeAccountId,
104
- };
105
- return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
106
- }
107
- const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
108
- const loopbackClient = customLoopbackClient || new LoopbackClient.LoopbackClient();
109
- let authCodeResponse = {};
110
- let authCodeListenerError = null;
111
- try {
112
- const authCodeListener = loopbackClient
113
- .listenForAuthCode(successTemplate, errorTemplate)
114
- .then((response) => {
115
- authCodeResponse = response;
116
- })
117
- .catch((e) => {
118
- // Store the promise instead of throwing so we can control when its thrown
119
- authCodeListenerError = e;
120
- });
121
- // Wait for server to be listening
122
- const redirectUri = await this.waitForRedirectUri(loopbackClient);
123
- const validRequest = {
124
- ...remainingProperties,
125
- correlationId: correlationId,
126
- scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
127
- redirectUri: redirectUri,
128
- responseMode: msalCommon.ResponseMode.QUERY,
129
- codeChallenge: challenge,
130
- codeChallengeMethod: msalCommon.CodeChallengeMethodValues.S256,
131
- };
132
- const authCodeUrl = await this.getAuthCodeUrl(validRequest);
133
- await openBrowser(authCodeUrl);
134
- await authCodeListener;
135
- if (authCodeListenerError) {
136
- throw authCodeListenerError;
137
- }
138
- if (authCodeResponse.error) {
139
- throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
140
- }
141
- else if (!authCodeResponse.code) {
142
- throw NodeAuthError.NodeAuthError.createNoAuthCodeInResponseError();
143
- }
144
- const clientInfo = authCodeResponse.client_info;
145
- const tokenRequest = {
146
- code: authCodeResponse.code,
147
- codeVerifier: verifier,
148
- clientInfo: clientInfo || msalCommon.Constants.EMPTY_STRING,
149
- ...validRequest,
150
- };
151
- return await this.acquireTokenByCode(tokenRequest); // Await this so the server doesn't close prematurely
152
- }
153
- finally {
154
- loopbackClient.closeServer();
155
- }
156
- }
157
- /**
158
- * Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
159
- * @param request
160
- * @returns
161
- */
162
- async acquireTokenSilent(request) {
163
- const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
164
- this.logger.trace("acquireTokenSilent called", correlationId);
165
- if (this.nativeBrokerPlugin) {
166
- const brokerRequest = {
167
- ...request,
168
- clientId: this.config.auth.clientId,
169
- scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
170
- redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
171
- authority: request.authority || this.config.auth.authority,
172
- correlationId: correlationId,
173
- extraParameters: {
174
- ...request.tokenQueryParameters,
175
- [msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
176
- },
177
- accountId: request.account.nativeAccountId,
178
- forceRefresh: request.forceRefresh || false,
179
- };
180
- return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
181
- }
182
- return super.acquireTokenSilent(request);
183
- }
184
- /**
185
- * Removes cache artifacts associated with the given account
186
- * @param request
187
- * @returns
188
- */
189
- async signOut(request) {
190
- if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
191
- const signoutRequest = {
192
- clientId: this.config.auth.clientId,
193
- accountId: request.account.nativeAccountId,
194
- correlationId: request.correlationId ||
195
- this.cryptoProvider.createNewGuid(),
196
- };
197
- await this.nativeBrokerPlugin.signOut(signoutRequest);
198
- }
199
- await this.getTokenCache().removeAccount(request.account);
200
- }
201
- /**
202
- * Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
203
- * @returns
204
- */
205
- async getAllAccounts() {
206
- if (this.nativeBrokerPlugin) {
207
- const correlationId = this.cryptoProvider.createNewGuid();
208
- return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
209
- }
210
- return this.getTokenCache().getAllAccounts();
211
- }
212
- /**
213
- * Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
214
- * @param loopbackClient
215
- * @returns
216
- */
217
- async waitForRedirectUri(loopbackClient) {
218
- return new Promise((resolve, reject) => {
219
- let ticks = 0;
220
- const id = setInterval(() => {
221
- if (Constants.LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
222
- Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
223
- ticks) {
224
- clearInterval(id);
225
- reject(NodeAuthError.NodeAuthError.createLoopbackServerTimeoutError());
226
- return;
227
- }
228
- try {
229
- const r = loopbackClient.getRedirectUri();
230
- clearInterval(id);
231
- resolve(r);
232
- return;
233
- }
234
- catch (e) {
235
- if (e instanceof msalCommon.AuthError &&
236
- e.errorCode ===
237
- NodeAuthError.NodeAuthErrorMessage.noLoopbackServerExists.code) {
238
- // Loopback server is not listening yet
239
- ticks++;
240
- return;
241
- }
242
- clearInterval(id);
243
- reject(e);
244
- return;
245
- }
246
- }, Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
247
- });
248
- }
13
+ /*
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License.
16
+ */
17
+ /**
18
+ * This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
19
+ * are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
20
+ * @public
21
+ */
22
+ class PublicClientApplication extends ClientApplication.ClientApplication {
23
+ /**
24
+ * Important attributes in the Configuration object for auth are:
25
+ * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
26
+ * - authority: the authority URL for your application.
27
+ *
28
+ * AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
29
+ * - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
30
+ * - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
31
+ * - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
32
+ * - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
33
+ *
34
+ * Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
35
+ * its own authority. You will have to set the all of the knownAuthorities at the time of the client application
36
+ * construction.
37
+ *
38
+ * ADFS authorities are of the form https://\{instance\}/adfs.
39
+ */
40
+ constructor(configuration) {
41
+ super(configuration);
42
+ if (this.config.broker.nativeBrokerPlugin) {
43
+ if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
44
+ this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
45
+ this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
46
+ }
47
+ else {
48
+ this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
49
+ }
50
+ }
51
+ this.skus = msalCommon.ServerTelemetryManager.makeExtraSkuString({
52
+ libraryName: Constants.Constants.MSAL_SKU,
53
+ libraryVersion: packageMetadata.version,
54
+ });
55
+ }
56
+ /**
57
+ * Acquires a token from the authority using OAuth2.0 device code flow.
58
+ * This flow is designed for devices that do not have access to a browser or have input constraints.
59
+ * The authorization server issues a DeviceCode object with a verification code, an end-user code,
60
+ * and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
61
+ * instructed to use another device to navigate to the verification URI to input credentials.
62
+ * Since the client cannot receive incoming requests, it polls the authorization server repeatedly
63
+ * until the end-user completes input of credentials.
64
+ */
65
+ async acquireTokenByDeviceCode(request) {
66
+ this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
67
+ const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
68
+ const serverTelemetryManager = this.initializeServerTelemetryManager(Constants.ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
69
+ try {
70
+ const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
71
+ const deviceCodeClient = new DeviceCodeClient.DeviceCodeClient(deviceCodeConfig);
72
+ this.logger.verbose("Device code client created", validRequest.correlationId);
73
+ return await deviceCodeClient.acquireToken(validRequest);
74
+ }
75
+ catch (e) {
76
+ if (e instanceof msalCommon.AuthError) {
77
+ e.setCorrelationId(validRequest.correlationId);
78
+ }
79
+ serverTelemetryManager.cacheFailedRequest(e);
80
+ throw e;
81
+ }
82
+ }
83
+ /**
84
+ * Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
85
+ */
86
+ async acquireTokenInteractive(request) {
87
+ const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
88
+ this.logger.trace("acquireTokenInteractive called", correlationId);
89
+ const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
90
+ if (this.nativeBrokerPlugin) {
91
+ const brokerRequest = {
92
+ ...remainingProperties,
93
+ clientId: this.config.auth.clientId,
94
+ scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
95
+ redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
96
+ authority: request.authority || this.config.auth.authority,
97
+ correlationId: correlationId,
98
+ extraParameters: {
99
+ ...remainingProperties.extraQueryParameters,
100
+ ...remainingProperties.tokenQueryParameters,
101
+ [msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
102
+ },
103
+ accountId: remainingProperties.account?.nativeAccountId,
104
+ };
105
+ return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
106
+ }
107
+ const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
108
+ const loopbackClient = customLoopbackClient || new LoopbackClient.LoopbackClient();
109
+ let authCodeResponse = {};
110
+ let authCodeListenerError = null;
111
+ try {
112
+ const authCodeListener = loopbackClient
113
+ .listenForAuthCode(successTemplate, errorTemplate)
114
+ .then((response) => {
115
+ authCodeResponse = response;
116
+ })
117
+ .catch((e) => {
118
+ // Store the promise instead of throwing so we can control when its thrown
119
+ authCodeListenerError = e;
120
+ });
121
+ // Wait for server to be listening
122
+ const redirectUri = await this.waitForRedirectUri(loopbackClient);
123
+ const validRequest = {
124
+ ...remainingProperties,
125
+ correlationId: correlationId,
126
+ scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
127
+ redirectUri: redirectUri,
128
+ responseMode: msalCommon.ResponseMode.QUERY,
129
+ codeChallenge: challenge,
130
+ codeChallengeMethod: msalCommon.CodeChallengeMethodValues.S256,
131
+ };
132
+ const authCodeUrl = await this.getAuthCodeUrl(validRequest);
133
+ await openBrowser(authCodeUrl);
134
+ await authCodeListener;
135
+ if (authCodeListenerError) {
136
+ throw authCodeListenerError;
137
+ }
138
+ if (authCodeResponse.error) {
139
+ throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
140
+ }
141
+ else if (!authCodeResponse.code) {
142
+ throw NodeAuthError.NodeAuthError.createNoAuthCodeInResponseError();
143
+ }
144
+ const clientInfo = authCodeResponse.client_info;
145
+ const tokenRequest = {
146
+ code: authCodeResponse.code,
147
+ codeVerifier: verifier,
148
+ clientInfo: clientInfo || msalCommon.Constants.EMPTY_STRING,
149
+ ...validRequest,
150
+ };
151
+ return await this.acquireTokenByCode(tokenRequest); // Await this so the server doesn't close prematurely
152
+ }
153
+ finally {
154
+ loopbackClient.closeServer();
155
+ }
156
+ }
157
+ /**
158
+ * Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
159
+ * @param request
160
+ * @returns
161
+ */
162
+ async acquireTokenSilent(request) {
163
+ const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
164
+ this.logger.trace("acquireTokenSilent called", correlationId);
165
+ if (this.nativeBrokerPlugin) {
166
+ const brokerRequest = {
167
+ ...request,
168
+ clientId: this.config.auth.clientId,
169
+ scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
170
+ redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
171
+ authority: request.authority || this.config.auth.authority,
172
+ correlationId: correlationId,
173
+ extraParameters: {
174
+ ...request.tokenQueryParameters,
175
+ [msalCommon.AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
176
+ },
177
+ accountId: request.account.nativeAccountId,
178
+ forceRefresh: request.forceRefresh || false,
179
+ };
180
+ return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
181
+ }
182
+ return super.acquireTokenSilent(request);
183
+ }
184
+ /**
185
+ * Removes cache artifacts associated with the given account
186
+ * @param request
187
+ * @returns
188
+ */
189
+ async signOut(request) {
190
+ if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
191
+ const signoutRequest = {
192
+ clientId: this.config.auth.clientId,
193
+ accountId: request.account.nativeAccountId,
194
+ correlationId: request.correlationId ||
195
+ this.cryptoProvider.createNewGuid(),
196
+ };
197
+ await this.nativeBrokerPlugin.signOut(signoutRequest);
198
+ }
199
+ await this.getTokenCache().removeAccount(request.account);
200
+ }
201
+ /**
202
+ * Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
203
+ * @returns
204
+ */
205
+ async getAllAccounts() {
206
+ if (this.nativeBrokerPlugin) {
207
+ const correlationId = this.cryptoProvider.createNewGuid();
208
+ return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
209
+ }
210
+ return this.getTokenCache().getAllAccounts();
211
+ }
212
+ /**
213
+ * Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
214
+ * @param loopbackClient
215
+ * @returns
216
+ */
217
+ async waitForRedirectUri(loopbackClient) {
218
+ return new Promise((resolve, reject) => {
219
+ let ticks = 0;
220
+ const id = setInterval(() => {
221
+ if (Constants.LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
222
+ Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
223
+ ticks) {
224
+ clearInterval(id);
225
+ reject(NodeAuthError.NodeAuthError.createLoopbackServerTimeoutError());
226
+ return;
227
+ }
228
+ try {
229
+ const r = loopbackClient.getRedirectUri();
230
+ clearInterval(id);
231
+ resolve(r);
232
+ return;
233
+ }
234
+ catch (e) {
235
+ if (e instanceof msalCommon.AuthError &&
236
+ e.errorCode ===
237
+ NodeAuthError.NodeAuthErrorMessage.noLoopbackServerExists.code) {
238
+ // Loopback server is not listening yet
239
+ ticks++;
240
+ return;
241
+ }
242
+ clearInterval(id);
243
+ reject(e);
244
+ return;
245
+ }
246
+ }, Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
247
+ });
248
+ }
249
249
  }
250
250
 
251
251
  exports.PublicClientApplication = PublicClientApplication;
@@ -1,73 +1,73 @@
1
- import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
2
- import { Configuration } from "../config/Configuration.js";
3
- import { ClientApplication } from "./ClientApplication.js";
4
- import { IPublicClientApplication } from "./IPublicClientApplication.js";
5
- import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
6
- import { InteractiveRequest } from "../request/InteractiveRequest.js";
7
- import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
8
- import { SignOutRequest } from "../request/SignOutRequest.js";
9
- /**
10
- * This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
11
- * are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
12
- * @public
13
- */
14
- export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
15
- private nativeBrokerPlugin?;
16
- private readonly skus;
17
- /**
18
- * Important attributes in the Configuration object for auth are:
19
- * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
20
- * - authority: the authority URL for your application.
21
- *
22
- * AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
23
- * - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
24
- * - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
25
- * - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
26
- * - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
27
- *
28
- * Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
29
- * its own authority. You will have to set the all of the knownAuthorities at the time of the client application
30
- * construction.
31
- *
32
- * ADFS authorities are of the form https://\{instance\}/adfs.
33
- */
34
- constructor(configuration: Configuration);
35
- /**
36
- * Acquires a token from the authority using OAuth2.0 device code flow.
37
- * This flow is designed for devices that do not have access to a browser or have input constraints.
38
- * The authorization server issues a DeviceCode object with a verification code, an end-user code,
39
- * and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
40
- * instructed to use another device to navigate to the verification URI to input credentials.
41
- * Since the client cannot receive incoming requests, it polls the authorization server repeatedly
42
- * until the end-user completes input of credentials.
43
- */
44
- acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
45
- /**
46
- * Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
47
- */
48
- acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
49
- /**
50
- * Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
51
- * @param request
52
- * @returns
53
- */
54
- acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
55
- /**
56
- * Removes cache artifacts associated with the given account
57
- * @param request
58
- * @returns
59
- */
60
- signOut(request: SignOutRequest): Promise<void>;
61
- /**
62
- * Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
63
- * @returns
64
- */
65
- getAllAccounts(): Promise<AccountInfo[]>;
66
- /**
67
- * Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
68
- * @param loopbackClient
69
- * @returns
70
- */
71
- private waitForRedirectUri;
72
- }
1
+ import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
2
+ import { Configuration } from "../config/Configuration.js";
3
+ import { ClientApplication } from "./ClientApplication.js";
4
+ import { IPublicClientApplication } from "./IPublicClientApplication.js";
5
+ import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
6
+ import { InteractiveRequest } from "../request/InteractiveRequest.js";
7
+ import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
8
+ import { SignOutRequest } from "../request/SignOutRequest.js";
9
+ /**
10
+ * This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
11
+ * are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
12
+ * @public
13
+ */
14
+ export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
15
+ private nativeBrokerPlugin?;
16
+ private readonly skus;
17
+ /**
18
+ * Important attributes in the Configuration object for auth are:
19
+ * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
20
+ * - authority: the authority URL for your application.
21
+ *
22
+ * AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
23
+ * - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
24
+ * - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
25
+ * - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
26
+ * - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
27
+ *
28
+ * Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
29
+ * its own authority. You will have to set the all of the knownAuthorities at the time of the client application
30
+ * construction.
31
+ *
32
+ * ADFS authorities are of the form https://\{instance\}/adfs.
33
+ */
34
+ constructor(configuration: Configuration);
35
+ /**
36
+ * Acquires a token from the authority using OAuth2.0 device code flow.
37
+ * This flow is designed for devices that do not have access to a browser or have input constraints.
38
+ * The authorization server issues a DeviceCode object with a verification code, an end-user code,
39
+ * and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
40
+ * instructed to use another device to navigate to the verification URI to input credentials.
41
+ * Since the client cannot receive incoming requests, it polls the authorization server repeatedly
42
+ * until the end-user completes input of credentials.
43
+ */
44
+ acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
45
+ /**
46
+ * Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
47
+ */
48
+ acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
49
+ /**
50
+ * Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
51
+ * @param request
52
+ * @returns
53
+ */
54
+ acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
55
+ /**
56
+ * Removes cache artifacts associated with the given account
57
+ * @param request
58
+ * @returns
59
+ */
60
+ signOut(request: SignOutRequest): Promise<void>;
61
+ /**
62
+ * Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
63
+ * @returns
64
+ */
65
+ getAllAccounts(): Promise<AccountInfo[]>;
66
+ /**
67
+ * Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
68
+ * @param loopbackClient
69
+ * @returns
70
+ */
71
+ private waitForRedirectUri;
72
+ }
73
73
  //# sourceMappingURL=PublicClientApplication.d.ts.map