@azure/msal-node 2.11.1 → 2.13.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 (200) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +425 -423
  3. package/dist/cache/NodeStorage.cjs.map +1 -1
  4. package/dist/cache/NodeStorage.d.ts +193 -193
  5. package/dist/cache/NodeStorage.mjs +423 -423
  6. package/dist/cache/TokenCache.cjs +267 -265
  7. package/dist/cache/TokenCache.cjs.map +1 -1
  8. package/dist/cache/TokenCache.d.ts +90 -90
  9. package/dist/cache/TokenCache.mjs +265 -265
  10. package/dist/cache/distributed/DistributedCachePlugin.cjs +28 -26
  11. package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
  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 +169 -167
  17. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  18. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  19. package/dist/cache/serializer/Deserializer.mjs +167 -167
  20. package/dist/cache/serializer/Serializer.cjs +139 -137
  21. package/dist/cache/serializer/Serializer.cjs.map +1 -1
  22. package/dist/cache/serializer/Serializer.d.ts +39 -39
  23. package/dist/cache/serializer/Serializer.mjs +137 -137
  24. package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
  25. package/dist/client/ClientApplication.cjs +336 -334
  26. package/dist/client/ClientApplication.cjs.map +1 -1
  27. package/dist/client/ClientApplication.d.ts +143 -143
  28. package/dist/client/ClientApplication.mjs +334 -334
  29. package/dist/client/ClientAssertion.cjs +149 -143
  30. package/dist/client/ClientAssertion.cjs.map +1 -1
  31. package/dist/client/ClientAssertion.d.ts +55 -55
  32. package/dist/client/ClientAssertion.mjs +143 -143
  33. package/dist/client/ClientCredentialClient.cjs +196 -194
  34. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  35. package/dist/client/ClientCredentialClient.d.ts +33 -33
  36. package/dist/client/ClientCredentialClient.mjs +194 -194
  37. package/dist/client/ConfidentialClientApplication.cjs +170 -169
  38. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  39. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  40. package/dist/client/ConfidentialClientApplication.mjs +168 -169
  41. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  42. package/dist/client/DeviceCodeClient.cjs +209 -207
  43. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  44. package/dist/client/DeviceCodeClient.d.ts +53 -53
  45. package/dist/client/DeviceCodeClient.mjs +207 -207
  46. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  47. package/dist/client/IPublicClientApplication.d.ts +42 -42
  48. package/dist/client/ManagedIdentityApplication.cjs +86 -84
  49. package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
  50. package/dist/client/ManagedIdentityApplication.d.ts +30 -30
  51. package/dist/client/ManagedIdentityApplication.mjs +84 -84
  52. package/dist/client/ManagedIdentityClient.cjs +62 -60
  53. package/dist/client/ManagedIdentityClient.cjs.map +1 -1
  54. package/dist/client/ManagedIdentityClient.d.ts +27 -27
  55. package/dist/client/ManagedIdentityClient.mjs +60 -60
  56. package/dist/client/ManagedIdentitySources/AppService.cjs +47 -45
  57. package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
  58. package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -17
  59. package/dist/client/ManagedIdentitySources/AppService.mjs +46 -46
  60. package/dist/client/ManagedIdentitySources/AzureArc.cjs +161 -120
  61. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  62. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +27 -23
  63. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  64. package/dist/client/ManagedIdentitySources/AzureArc.mjs +155 -122
  65. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  66. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +124 -122
  67. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
  68. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -30
  69. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +122 -122
  70. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  71. package/dist/client/ManagedIdentitySources/CloudShell.cjs +40 -38
  72. package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -1
  73. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -16
  74. package/dist/client/ManagedIdentitySources/CloudShell.mjs +39 -39
  75. package/dist/client/ManagedIdentitySources/Imds.cjs +45 -43
  76. package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
  77. package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
  78. package/dist/client/ManagedIdentitySources/Imds.mjs +44 -44
  79. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +56 -54
  80. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -1
  81. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -17
  82. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +55 -55
  83. package/dist/client/OnBehalfOfClient.cjs +204 -202
  84. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  85. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  86. package/dist/client/OnBehalfOfClient.mjs +202 -202
  87. package/dist/client/PublicClientApplication.cjs +240 -229
  88. package/dist/client/PublicClientApplication.cjs.map +1 -1
  89. package/dist/client/PublicClientApplication.d.ts +72 -71
  90. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  91. package/dist/client/PublicClientApplication.mjs +240 -231
  92. package/dist/client/PublicClientApplication.mjs.map +1 -1
  93. package/dist/client/UsernamePasswordClient.cjs +97 -95
  94. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  95. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  96. package/dist/client/UsernamePasswordClient.mjs +95 -95
  97. package/dist/config/Configuration.cjs +108 -106
  98. package/dist/config/Configuration.cjs.map +1 -1
  99. package/dist/config/Configuration.d.ts +131 -131
  100. package/dist/config/Configuration.mjs +106 -106
  101. package/dist/config/ManagedIdentityId.cjs +50 -48
  102. package/dist/config/ManagedIdentityId.cjs.map +1 -1
  103. package/dist/config/ManagedIdentityId.d.ts +11 -11
  104. package/dist/config/ManagedIdentityId.mjs +48 -48
  105. package/dist/config/ManagedIdentityRequestParameters.cjs +30 -28
  106. package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
  107. package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
  108. package/dist/config/ManagedIdentityRequestParameters.mjs +28 -28
  109. package/dist/crypto/CryptoProvider.cjs +91 -89
  110. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  111. package/dist/crypto/CryptoProvider.d.ts +62 -62
  112. package/dist/crypto/CryptoProvider.mjs +89 -89
  113. package/dist/crypto/GuidGenerator.cjs +24 -22
  114. package/dist/crypto/GuidGenerator.cjs.map +1 -1
  115. package/dist/crypto/GuidGenerator.d.ts +14 -14
  116. package/dist/crypto/GuidGenerator.mjs +22 -22
  117. package/dist/crypto/HashUtils.cjs +19 -13
  118. package/dist/crypto/HashUtils.cjs.map +1 -1
  119. package/dist/crypto/HashUtils.d.ts +8 -8
  120. package/dist/crypto/HashUtils.mjs +13 -13
  121. package/dist/crypto/PkceGenerator.cjs +55 -49
  122. package/dist/crypto/PkceGenerator.cjs.map +1 -1
  123. package/dist/crypto/PkceGenerator.d.ts +22 -22
  124. package/dist/crypto/PkceGenerator.mjs +49 -49
  125. package/dist/error/ManagedIdentityError.cjs +43 -41
  126. package/dist/error/ManagedIdentityError.cjs.map +1 -1
  127. package/dist/error/ManagedIdentityError.d.ts +30 -30
  128. package/dist/error/ManagedIdentityError.mjs +41 -41
  129. package/dist/error/ManagedIdentityErrorCodes.cjs +26 -24
  130. package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
  131. package/dist/error/ManagedIdentityErrorCodes.d.ts +22 -22
  132. package/dist/error/ManagedIdentityErrorCodes.mjs +24 -24
  133. package/dist/error/NodeAuthError.cjs +97 -95
  134. package/dist/error/NodeAuthError.cjs.map +1 -1
  135. package/dist/error/NodeAuthError.d.ts +73 -73
  136. package/dist/error/NodeAuthError.mjs +95 -95
  137. package/dist/index.cjs +3 -1
  138. package/dist/index.cjs.map +1 -1
  139. package/dist/index.d.ts +45 -45
  140. package/dist/index.mjs +1 -1
  141. package/dist/internals.cjs +6 -8
  142. package/dist/internals.cjs.map +1 -1
  143. package/dist/internals.d.ts +6 -6
  144. package/dist/internals.mjs +4 -8
  145. package/dist/internals.mjs.map +1 -1
  146. package/dist/network/HttpClient.cjs +288 -281
  147. package/dist/network/HttpClient.cjs.map +1 -1
  148. package/dist/network/HttpClient.d.ts +25 -25
  149. package/dist/network/HttpClient.mjs +281 -281
  150. package/dist/network/HttpClientWithRetries.cjs +36 -34
  151. package/dist/network/HttpClientWithRetries.cjs.map +1 -1
  152. package/dist/network/HttpClientWithRetries.d.ts +11 -11
  153. package/dist/network/HttpClientWithRetries.mjs +34 -34
  154. package/dist/network/ILoopbackClient.d.ts +10 -10
  155. package/dist/network/LoopbackClient.cjs +87 -77
  156. package/dist/network/LoopbackClient.cjs.map +1 -1
  157. package/dist/network/LoopbackClient.d.ts +21 -21
  158. package/dist/network/LoopbackClient.d.ts.map +1 -1
  159. package/dist/network/LoopbackClient.mjs +81 -77
  160. package/dist/network/LoopbackClient.mjs.map +1 -1
  161. package/dist/packageMetadata.cjs +6 -4
  162. package/dist/packageMetadata.cjs.map +1 -1
  163. package/dist/packageMetadata.d.ts +2 -2
  164. package/dist/packageMetadata.mjs +4 -4
  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 +8 -8
  171. package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
  172. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  173. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  174. package/dist/request/SignOutRequest.d.ts +5 -5
  175. package/dist/request/SilentFlowRequest.d.ts +16 -16
  176. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  177. package/dist/response/ManagedIdentityTokenResponse.d.ts +34 -34
  178. package/dist/retry/IHttpRetryPolicy.d.ts +5 -5
  179. package/dist/retry/LinearRetryPolicy.cjs +42 -40
  180. package/dist/retry/LinearRetryPolicy.cjs.map +1 -1
  181. package/dist/retry/LinearRetryPolicy.d.ts +11 -11
  182. package/dist/retry/LinearRetryPolicy.mjs +40 -40
  183. package/dist/utils/Constants.cjs +138 -136
  184. package/dist/utils/Constants.cjs.map +1 -1
  185. package/dist/utils/Constants.d.ts +141 -141
  186. package/dist/utils/Constants.mjs +136 -136
  187. package/dist/utils/EncodingUtils.cjs +46 -44
  188. package/dist/utils/EncodingUtils.cjs.map +1 -1
  189. package/dist/utils/EncodingUtils.d.ts +26 -26
  190. package/dist/utils/EncodingUtils.mjs +44 -44
  191. package/dist/utils/NetworkUtils.cjs +40 -38
  192. package/dist/utils/NetworkUtils.cjs.map +1 -1
  193. package/dist/utils/NetworkUtils.d.ts +5 -5
  194. package/dist/utils/NetworkUtils.mjs +38 -38
  195. package/package.json +2 -2
  196. package/src/client/ConfidentialClientApplication.ts +3 -3
  197. package/src/client/ManagedIdentitySources/AzureArc.ts +80 -25
  198. package/src/client/PublicClientApplication.ts +13 -1
  199. package/src/network/LoopbackClient.ts +6 -0
  200. package/src/packageMetadata.ts +1 -1
