@azure/msal-node 2.0.2 → 2.2.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 (218) hide show
  1. package/README.md +3 -1
  2. package/dist/cache/ITokenCache.d.ts +15 -15
  3. package/dist/cache/NodeStorage.cjs +401 -401
  4. package/dist/cache/NodeStorage.cjs.map +1 -1
  5. package/dist/cache/NodeStorage.d.ts +182 -182
  6. package/dist/cache/NodeStorage.d.ts.map +1 -1
  7. package/dist/cache/NodeStorage.mjs +401 -401
  8. package/dist/cache/NodeStorage.mjs.map +1 -1
  9. package/dist/cache/TokenCache.cjs +265 -269
  10. package/dist/cache/TokenCache.cjs.map +1 -1
  11. package/dist/cache/TokenCache.d.ts +90 -90
  12. package/dist/cache/TokenCache.d.ts.map +1 -1
  13. package/dist/cache/TokenCache.mjs +266 -270
  14. package/dist/cache/TokenCache.mjs.map +1 -1
  15. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  16. package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
  17. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  18. package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
  19. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  20. package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
  21. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  22. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  23. package/dist/cache/serializer/Deserializer.cjs +173 -175
  24. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  25. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  26. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  27. package/dist/cache/serializer/Deserializer.mjs +174 -176
  28. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  29. package/dist/cache/serializer/Serializer.cjs +134 -134
  30. package/dist/cache/serializer/Serializer.cjs.map +1 -1
  31. package/dist/cache/serializer/Serializer.d.ts +39 -39
  32. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  33. package/dist/cache/serializer/Serializer.mjs +134 -134
  34. package/dist/cache/serializer/Serializer.mjs.map +1 -1
  35. package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
  36. package/dist/client/ClientApplication.cjs +333 -333
  37. package/dist/client/ClientApplication.cjs.map +1 -1
  38. package/dist/client/ClientApplication.d.ts +142 -142
  39. package/dist/client/ClientApplication.d.ts.map +1 -1
  40. package/dist/client/ClientApplication.mjs +334 -334
  41. package/dist/client/ClientApplication.mjs.map +1 -1
  42. package/dist/client/ClientAssertion.cjs +116 -116
  43. package/dist/client/ClientAssertion.cjs.map +1 -1
  44. package/dist/client/ClientAssertion.d.ts +46 -46
  45. package/dist/client/ClientAssertion.d.ts.map +1 -1
  46. package/dist/client/ClientAssertion.mjs +117 -117
  47. package/dist/client/ClientAssertion.mjs.map +1 -1
  48. package/dist/client/ClientCredentialClient.cjs +189 -168
  49. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  50. package/dist/client/ClientCredentialClient.d.ts +33 -33
  51. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  52. package/dist/client/ClientCredentialClient.mjs +190 -169
  53. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  54. package/dist/client/ConfidentialClientApplication.cjs +163 -164
  55. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  56. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  57. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  58. package/dist/client/ConfidentialClientApplication.mjs +164 -165
  59. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  60. package/dist/client/DeviceCodeClient.cjs +207 -207
  61. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  62. package/dist/client/DeviceCodeClient.d.ts +53 -53
  63. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  64. package/dist/client/DeviceCodeClient.mjs +208 -208
  65. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  66. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  67. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  68. package/dist/client/IPublicClientApplication.d.ts +42 -42
  69. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  70. package/dist/client/OnBehalfOfClient.cjs +203 -204
  71. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  72. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  73. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  74. package/dist/client/OnBehalfOfClient.mjs +204 -205
  75. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  76. package/dist/client/PublicClientApplication.cjs +229 -175
  77. package/dist/client/PublicClientApplication.cjs.map +1 -1
  78. package/dist/client/PublicClientApplication.d.ts +71 -65
  79. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  80. package/dist/client/PublicClientApplication.mjs +232 -178
  81. package/dist/client/PublicClientApplication.mjs.map +1 -1
  82. package/dist/client/UsernamePasswordClient.cjs +95 -95
  83. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  84. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  85. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  86. package/dist/client/UsernamePasswordClient.mjs +95 -95
  87. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  88. package/dist/config/Configuration.cjs +72 -72
  89. package/dist/config/Configuration.cjs.map +1 -1
  90. package/dist/config/Configuration.d.ts +107 -107
  91. package/dist/config/Configuration.mjs +72 -72
  92. package/dist/config/Configuration.mjs.map +1 -1
  93. package/dist/crypto/CryptoProvider.cjs +75 -75
  94. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  95. package/dist/crypto/CryptoProvider.d.ts +52 -52
  96. package/dist/crypto/CryptoProvider.mjs +75 -75
  97. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  98. package/dist/crypto/GuidGenerator.cjs +22 -22
  99. package/dist/crypto/GuidGenerator.cjs.map +1 -1
  100. package/dist/crypto/GuidGenerator.d.ts +14 -14
  101. package/dist/crypto/GuidGenerator.mjs +22 -22
  102. package/dist/crypto/GuidGenerator.mjs.map +1 -1
  103. package/dist/crypto/HashUtils.cjs +13 -13
  104. package/dist/crypto/HashUtils.cjs.map +1 -1
  105. package/dist/crypto/HashUtils.d.ts +8 -8
  106. package/dist/crypto/HashUtils.mjs +13 -13
  107. package/dist/crypto/HashUtils.mjs.map +1 -1
  108. package/dist/crypto/PkceGenerator.cjs +49 -49
  109. package/dist/crypto/PkceGenerator.cjs.map +1 -1
  110. package/dist/crypto/PkceGenerator.d.ts +22 -22
  111. package/dist/crypto/PkceGenerator.mjs +49 -49
  112. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  113. package/dist/error/NodeAuthError.cjs +85 -85
  114. package/dist/error/NodeAuthError.cjs.map +1 -1
  115. package/dist/error/NodeAuthError.d.ts +65 -65
  116. package/dist/error/NodeAuthError.mjs +85 -85
  117. package/dist/error/NodeAuthError.mjs.map +1 -1
  118. package/dist/index.cjs +17 -1
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.ts +42 -42
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.mjs +2 -2
  123. package/dist/internals.cjs +8 -8
  124. package/dist/internals.cjs.map +1 -1
  125. package/dist/internals.d.ts +6 -6
  126. package/dist/internals.d.ts.map +1 -1
  127. package/dist/internals.mjs +8 -8
  128. package/dist/internals.mjs.map +1 -1
  129. package/dist/network/HttpClient.cjs +277 -276
  130. package/dist/network/HttpClient.cjs.map +1 -1
  131. package/dist/network/HttpClient.d.ts +25 -25
  132. package/dist/network/HttpClient.d.ts.map +1 -1
  133. package/dist/network/HttpClient.mjs +278 -277
  134. package/dist/network/HttpClient.mjs.map +1 -1
  135. package/dist/network/ILoopbackClient.d.ts +10 -10
  136. package/dist/network/LoopbackClient.cjs +75 -84
  137. package/dist/network/LoopbackClient.cjs.map +1 -1
  138. package/dist/network/LoopbackClient.d.ts +21 -21
  139. package/dist/network/LoopbackClient.d.ts.map +1 -1
  140. package/dist/network/LoopbackClient.mjs +77 -86
  141. package/dist/network/LoopbackClient.mjs.map +1 -1
  142. package/dist/packageMetadata.cjs +4 -4
  143. package/dist/packageMetadata.cjs.map +1 -1
  144. package/dist/packageMetadata.d.ts +2 -2
  145. package/dist/packageMetadata.mjs +4 -4
  146. package/dist/packageMetadata.mjs.map +1 -1
  147. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  148. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  149. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  150. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  151. package/dist/request/InteractiveRequest.d.ts +22 -22
  152. package/dist/request/InteractiveRequest.d.ts.map +1 -1
  153. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  154. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  155. package/dist/request/SignOutRequest.d.ts +5 -5
  156. package/dist/request/SilentFlowRequest.d.ts +16 -16
  157. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  158. package/dist/utils/Constants.cjs +80 -90
  159. package/dist/utils/Constants.cjs.map +1 -1
  160. package/dist/utils/Constants.d.ts +86 -96
  161. package/dist/utils/Constants.d.ts.map +1 -1
  162. package/dist/utils/Constants.mjs +81 -90
  163. package/dist/utils/Constants.mjs.map +1 -1
  164. package/dist/utils/EncodingUtils.cjs +44 -44
  165. package/dist/utils/EncodingUtils.cjs.map +1 -1
  166. package/dist/utils/EncodingUtils.d.ts +26 -26
  167. package/dist/utils/EncodingUtils.mjs +44 -44
  168. package/dist/utils/EncodingUtils.mjs.map +1 -1
  169. package/dist/utils/NetworkUtils.cjs +38 -38
  170. package/dist/utils/NetworkUtils.cjs.map +1 -1
  171. package/dist/utils/NetworkUtils.d.ts +5 -5
  172. package/dist/utils/NetworkUtils.mjs +38 -38
  173. package/dist/utils/NetworkUtils.mjs.map +1 -1
  174. package/package.json +8 -5
  175. package/src/cache/ITokenCache.ts +24 -0
  176. package/src/cache/NodeStorage.ts +533 -0
  177. package/src/cache/TokenCache.ts +358 -0
  178. package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
  179. package/src/cache/distributed/ICacheClient.ts +23 -0
  180. package/src/cache/distributed/IPartitionManager.ts +35 -0
  181. package/src/cache/serializer/Deserializer.ts +218 -0
  182. package/src/cache/serializer/Serializer.ts +173 -0
  183. package/src/cache/serializer/SerializerTypes.ts +121 -0
  184. package/src/client/ClientApplication.ts +596 -0
  185. package/src/client/ClientAssertion.ts +165 -0
  186. package/src/client/ClientCredentialClient.ts +346 -0
  187. package/src/client/ConfidentialClientApplication.ts +268 -0
  188. package/src/client/DeviceCodeClient.ts +369 -0
  189. package/src/client/IConfidentialClientApplication.ts +72 -0
  190. package/src/client/IPublicClientApplication.ts +72 -0
  191. package/src/client/OnBehalfOfClient.ts +368 -0
  192. package/src/client/PublicClientApplication.ts +339 -0
  193. package/src/client/UsernamePasswordClient.ts +180 -0
  194. package/src/config/Configuration.ts +201 -0
  195. package/src/crypto/CryptoProvider.ts +98 -0
  196. package/src/crypto/GuidGenerator.ts +28 -0
  197. package/src/crypto/HashUtils.ts +17 -0
  198. package/src/crypto/PkceGenerator.ts +63 -0
  199. package/src/error/NodeAuthError.ts +117 -0
  200. package/src/index.ts +125 -0
  201. package/src/internals.ts +12 -0
  202. package/src/network/HttpClient.ts +425 -0
  203. package/src/network/ILoopbackClient.ts +19 -0
  204. package/src/network/LoopbackClient.ts +110 -0
  205. package/src/packageMetadata.ts +3 -0
  206. package/src/request/AuthorizationCodeRequest.ts +39 -0
  207. package/src/request/AuthorizationUrlRequest.ts +50 -0
  208. package/src/request/ClientCredentialRequest.ts +29 -0
  209. package/src/request/DeviceCodeRequest.ts +34 -0
  210. package/src/request/InteractiveRequest.ts +39 -0
  211. package/src/request/OnBehalfOfRequest.ts +30 -0
  212. package/src/request/RefreshTokenRequest.ts +34 -0
  213. package/src/request/SignOutRequest.ts +11 -0
  214. package/src/request/SilentFlowRequest.ts +32 -0
  215. package/src/request/UsernamePasswordRequest.ts +36 -0
  216. package/src/utils/Constants.ts +103 -0
  217. package/src/utils/EncodingUtils.ts +50 -0
  218. package/src/utils/NetworkUtils.ts +49 -0
