@azure/msal-node 2.7.0-alpha.0 → 2.7.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 (225) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +423 -423
  3. package/dist/cache/NodeStorage.cjs.map +1 -1
  4. package/dist/cache/NodeStorage.d.ts +193 -193
  5. package/dist/cache/NodeStorage.d.ts.map +1 -1
  6. package/dist/cache/NodeStorage.mjs +424 -424
  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 +167 -170
  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.d.ts.map +1 -1
  20. package/dist/cache/serializer/Deserializer.mjs +168 -171
  21. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  22. package/dist/cache/serializer/Serializer.cjs +137 -137
  23. package/dist/cache/serializer/Serializer.d.ts +39 -39
  24. package/dist/cache/serializer/Serializer.mjs +137 -137
  25. package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
  26. package/dist/client/ClientApplication.cjs +333 -333
  27. package/dist/client/ClientApplication.cjs.map +1 -1
  28. package/dist/client/ClientApplication.d.ts +142 -142
  29. package/dist/client/ClientApplication.d.ts.map +1 -1
  30. package/dist/client/ClientApplication.mjs +333 -333
  31. package/dist/client/ClientApplication.mjs.map +1 -1
  32. package/dist/client/ClientAssertion.cjs +116 -116
  33. package/dist/client/ClientAssertion.d.ts +46 -46
  34. package/dist/client/ClientAssertion.mjs +116 -116
  35. package/dist/client/ClientCredentialClient.cjs +194 -194
  36. package/dist/client/ClientCredentialClient.d.ts +33 -33
  37. package/dist/client/ClientCredentialClient.mjs +194 -194
  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 +79 -78
  47. package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
  48. package/dist/client/ManagedIdentityApplication.d.ts +23 -23
  49. package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
  50. package/dist/client/ManagedIdentityApplication.mjs +79 -78
  51. package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
  52. package/dist/client/ManagedIdentityClient.cjs +40 -36
  53. package/dist/client/ManagedIdentityClient.cjs.map +1 -1
  54. package/dist/client/ManagedIdentityClient.d.ts +19 -24
  55. package/dist/client/ManagedIdentityClient.d.ts.map +1 -1
  56. package/dist/client/ManagedIdentityClient.mjs +40 -36
  57. package/dist/client/ManagedIdentityClient.mjs.map +1 -1
  58. package/dist/client/ManagedIdentitySources/AppService.cjs +42 -69
  59. package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
  60. package/dist/client/ManagedIdentitySources/AppService.d.ts +16 -16
  61. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  62. package/dist/client/ManagedIdentitySources/AppService.mjs +43 -70
  63. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
  64. package/dist/client/ManagedIdentitySources/AzureArc.cjs +81 -92
  65. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  66. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +18 -18
  67. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  68. package/dist/client/ManagedIdentitySources/AzureArc.mjs +84 -95
  69. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  70. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +112 -77
  71. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
  72. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -18
  73. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  74. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +114 -80
  75. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  76. package/dist/client/ManagedIdentitySources/CloudShell.cjs +47 -0
  77. package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -0
  78. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +15 -6
  79. package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  80. package/dist/client/ManagedIdentitySources/CloudShell.mjs +45 -0
  81. package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -0
  82. package/dist/client/ManagedIdentitySources/Imds.cjs +43 -52
  83. package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
  84. package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
  85. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  86. package/dist/client/ManagedIdentitySources/Imds.mjs +44 -53
  87. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
  88. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +61 -0
  89. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -0
  90. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +16 -6
  91. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  92. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +59 -0
  93. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -0
  94. package/dist/client/OnBehalfOfClient.cjs +202 -202
  95. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  96. package/dist/client/OnBehalfOfClient.mjs +202 -202
  97. package/dist/client/PublicClientApplication.cjs +229 -229
  98. package/dist/client/PublicClientApplication.d.ts +71 -71
  99. package/dist/client/PublicClientApplication.mjs +229 -229
  100. package/dist/client/UsernamePasswordClient.cjs +95 -95
  101. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  102. package/dist/client/UsernamePasswordClient.mjs +95 -95
  103. package/dist/config/Configuration.cjs +102 -86
  104. package/dist/config/Configuration.cjs.map +1 -1
  105. package/dist/config/Configuration.d.ts +123 -122
  106. package/dist/config/Configuration.d.ts.map +1 -1
  107. package/dist/config/Configuration.mjs +102 -86
  108. package/dist/config/Configuration.mjs.map +1 -1
  109. package/dist/config/ManagedIdentityId.cjs +48 -48
  110. package/dist/config/ManagedIdentityId.d.ts +11 -11
  111. package/dist/config/ManagedIdentityId.mjs +48 -48
  112. package/dist/config/ManagedIdentityRequestParameters.cjs +28 -29
  113. package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
  114. package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
  115. package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -1
  116. package/dist/config/ManagedIdentityRequestParameters.mjs +28 -29
  117. package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
  118. package/dist/crypto/CryptoProvider.cjs +75 -75
  119. package/dist/crypto/CryptoProvider.d.ts +52 -52
  120. package/dist/crypto/CryptoProvider.mjs +75 -75
  121. package/dist/crypto/GuidGenerator.cjs +22 -22
  122. package/dist/crypto/GuidGenerator.d.ts +14 -14
  123. package/dist/crypto/GuidGenerator.mjs +22 -22
  124. package/dist/crypto/HashUtils.cjs +13 -13
  125. package/dist/crypto/HashUtils.d.ts +8 -8
  126. package/dist/crypto/HashUtils.mjs +13 -13
  127. package/dist/crypto/PkceGenerator.cjs +49 -49
  128. package/dist/crypto/PkceGenerator.d.ts +22 -22
  129. package/dist/crypto/PkceGenerator.mjs +49 -49
  130. package/dist/error/ManagedIdentityError.cjs +39 -28
  131. package/dist/error/ManagedIdentityError.cjs.map +1 -1
  132. package/dist/error/ManagedIdentityError.d.ts +27 -21
  133. package/dist/error/ManagedIdentityError.d.ts.map +1 -1
  134. package/dist/error/ManagedIdentityError.mjs +40 -29
  135. package/dist/error/ManagedIdentityError.mjs.map +1 -1
  136. package/dist/error/ManagedIdentityErrorCodes.cjs +27 -14
  137. package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
  138. package/dist/error/ManagedIdentityErrorCodes.d.ts +19 -9
  139. package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
  140. package/dist/error/ManagedIdentityErrorCodes.mjs +24 -14
  141. package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
  142. package/dist/error/NodeAuthError.cjs +85 -85
  143. package/dist/error/NodeAuthError.d.ts +65 -65
  144. package/dist/error/NodeAuthError.mjs +85 -85
  145. package/dist/index.cjs +1 -1
  146. package/dist/index.d.ts +44 -44
  147. package/dist/index.mjs +1 -1
  148. package/dist/internals.cjs +8 -8
  149. package/dist/internals.d.ts +6 -6
  150. package/dist/internals.mjs +8 -8
  151. package/dist/network/HttpClient.cjs +283 -283
  152. package/dist/network/HttpClient.cjs.map +1 -1
  153. package/dist/network/HttpClient.d.ts +25 -26
  154. package/dist/network/HttpClient.d.ts.map +1 -1
  155. package/dist/network/HttpClient.mjs +283 -283
  156. package/dist/network/HttpClient.mjs.map +1 -1
  157. package/dist/network/HttpClientWithRetries.cjs +44 -0
  158. package/dist/network/HttpClientWithRetries.cjs.map +1 -0
  159. package/dist/network/HttpClientWithRetries.d.ts +12 -0
  160. package/dist/network/HttpClientWithRetries.d.ts.map +1 -0
  161. package/dist/network/HttpClientWithRetries.mjs +42 -0
  162. package/dist/network/HttpClientWithRetries.mjs.map +1 -0
  163. package/dist/network/ILoopbackClient.d.ts +10 -10
  164. package/dist/network/LoopbackClient.cjs +77 -77
  165. package/dist/network/LoopbackClient.d.ts +21 -21
  166. package/dist/network/LoopbackClient.mjs +77 -77
  167. package/dist/packageMetadata.cjs +4 -4
  168. package/dist/packageMetadata.d.ts +2 -2
  169. package/dist/packageMetadata.d.ts.map +1 -1
  170. package/dist/packageMetadata.mjs +4 -4
  171. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  172. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  173. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  174. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  175. package/dist/request/InteractiveRequest.d.ts +22 -22
  176. package/dist/request/ManagedIdentityRequest.d.ts +8 -8
  177. package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
  178. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  179. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  180. package/dist/request/SignOutRequest.d.ts +5 -5
  181. package/dist/request/SilentFlowRequest.d.ts +16 -16
  182. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  183. package/dist/response/ManagedIdentityTokenResponse.d.ts +24 -24
  184. package/dist/retry/IHttpRetryPolicy.d.ts +6 -0
  185. package/dist/retry/IHttpRetryPolicy.d.ts.map +1 -0
  186. package/dist/retry/LinearRetryPolicy.cjs +47 -0
  187. package/dist/retry/LinearRetryPolicy.cjs.map +1 -0
  188. package/dist/retry/LinearRetryPolicy.d.ts +12 -0
  189. package/dist/retry/LinearRetryPolicy.d.ts.map +1 -0
  190. package/dist/retry/LinearRetryPolicy.mjs +45 -0
  191. package/dist/retry/LinearRetryPolicy.mjs.map +1 -0
  192. package/dist/utils/Constants.cjs +141 -103
  193. package/dist/utils/Constants.cjs.map +1 -1
  194. package/dist/utils/Constants.d.ts +131 -106
  195. package/dist/utils/Constants.d.ts.map +1 -1
  196. package/dist/utils/Constants.mjs +133 -100
  197. package/dist/utils/Constants.mjs.map +1 -1
  198. package/dist/utils/EncodingUtils.cjs +44 -44
  199. package/dist/utils/EncodingUtils.d.ts +26 -26
  200. package/dist/utils/EncodingUtils.mjs +44 -44
  201. package/dist/utils/NetworkUtils.cjs +38 -38
  202. package/dist/utils/NetworkUtils.d.ts +5 -5
  203. package/dist/utils/NetworkUtils.mjs +38 -38
  204. package/package.json +5 -5
  205. package/src/cache/NodeStorage.ts +4 -9
  206. package/src/cache/serializer/Deserializer.ts +1 -5
  207. package/src/client/ClientApplication.ts +5 -4
  208. package/src/client/ManagedIdentityApplication.ts +3 -3
  209. package/src/client/ManagedIdentityClient.ts +23 -11
  210. package/src/client/ManagedIdentitySources/AppService.ts +68 -97
  211. package/src/client/ManagedIdentitySources/AzureArc.ts +59 -68
  212. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +70 -2
  213. package/src/client/ManagedIdentitySources/CloudShell.ts +93 -8
  214. package/src/client/ManagedIdentitySources/Imds.ts +54 -40
  215. package/src/client/ManagedIdentitySources/ServiceFabric.ts +126 -5
  216. package/src/config/Configuration.ts +44 -16
  217. package/src/config/ManagedIdentityRequestParameters.ts +1 -6
  218. package/src/error/ManagedIdentityError.ts +15 -2
  219. package/src/error/ManagedIdentityErrorCodes.ts +19 -0
  220. package/src/network/HttpClient.ts +6 -11
  221. package/src/network/HttpClientWithRetries.ts +80 -0
  222. package/src/packageMetadata.ts +1 -1
  223. package/src/retry/IHttpRetryPolicy.ts +18 -0
  224. package/src/retry/LinearRetryPolicy.ts +71 -0
  225. package/src/utils/Constants.ts +43 -7
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.7.0-alpha.0 2023-12-15 */
1
+ /*! @azure/msal-node v2.7.0 2024-04-11 */
2
2
  'use strict';
3
3
  import { ClientApplication } from './ClientApplication.mjs';
4
4
  import { ClientAssertion } from './ClientAssertion.mjs';
@@ -7,168 +7,168 @@ import { OIDC_DEFAULT_SCOPES, UrlString, AADAuthorityConstants, createClientAuth
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 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 await 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 await 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
- }
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 await 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 await 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
+ }
172
172
  }
173
173
 
174
174
  export { ConfidentialClientApplication };