@@ -1,103 +1,105 @@
1
- /*! @azure/msal-node v2.11.1 2024-07-16 */
1
+ /*! @azure/msal-node v2.13.0 2024-08-13 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
5
+ Object.defineProperty(exports, '__esModule', { value: true });
6
+
5
7
  var msalCommon = require('@azure/msal-common');
6
8
 
7
- /*
8
- * Copyright (c) Microsoft Corporation. All rights reserved.
9
- * Licensed under the MIT License.
10
- */
11
- /**
12
- * Oauth2.0 Password grant client
13
- * Note: We are only supporting public clients for password grant and for purely testing purposes
14
- */
15
- class UsernamePasswordClient extends msalCommon.BaseClient {
16
- constructor(configuration) {
17
- super(configuration);
18
- }
19
- /**
20
- * API to acquire a token by passing the username and password to the service in exchage of credentials
21
- * password_grant
22
- * @param request
23
- */
24
- async acquireToken(request) {
25
- this.logger.info("in acquireToken call in username-password client");
26
- const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
27
- const response = await this.executeTokenRequest(this.authority, request);
28
- const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
29
- // Validate response. This function throws a server error if an error is returned by the server.
30
- responseHandler.validateTokenResponse(response.body);
31
- const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
32
- return tokenResponse;
33
- }
34
- /**
35
- * Executes POST request to token endpoint
36
- * @param authority
37
- * @param request
38
- */
39
- async executeTokenRequest(authority, request) {
40
- const queryParametersString = this.createTokenQueryParameters(request);
41
- const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
42
- const requestBody = await this.createTokenRequestBody(request);
43
- const headers = this.createTokenRequestHeaders({
44
- credential: request.username,
45
- type: msalCommon.CcsCredentialType.UPN,
46
- });
47
- const thumbprint = {
48
- clientId: this.config.authOptions.clientId,
49
- authority: authority.canonicalAuthority,
50
- scopes: request.scopes,
51
- claims: request.claims,
52
- authenticationScheme: request.authenticationScheme,
53
- resourceRequestMethod: request.resourceRequestMethod,
54
- resourceRequestUri: request.resourceRequestUri,
55
- shrClaims: request.shrClaims,
56
- sshKid: request.sshKid,
57
- };
58
- return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
59
- }
60
- /**
61
- * Generates a map for all the params to be sent to the service
62
- * @param request
63
- */
64
- async createTokenRequestBody(request) {
65
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
66
- parameterBuilder.addClientId(this.config.authOptions.clientId);
67
- parameterBuilder.addUsername(request.username);
68
- parameterBuilder.addPassword(request.password);
69
- parameterBuilder.addScopes(request.scopes);
70
- parameterBuilder.addResponseTypeForTokenAndIdToken();
71
- parameterBuilder.addGrantType(msalCommon.GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
72
- parameterBuilder.addClientInfo();
73
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
74
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
75
- parameterBuilder.addThrottling();
76
- if (this.serverTelemetryManager) {
77
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
78
- }
79
- const correlationId = request.correlationId ||
80
- this.config.cryptoInterface.createNewGuid();
81
- parameterBuilder.addCorrelationId(correlationId);
82
- if (this.config.clientCredentials.clientSecret) {
83
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
84
- }
85
- const clientAssertion = this.config.clientCredentials.clientAssertion;
86
- if (clientAssertion) {
87
- parameterBuilder.addClientAssertion(await msalCommon.getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
88
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
89
- }
90
- if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
91
- (this.config.authOptions.clientCapabilities &&
92
- this.config.authOptions.clientCapabilities.length > 0)) {
93
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
94
- }
95
- if (this.config.systemOptions.preventCorsPreflight &&
96
- request.username) {
97
- parameterBuilder.addCcsUpn(request.username);
98
- }
99
- return parameterBuilder.createQueryString();
100
- }
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * Oauth2.0 Password grant client
15
+ * Note: We are only supporting public clients for password grant and for purely testing purposes
16
+ */
17
+ class UsernamePasswordClient extends msalCommon.BaseClient {
18
+ constructor(configuration) {
19
+ super(configuration);
20
+ }
21
+ /**
22
+ * API to acquire a token by passing the username and password to the service in exchage of credentials
23
+ * password_grant
24
+ * @param request
25
+ */
26
+ async acquireToken(request) {
27
+ this.logger.info("in acquireToken call in username-password client");
28
+ const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
29
+ const response = await this.executeTokenRequest(this.authority, request);
30
+ const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
31
+ // Validate response. This function throws a server error if an error is returned by the server.
32
+ responseHandler.validateTokenResponse(response.body);
33
+ const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
34
+ return tokenResponse;
35
+ }
36
+ /**
37
+ * Executes POST request to token endpoint
38
+ * @param authority
39
+ * @param request
40
+ */
41
+ async executeTokenRequest(authority, request) {
42
+ const queryParametersString = this.createTokenQueryParameters(request);
43
+ const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
44
+ const requestBody = await this.createTokenRequestBody(request);
45
+ const headers = this.createTokenRequestHeaders({
46
+ credential: request.username,
47
+ type: msalCommon.CcsCredentialType.UPN,
48
+ });
49
+ const thumbprint = {
50
+ clientId: this.config.authOptions.clientId,
51
+ authority: authority.canonicalAuthority,
52
+ scopes: request.scopes,
53
+ claims: request.claims,
54
+ authenticationScheme: request.authenticationScheme,
55
+ resourceRequestMethod: request.resourceRequestMethod,
56
+ resourceRequestUri: request.resourceRequestUri,
57
+ shrClaims: request.shrClaims,
58
+ sshKid: request.sshKid,
59
+ };
60
+ return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
61
+ }
62
+ /**
63
+ * Generates a map for all the params to be sent to the service
64
+ * @param request
65
+ */
66
+ async createTokenRequestBody(request) {
67
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
68
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
69
+ parameterBuilder.addUsername(request.username);
70
+ parameterBuilder.addPassword(request.password);
71
+ parameterBuilder.addScopes(request.scopes);
72
+ parameterBuilder.addResponseTypeForTokenAndIdToken();
73
+ parameterBuilder.addGrantType(msalCommon.GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
74
+ parameterBuilder.addClientInfo();
75
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
76
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
77
+ parameterBuilder.addThrottling();
78
+ if (this.serverTelemetryManager) {
79
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
80
+ }
81
+ const correlationId = request.correlationId ||
82
+ this.config.cryptoInterface.createNewGuid();
83
+ parameterBuilder.addCorrelationId(correlationId);
84
+ if (this.config.clientCredentials.clientSecret) {
85
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
86
+ }
87
+ const clientAssertion = this.config.clientCredentials.clientAssertion;
88
+ if (clientAssertion) {
89
+ parameterBuilder.addClientAssertion(await msalCommon.getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
90
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
91
+ }
92
+ if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
93
+ (this.config.authOptions.clientCapabilities &&
94
+ this.config.authOptions.clientCapabilities.length > 0)) {
95
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
96
+ }
97
+ if (this.config.systemOptions.preventCorsPreflight &&
98
+ request.username) {
99
+ parameterBuilder.addCcsUpn(request.username);
100
+ }
101
+ return parameterBuilder.createQueryString();
102
+ }
101
103
  }
102
104
 
103
105
  exports.UsernamePasswordClient = UsernamePasswordClient;
@@ -1 +1 @@
1
- {"version":3,"file":"UsernamePasswordClient.cjs","sources":["../../src/client/UsernamePasswordClient.ts"],"sourcesContent":[null],"names":["BaseClient","TimeUtils","ResponseHandler","UrlString","CcsCredentialType","RequestParameterBuilder","GrantType","getClientAssertion","StringUtils"],"mappings":";;;;;;AAAA;;;AAGG;AAsBH;;;AAGG;AACG,MAAO,sBAAuB,SAAQA,qBAAU,CAAA;AAClD,IAAA,WAAA,CAAY,aAAkC,EAAA;QAC1C,KAAK,CAAC,aAAa,CAAC,CAAC;KACxB;AAED;;;;AAIG;IACH,MAAM,YAAY,CACd,OAAsC,EAAA;AAEtC,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;AAErE,QAAA,MAAM,YAAY,GAAGC,oBAAS,CAAC,UAAU,EAAE,CAAC;AAC5C,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAC3C,IAAI,CAAC,SAAS,EACd,OAAO,CACV,CAAC;AAEF,QAAA,MAAM,eAAe,GAAG,IAAIC,0BAAe,CACvC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAChC,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAC7B,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAChC,CAAC;;AAGF,QAAA,eAAe,CAAC,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACrD,QAAA,MAAM,aAAa,GAAG,eAAe,CAAC,yBAAyB,CAC3D,QAAQ,CAAC,IAAI,EACb,IAAI,CAAC,SAAS,EACd,YAAY,EACZ,OAAO,CACV,CAAC;AAEF,QAAA,OAAO,aAAa,CAAC;KACxB;AAED;;;;AAIG;AACK,IAAA,MAAM,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,EAChC,OAAO,CAAC,kBAAkB,CAC7B,CACJ,CAAC;AACF,YAAA,gBAAgB,CAAC,sBAAsB,CACnC,eAAe,CAAC,aAAa,CAChC,CAAC;AACL,SAAA;QAED,IACI,CAACC,sBAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;AACvC,aAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB;gBACvC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC,EAC5D;AACE,YAAA,gBAAgB,CAAC,SAAS,CACtB,OAAO,CAAC,MAAM,EACd,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAC7C,CAAC;AACL,SAAA;AAED,QAAA,IACI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,oBAAoB;YAC9C,OAAO,CAAC,QAAQ,EAClB;AACE,YAAA,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChD,SAAA;AAED,QAAA,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C;AACJ;;;;"}
1
+ {"version":3,"file":"UsernamePasswordClient.cjs","sources":["../../src/client/UsernamePasswordClient.ts"],"sourcesContent":[null],"names":["BaseClient","TimeUtils","ResponseHandler","UrlString","CcsCredentialType","RequestParameterBuilder","GrantType","getClientAssertion","StringUtils"],"mappings":";;;;;;;;AAAA;;;AAGG;AAsBH;;;AAGG;AACG,MAAO,sBAAuB,SAAQA,qBAAU,CAAA;AAClD,IAAA,WAAA,CAAY,aAAkC,EAAA;QAC1C,KAAK,CAAC,aAAa,CAAC,CAAC;KACxB;AAED;;;;AAIG;IACH,MAAM,YAAY,CACd,OAAsC,EAAA;AAEtC,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;AAErE,QAAA,MAAM,YAAY,GAAGC,oBAAS,CAAC,UAAU,EAAE,CAAC;AAC5C,Q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C,QAAQ,CAAC,CAAC;AAChD,SAAA;AAED,QAAA,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C;AACJ;;;;"}
@@ -1,26 +1,26 @@
1
- import { AuthenticationResult, BaseClient, ClientConfiguration, CommonUsernamePasswordRequest } from "@azure/msal-common";
2
- /**
3
- * Oauth2.0 Password grant client
4
- * Note: We are only supporting public clients for password grant and for purely testing purposes
5
- */
6
- export declare class UsernamePasswordClient extends BaseClient {
7
- constructor(configuration: ClientConfiguration);
8
- /**
9
- * API to acquire a token by passing the username and password to the service in exchage of credentials
10
- * password_grant
11
- * @param request
12
- */
13
- acquireToken(request: CommonUsernamePasswordRequest): Promise<AuthenticationResult | null>;
14
- /**
15
- * Executes POST request to token endpoint
16
- * @param authority
17
- * @param request
18
- */
19
- private executeTokenRequest;
20
- /**
21
- * Generates a map for all the params to be sent to the service
22
- * @param request
23
- */
24
- private createTokenRequestBody;
25
- }
1
+ import { AuthenticationResult, BaseClient, ClientConfiguration, CommonUsernamePasswordRequest } from "@azure/msal-common";
2
+ /**
3
+ * Oauth2.0 Password grant client
4
+ * Note: We are only supporting public clients for password grant and for purely testing purposes
5
+ */
6
+ export declare class UsernamePasswordClient extends BaseClient {
7
+ constructor(configuration: ClientConfiguration);
8
+ /**
9
+ * API to acquire a token by passing the username and password to the service in exchage of credentials
10
+ * password_grant
11
+ * @param request
12
+ */
13
+ acquireToken(request: CommonUsernamePasswordRequest): Promise<AuthenticationResult | null>;
14
+ /**
15
+ * Executes POST request to token endpoint
16
+ * @param authority
17
+ * @param request
18
+ */
19
+ private executeTokenRequest;
20
+ /**
21
+ * Generates a map for all the params to be sent to the service
22
+ * @param request
23
+ */
24
+ private createTokenRequestBody;
25
+ }
26
26
  //# sourceMappingURL=UsernamePasswordClient.d.ts.map
@@ -1,101 +1,101 @@
1
- /*! @azure/msal-node v2.11.1 2024-07-16 */
1
+ /*! @azure/msal-node v2.13.0 2024-08-13 */
2
2
  'use strict';
3
3
  import { BaseClient, TimeUtils, ResponseHandler, UrlString, CcsCredentialType, RequestParameterBuilder, GrantType, getClientAssertion, StringUtils } from '@azure/msal-common';
4
4
 
5
- /*
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- /**
10
- * Oauth2.0 Password grant client
11
- * Note: We are only supporting public clients for password grant and for purely testing purposes
12
- */
13
- class UsernamePasswordClient extends BaseClient {
14
- constructor(configuration) {
15
- super(configuration);
16
- }
17
- /**
18
- * API to acquire a token by passing the username and password to the service in exchage of credentials
19
- * password_grant
20
- * @param request
21
- */
22
- async acquireToken(request) {
23
- this.logger.info("in acquireToken call in username-password client");
24
- const reqTimestamp = TimeUtils.nowSeconds();
25
- const response = await this.executeTokenRequest(this.authority, request);
26
- const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
27
- // Validate response. This function throws a server error if an error is returned by the server.
28
- responseHandler.validateTokenResponse(response.body);
29
- const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
30
- return tokenResponse;
31
- }
32
- /**
33
- * Executes POST request to token endpoint
34
- * @param authority
35
- * @param request
36
- */
37
- async executeTokenRequest(authority, request) {
38
- const queryParametersString = this.createTokenQueryParameters(request);
39
- const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
40
- const requestBody = await this.createTokenRequestBody(request);
41
- const headers = this.createTokenRequestHeaders({
42
- credential: request.username,
43
- type: CcsCredentialType.UPN,
44
- });
45
- const thumbprint = {
46
- clientId: this.config.authOptions.clientId,
47
- authority: authority.canonicalAuthority,
48
- scopes: request.scopes,
49
- claims: request.claims,
50
- authenticationScheme: request.authenticationScheme,
51
- resourceRequestMethod: request.resourceRequestMethod,
52
- resourceRequestUri: request.resourceRequestUri,
53
- shrClaims: request.shrClaims,
54
- sshKid: request.sshKid,
55
- };
56
- return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
57
- }
58
- /**
59
- * Generates a map for all the params to be sent to the service
60
- * @param request
61
- */
62
- async createTokenRequestBody(request) {
63
- const parameterBuilder = new RequestParameterBuilder();
64
- parameterBuilder.addClientId(this.config.authOptions.clientId);
65
- parameterBuilder.addUsername(request.username);
66
- parameterBuilder.addPassword(request.password);
67
- parameterBuilder.addScopes(request.scopes);
68
- parameterBuilder.addResponseTypeForTokenAndIdToken();
69
- parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
70
- parameterBuilder.addClientInfo();
71
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
72
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
73
- parameterBuilder.addThrottling();
74
- if (this.serverTelemetryManager) {
75
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
76
- }
77
- const correlationId = request.correlationId ||
78
- this.config.cryptoInterface.createNewGuid();
79
- parameterBuilder.addCorrelationId(correlationId);
80
- if (this.config.clientCredentials.clientSecret) {
81
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
82
- }
83
- const clientAssertion = this.config.clientCredentials.clientAssertion;
84
- if (clientAssertion) {
85
- parameterBuilder.addClientAssertion(await getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
86
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
87
- }
88
- if (!StringUtils.isEmptyObj(request.claims) ||
89
- (this.config.authOptions.clientCapabilities &&
90
- this.config.authOptions.clientCapabilities.length > 0)) {
91
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
92
- }
93
- if (this.config.systemOptions.preventCorsPreflight &&
94
- request.username) {
95
- parameterBuilder.addCcsUpn(request.username);
96
- }
97
- return parameterBuilder.createQueryString();
98
- }
5
+ /*
6
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7
+ * Licensed under the MIT License.
8
+ */
9
+ /**
10
+ * Oauth2.0 Password grant client
11
+ * Note: We are only supporting public clients for password grant and for purely testing purposes
12
+ */
13
+ class UsernamePasswordClient extends BaseClient {
14
+ constructor(configuration) {
15
+ super(configuration);
16
+ }
17
+ /**
18
+ * API to acquire a token by passing the username and password to the service in exchage of credentials
19
+ * password_grant
20
+ * @param request
21
+ */
22
+ async acquireToken(request) {
23
+ this.logger.info("in acquireToken call in username-password client");
24
+ const reqTimestamp = TimeUtils.nowSeconds();
25
+ const response = await this.executeTokenRequest(this.authority, request);
26
+ const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
27
+ // Validate response. This function throws a server error if an error is returned by the server.
28
+ responseHandler.validateTokenResponse(response.body);
29
+ const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
30
+ return tokenResponse;
31
+ }
32
+ /**
33
+ * Executes POST request to token endpoint
34
+ * @param authority
35
+ * @param request
36
+ */
37
+ async executeTokenRequest(authority, request) {
38
+ const queryParametersString = this.createTokenQueryParameters(request);
39
+ const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
40
+ const requestBody = await this.createTokenRequestBody(request);
41
+ const headers = this.createTokenRequestHeaders({
42
+ credential: request.username,
43
+ type: CcsCredentialType.UPN,
44
+ });
45
+ const thumbprint = {
46
+ clientId: this.config.authOptions.clientId,
47
+ authority: authority.canonicalAuthority,
48
+ scopes: request.scopes,
49
+ claims: request.claims,
50
+ authenticationScheme: request.authenticationScheme,
51
+ resourceRequestMethod: request.resourceRequestMethod,
52
+ resourceRequestUri: request.resourceRequestUri,
53
+ shrClaims: request.shrClaims,
54
+ sshKid: request.sshKid,
55
+ };
56
+ return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
57
+ }
58
+ /**
59
+ * Generates a map for all the params to be sent to the service
60
+ * @param request
61
+ */
62
+ async createTokenRequestBody(request) {
63
+ const parameterBuilder = new RequestParameterBuilder();
64
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
65
+ parameterBuilder.addUsername(request.username);
66
+ parameterBuilder.addPassword(request.password);
67
+ parameterBuilder.addScopes(request.scopes);
68
+ parameterBuilder.addResponseTypeForTokenAndIdToken();
69
+ parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
70
+ parameterBuilder.addClientInfo();
71
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
72
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
73
+ parameterBuilder.addThrottling();
74
+ if (this.serverTelemetryManager) {
75
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
76
+ }
77
+ const correlationId = request.correlationId ||
78
+ this.config.cryptoInterface.createNewGuid();
79
+ parameterBuilder.addCorrelationId(correlationId);
80
+ if (this.config.clientCredentials.clientSecret) {
81
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
82
+ }
83
+ const clientAssertion = this.config.clientCredentials.clientAssertion;
84
+ if (clientAssertion) {
85
+ parameterBuilder.addClientAssertion(await getClientAssertion(clientAssertion.assertion, this.config.authOptions.clientId, request.resourceRequestUri));
86
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
87
+ }
88
+ if (!StringUtils.isEmptyObj(request.claims) ||
89
+ (this.config.authOptions.clientCapabilities &&
90
+ this.config.authOptions.clientCapabilities.length > 0)) {
91
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
92
+ }
93
+ if (this.config.systemOptions.preventCorsPreflight &&
94
+ request.username) {
95
+ parameterBuilder.addCcsUpn(request.username);
96
+ }
97
+ return parameterBuilder.createQueryString();
98
+ }
99
99
  }
100
100
 
101
101
  export { UsernamePasswordClient };