@@ -1,175 +1,174 @@
1
- /*! @azure/msal-node v2.0.2 2023-08-18 */
1
+ /*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
2
2
  'use strict';
3
3
  import { ClientApplication } from './ClientApplication.mjs';
4
4
  import { ClientAssertion } from './ClientAssertion.mjs';
5
5
  import { REGION_ENVIRONMENT_VARIABLE, ApiId, Constants as Constants$1 } from '../utils/Constants.mjs';
6
- import { OIDC_DEFAULT_SCOPES, UrlString, AADAuthorityConstants, ClientAuthError, AuthError, StringUtils, Constants } from '@azure/msal-common';
6
+ import { OIDC_DEFAULT_SCOPES, UrlString, AADAuthorityConstants, createClientAuthError, ClientAuthErrorCodes, AuthError, Constants } from '@azure/msal-common';
7
7
  import { ClientCredentialClient } from './ClientCredentialClient.mjs';
8
8
  import { OnBehalfOfClient } from './OnBehalfOfClient.mjs';
9
9
 
10
- /*
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License.
13
- */
14
- // AADAuthorityConstants
15
- /**
16
- * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
17
- * will configure application secrets, client certificates/assertions as applicable
18
- * @public
19
- */
20
- class ConfidentialClientApplication extends ClientApplication {
21
- /**
22
- * Constructor for the ConfidentialClientApplication
23
- *
24
- * Required attributes in the Configuration object 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
- * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
28
- *
29
- * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
30
- * 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).
31
- * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
32
- * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
33
- * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
34
- *
35
- * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
36
- * Full B2C functionality will be available in this library in future versions.
37
- *
38
- * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
39
- */
40
- constructor(configuration) {
41
- super(configuration);
42
- this.setClientCredential(this.config);
43
- this.appTokenProvider = undefined;
44
- }
45
- /**
46
- * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
47
- * is meant for Azure SDK to enhance Managed Identity support.
48
- *
49
- * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
50
- */
51
- SetAppTokenProvider(provider) {
52
- this.appTokenProvider = provider;
53
- }
54
- /**
55
- * Acquires tokens from the authority for the application (not for an end user).
56
- */
57
- async acquireTokenByClientCredential(request) {
58
- this.logger.info("acquireTokenByClientCredential called", request.correlationId);
59
- // If there is a client assertion present in the request, it overrides the one present in the client configuration
60
- let clientAssertion;
61
- if (request.clientAssertion) {
62
- clientAssertion = {
63
- assertion: request.clientAssertion,
64
- assertionType: Constants$1.JWT_BEARER_ASSERTION_TYPE,
65
- };
66
- }
67
- const baseRequest = await this.initializeBaseRequest(request);
68
- // valid base request should not contain oidc scopes in this grant type
69
- const validBaseRequest = {
70
- ...baseRequest,
71
- scopes: baseRequest.scopes.filter((scope) => !OIDC_DEFAULT_SCOPES.includes(scope)),
72
- };
73
- const validRequest = {
74
- ...request,
75
- ...validBaseRequest,
76
- clientAssertion,
77
- };
78
- /*
79
- * valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
80
- * example authority: "https://login.microsoftonline.com/TenantId",
81
- */
82
- const authority = new UrlString(validRequest.authority);
83
- const tenantId = authority.getUrlComponents().PathSegments[0];
84
- if (Object.values(AADAuthorityConstants).includes(tenantId)) {
85
- throw ClientAuthError.createMissingTenantIdError();
86
- }
87
- const azureRegionConfiguration = {
88
- azureRegion: validRequest.azureRegion,
89
- environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE],
90
- };
91
- const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
92
- try {
93
- const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
94
- const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
95
- this.logger.verbose("Client credential client created", validRequest.correlationId);
96
- return clientCredentialClient.acquireToken(validRequest);
97
- }
98
- catch (e) {
99
- if (e instanceof AuthError) {
100
- e.setCorrelationId(validRequest.correlationId);
101
- }
102
- serverTelemetryManager.cacheFailedRequest(e);
103
- throw e;
104
- }
105
- }
106
- /**
107
- * Acquires tokens from the authority for the application.
108
- *
109
- * Used in scenarios where the current app is a middle-tier service which was called with a token
110
- * representing an end user. The current app can use the token (oboAssertion) to request another
111
- * token to access downstream web API, on behalf of that user.
112
- *
113
- * The current middle-tier app has no user interaction to obtain consent.
114
- * See how to gain consent upfront for your middle-tier app from this article.
115
- * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
116
- */
117
- async acquireTokenOnBehalfOf(request) {
118
- this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
119
- const validRequest = {
120
- ...request,
121
- ...(await this.initializeBaseRequest(request)),
122
- };
123
- try {
124
- const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
125
- const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
126
- this.logger.verbose("On behalf of client created", validRequest.correlationId);
127
- return oboClient.acquireToken(validRequest);
128
- }
129
- catch (e) {
130
- if (e instanceof AuthError) {
131
- e.setCorrelationId(validRequest.correlationId);
132
- }
133
- throw e;
134
- }
135
- }
136
- setClientCredential(configuration) {
137
- const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
138
- const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
139
- const certificate = configuration.auth.clientCertificate || {
140
- thumbprint: Constants.EMPTY_STRING,
141
- privateKey: Constants.EMPTY_STRING,
142
- };
143
- const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) ||
144
- !StringUtils.isEmpty(certificate.privateKey);
145
- /*
146
- * If app developer configures this callback, they don't need a credential
147
- * i.e. AzureSDK can get token from Managed Identity without a cert / secret
148
- */
149
- if (this.appTokenProvider) {
150
- return;
151
- }
152
- // Check that at most one credential is set on the application
153
- if ((clientSecretNotEmpty && clientAssertionNotEmpty) ||
154
- (clientAssertionNotEmpty && certificateNotEmpty) ||
155
- (clientSecretNotEmpty && certificateNotEmpty)) {
156
- throw ClientAuthError.createInvalidCredentialError();
157
- }
158
- if (configuration.auth.clientSecret) {
159
- this.clientSecret = configuration.auth.clientSecret;
160
- return;
161
- }
162
- if (configuration.auth.clientAssertion) {
163
- this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
164
- return;
165
- }
166
- if (!certificateNotEmpty) {
167
- throw ClientAuthError.createInvalidCredentialError();
168
- }
169
- else {
170
- this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, configuration.auth.clientCertificate?.x5c);
171
- }
172
- }
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ // AADAuthorityConstants
15
+ /**
16
+ * This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
17
+ * will configure application secrets, client certificates/assertions as applicable
18
+ * @public
19
+ */
20
+ class ConfidentialClientApplication extends ClientApplication {
21
+ /**
22
+ * Constructor for the ConfidentialClientApplication
23
+ *
24
+ * Required attributes in the Configuration object 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
+ * - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
28
+ *
29
+ * In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
30
+ * 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).
31
+ * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
32
+ * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
33
+ * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
34
+ *
35
+ * In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
36
+ * Full B2C functionality will be available in this library in future versions.
37
+ *
38
+ * @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
39
+ */
40
+ constructor(configuration) {
41
+ super(configuration);
42
+ this.setClientCredential(this.config);
43
+ this.appTokenProvider = undefined;
44
+ }
45
+ /**
46
+ * This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
47
+ * is meant for Azure SDK to enhance Managed Identity support.
48
+ *
49
+ * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
50
+ */
51
+ SetAppTokenProvider(provider) {
52
+ this.appTokenProvider = provider;
53
+ }
54
+ /**
55
+ * Acquires tokens from the authority for the application (not for an end user).
56
+ */
57
+ async acquireTokenByClientCredential(request) {
58
+ this.logger.info("acquireTokenByClientCredential called", request.correlationId);
59
+ // If there is a client assertion present in the request, it overrides the one present in the client configuration
60
+ let clientAssertion;
61
+ if (request.clientAssertion) {
62
+ clientAssertion = {
63
+ assertion: request.clientAssertion,
64
+ assertionType: Constants$1.JWT_BEARER_ASSERTION_TYPE,
65
+ };
66
+ }
67
+ const baseRequest = await this.initializeBaseRequest(request);
68
+ // valid base request should not contain oidc scopes in this grant type
69
+ const validBaseRequest = {
70
+ ...baseRequest,
71
+ scopes: baseRequest.scopes.filter((scope) => !OIDC_DEFAULT_SCOPES.includes(scope)),
72
+ };
73
+ const validRequest = {
74
+ ...request,
75
+ ...validBaseRequest,
76
+ clientAssertion,
77
+ };
78
+ /*
79
+ * valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
80
+ * example authority: "https://login.microsoftonline.com/TenantId",
81
+ */
82
+ const authority = new UrlString(validRequest.authority);
83
+ const tenantId = authority.getUrlComponents().PathSegments[0];
84
+ if (Object.values(AADAuthorityConstants).includes(tenantId)) {
85
+ throw createClientAuthError(ClientAuthErrorCodes.missingTenantIdError);
86
+ }
87
+ const azureRegionConfiguration = {
88
+ azureRegion: validRequest.azureRegion,
89
+ environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE],
90
+ };
91
+ const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
92
+ try {
93
+ const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
94
+ const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
95
+ this.logger.verbose("Client credential client created", validRequest.correlationId);
96
+ return clientCredentialClient.acquireToken(validRequest);
97
+ }
98
+ catch (e) {
99
+ if (e instanceof AuthError) {
100
+ e.setCorrelationId(validRequest.correlationId);
101
+ }
102
+ serverTelemetryManager.cacheFailedRequest(e);
103
+ throw e;
104
+ }
105
+ }
106
+ /**
107
+ * Acquires tokens from the authority for the application.
108
+ *
109
+ * Used in scenarios where the current app is a middle-tier service which was called with a token
110
+ * representing an end user. The current app can use the token (oboAssertion) to request another
111
+ * token to access downstream web API, on behalf of that user.
112
+ *
113
+ * The current middle-tier app has no user interaction to obtain consent.
114
+ * See how to gain consent upfront for your middle-tier app from this article.
115
+ * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
116
+ */
117
+ async acquireTokenOnBehalfOf(request) {
118
+ this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
119
+ const validRequest = {
120
+ ...request,
121
+ ...(await this.initializeBaseRequest(request)),
122
+ };
123
+ try {
124
+ const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
125
+ const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
126
+ this.logger.verbose("On behalf of client created", validRequest.correlationId);
127
+ return oboClient.acquireToken(validRequest);
128
+ }
129
+ catch (e) {
130
+ if (e instanceof AuthError) {
131
+ e.setCorrelationId(validRequest.correlationId);
132
+ }
133
+ throw e;
134
+ }
135
+ }
136
+ setClientCredential(configuration) {
137
+ const clientSecretNotEmpty = !!configuration.auth.clientSecret;
138
+ const clientAssertionNotEmpty = !!configuration.auth.clientAssertion;
139
+ const certificate = configuration.auth.clientCertificate || {
140
+ thumbprint: Constants.EMPTY_STRING,
141
+ privateKey: Constants.EMPTY_STRING,
142
+ };
143
+ const certificateNotEmpty = !!certificate.thumbprint || !!certificate.privateKey;
144
+ /*
145
+ * If app developer configures this callback, they don't need a credential
146
+ * i.e. AzureSDK can get token from Managed Identity without a cert / secret
147
+ */
148
+ if (this.appTokenProvider) {
149
+ return;
150
+ }
151
+ // Check that at most one credential is set on the application
152
+ if ((clientSecretNotEmpty && clientAssertionNotEmpty) ||
153
+ (clientAssertionNotEmpty && certificateNotEmpty) ||
154
+ (clientSecretNotEmpty && certificateNotEmpty)) {
155
+ throw createClientAuthError(ClientAuthErrorCodes.invalidClientCredential);
156
+ }
157
+ if (configuration.auth.clientSecret) {
158
+ this.clientSecret = configuration.auth.clientSecret;
159
+ return;
160
+ }
161
+ if (configuration.auth.clientAssertion) {
162
+ this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
163
+ return;
164
+ }
165
+ if (!certificateNotEmpty) {
166
+ throw createClientAuthError(ClientAuthErrorCodes.invalidClientCredential);
167
+ }
168
+ else {
169
+ this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, configuration.auth.clientCertificate?.x5c);
170
+ }
171
+ }
173
172
  }
