@azure/msal-node 2.2.0 → 2.3.0-alpha.0

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