174
173
 
175
174
  export { ConfidentialClientApplication };
@@ -1 +1 @@
1
- {"version":3,"file":"ConfidentialClientApplication.mjs","sources":["../../src/client/ConfidentialClientApplication.ts"],"sourcesContent":[null],"names":["NodeConstants"],"mappings":";;;;;;;;;AAAA;;;AAGG;AAEH;AA8BA;;;;AAIG;AACG,MAAO,6BACT,SAAQ,iBAAiB,CAAA;AAKzB;;;;;;;;;;;;;;;;;;AAkBG;AACH,IAAA,WAAA,CAAY,aAA4B,EAAA;QACpC,KAAK,CAAC,aAAa,CAAC,CAAC;AACrB,QAAA,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACtC,QAAA,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;KACrC;AAED;;;;;AAKG;AACH,IAAA,mBAAmB,CAAC,QAA2B,EAAA;AAC3C,QAAA,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;KACpC;AAED;;AAEG;IACI,MAAM,8BAA8B,CACvC,OAAgC,EAAA;QAEhC,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,uCAAuC,EACvC,OAAO,CAAC,aAAa,CACxB,CAAC;;AAGF,QAAA,IAAI,eAAe,CAAC;QACpB,IAAI,OAAO,CAAC,eAAe,EAAE;AACzB,YAAA,eAAe,GAAG;gBACd,SAAS,EAAE,OAAO,CAAC,eAAe;gBAClC,aAAa,EAAEA,WAAa,CAAC,yBAAyB;aACzD,CAAC;AACL,SAAA;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,qBAA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CAAC,4BAA4B,EAAE,CAAC;AACxD,SAAA;AAAM,aAAA;YACH,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC,eAAe,CAClD,WAAW,CAAC,UAAU,EACtB,WAAW,CAAC,UAAU,EACtB,aAAa,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,CAC5C,CAAC;AACL,SAAA;KACJ;AACJ;;;;"}
1
+ {"version":3,"file":"ConfidentialClientApplication.mjs","sources":["../../src/client/ConfidentialClientApplication.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAOA;AACA;AAOA;AAcA;AACA;AAUA;;AAMI;;;;;;;;;;;;;;;;;;AAkBG;AACS;AAMZ;;;;;AAKG,QAAA,IAAA,CAAA,mBAAA,CAAA,IAAA,CAAA,MAAA,CAAA,CAAA;AACH,QAAA,IAAA,CAAA,gBAAoB,GAAQ,SAAE,CAAA;AAI9B,KAAA;;AAEG;;AAuFH;;;;;;;;;;AAUG,QAAA,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,uCAAA,EAAA,OAAA,CAAA,aAAA,CAAA,CAAA;;AAkCH,QAAA,IAAQ,eAAmB,CAAA;AAqD9B,QAAA,IAAA,OAAA,CAAA,eAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}