@azure/msal-node 2.1.0 → 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 (134) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +401 -401
  3. package/dist/cache/NodeStorage.d.ts +182 -182
  4. package/dist/cache/NodeStorage.mjs +401 -401
  5. package/dist/cache/TokenCache.cjs +265 -265
  6. package/dist/cache/TokenCache.d.ts +90 -90
  7. package/dist/cache/TokenCache.mjs +265 -265
  8. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  9. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  10. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  11. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  12. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  13. package/dist/cache/serializer/Deserializer.cjs +173 -173
  14. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  15. package/dist/cache/serializer/Deserializer.mjs +173 -173
  16. package/dist/cache/serializer/Serializer.cjs +134 -134
  17. package/dist/cache/serializer/Serializer.d.ts +39 -39
  18. package/dist/cache/serializer/Serializer.mjs +134 -134
  19. package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
  20. package/dist/client/ClientApplication.cjs +333 -333
  21. package/dist/client/ClientApplication.cjs.map +1 -1
  22. package/dist/client/ClientApplication.d.ts +142 -142
  23. package/dist/client/ClientApplication.d.ts.map +1 -1
  24. package/dist/client/ClientApplication.mjs +334 -334
  25. package/dist/client/ClientApplication.mjs.map +1 -1
  26. package/dist/client/ClientAssertion.cjs +116 -116
  27. package/dist/client/ClientAssertion.cjs.map +1 -1
  28. package/dist/client/ClientAssertion.d.ts +46 -46
  29. package/dist/client/ClientAssertion.d.ts.map +1 -1
  30. package/dist/client/ClientAssertion.mjs +117 -117
  31. package/dist/client/ClientAssertion.mjs.map +1 -1
  32. package/dist/client/ClientCredentialClient.cjs +189 -190
  33. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  34. package/dist/client/ClientCredentialClient.d.ts +33 -34
  35. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  36. package/dist/client/ClientCredentialClient.mjs +190 -191
  37. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  38. package/dist/client/ConfidentialClientApplication.cjs +163 -163
  39. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  40. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  41. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  42. package/dist/client/ConfidentialClientApplication.mjs +164 -164
  43. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  44. package/dist/client/DeviceCodeClient.cjs +207 -207
  45. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  46. package/dist/client/DeviceCodeClient.d.ts +53 -53
  47. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  48. package/dist/client/DeviceCodeClient.mjs +208 -208
  49. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  50. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  51. package/dist/client/IPublicClientApplication.d.ts +42 -42
  52. package/dist/client/OnBehalfOfClient.cjs +202 -202
  53. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  54. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  55. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  56. package/dist/client/OnBehalfOfClient.mjs +203 -203
  57. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  58. package/dist/client/PublicClientApplication.cjs +229 -182
  59. package/dist/client/PublicClientApplication.cjs.map +1 -1
  60. package/dist/client/PublicClientApplication.d.ts +71 -65
  61. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  62. package/dist/client/PublicClientApplication.mjs +231 -184
  63. package/dist/client/PublicClientApplication.mjs.map +1 -1
  64. package/dist/client/UsernamePasswordClient.cjs +95 -95
  65. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  66. package/dist/client/UsernamePasswordClient.mjs +95 -95
  67. package/dist/config/Configuration.cjs +72 -72
  68. package/dist/config/Configuration.d.ts +107 -107
  69. package/dist/config/Configuration.mjs +72 -72
  70. package/dist/crypto/CryptoProvider.cjs +75 -75
  71. package/dist/crypto/CryptoProvider.d.ts +52 -52
  72. package/dist/crypto/CryptoProvider.mjs +75 -75
  73. package/dist/crypto/GuidGenerator.cjs +22 -22
  74. package/dist/crypto/GuidGenerator.d.ts +14 -14
  75. package/dist/crypto/GuidGenerator.mjs +22 -22
  76. package/dist/crypto/HashUtils.cjs +13 -13
  77. package/dist/crypto/HashUtils.d.ts +8 -8
  78. package/dist/crypto/HashUtils.mjs +13 -13
  79. package/dist/crypto/PkceGenerator.cjs +49 -49
  80. package/dist/crypto/PkceGenerator.d.ts +22 -22
  81. package/dist/crypto/PkceGenerator.mjs +49 -49
  82. package/dist/error/NodeAuthError.cjs +85 -85
  83. package/dist/error/NodeAuthError.d.ts +65 -65
  84. package/dist/error/NodeAuthError.mjs +85 -85
  85. package/dist/index.cjs +17 -1
  86. package/dist/index.cjs.map +1 -1
  87. package/dist/index.d.ts +42 -42
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.mjs +2 -2
  90. package/dist/internals.cjs +8 -8
  91. package/dist/internals.d.ts +6 -6
  92. package/dist/internals.mjs +8 -8
  93. package/dist/network/HttpClient.cjs +276 -276
  94. package/dist/network/HttpClient.d.ts +25 -25
  95. package/dist/network/HttpClient.mjs +276 -276
  96. package/dist/network/ILoopbackClient.d.ts +10 -10
  97. package/dist/network/LoopbackClient.cjs +75 -84
  98. package/dist/network/LoopbackClient.cjs.map +1 -1
  99. package/dist/network/LoopbackClient.d.ts +21 -21
  100. package/dist/network/LoopbackClient.d.ts.map +1 -1
  101. package/dist/network/LoopbackClient.mjs +76 -85
  102. package/dist/network/LoopbackClient.mjs.map +1 -1
  103. package/dist/packageMetadata.cjs +3 -3
  104. package/dist/packageMetadata.d.ts +2 -2
  105. package/dist/packageMetadata.mjs +3 -3
  106. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  107. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  108. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  109. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  110. package/dist/request/InteractiveRequest.d.ts +22 -22
  111. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  112. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  113. package/dist/request/SignOutRequest.d.ts +5 -5
  114. package/dist/request/SilentFlowRequest.d.ts +16 -16
  115. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  116. package/dist/utils/Constants.cjs +80 -80
  117. package/dist/utils/Constants.d.ts +86 -86
  118. package/dist/utils/Constants.mjs +80 -80
  119. package/dist/utils/EncodingUtils.cjs +44 -44
  120. package/dist/utils/EncodingUtils.d.ts +26 -26
  121. package/dist/utils/EncodingUtils.mjs +44 -44
  122. package/dist/utils/NetworkUtils.cjs +38 -38
  123. package/dist/utils/NetworkUtils.d.ts +5 -5
  124. package/dist/utils/NetworkUtils.mjs +38 -38
  125. package/package.json +2 -2
  126. package/src/client/ClientApplication.ts +3 -2
  127. package/src/client/ClientAssertion.ts +7 -2
  128. package/src/client/ClientCredentialClient.ts +32 -34
  129. package/src/client/ConfidentialClientApplication.ts +11 -4
  130. package/src/client/DeviceCodeClient.ts +16 -7
  131. package/src/client/OnBehalfOfClient.ts +11 -4
  132. package/src/client/PublicClientApplication.ts +69 -13
  133. package/src/index.ts +4 -0
  134. package/src/network/LoopbackClient.ts +17 -33
@@ -1,196 +1,195 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
2
2
  'use strict';
3
- import { BaseClient, ScopeSet, CacheOutcome, TokenCacheContext, TimeUtils, ResponseHandler, Constants, CredentialType, ClientAuthError, UrlString, RequestParameterBuilder, GrantType, StringUtils, AuthenticationScheme } from '@azure/msal-common';
3
+ import { BaseClient, ScopeSet, CacheOutcome, TokenCacheContext, TimeUtils, ResponseHandler, Constants, CredentialType, createClientAuthError, ClientAuthErrorCodes, UrlString, RequestParameterBuilder, GrantType, StringUtils, AuthenticationScheme } 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 client credential grant
11
- */
12
- class ClientCredentialClient extends BaseClient {
13
- constructor(configuration, appTokenProvider) {
14
- super(configuration);
15
- this.appTokenProvider = appTokenProvider;
16
- }
17
- /**
18
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
19
- * @param request
20
- */
21
- async acquireToken(request) {
22
- this.scopeSet = new ScopeSet(request.scopes || []);
23
- if (request.skipCache) {
24
- return await this.executeTokenRequest(request, this.authority);
25
- }
26
- const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);
27
- if (cachedAuthenticationResult) {
28
- // if the token is not expired but must be refreshed; get a new one in the background
29
- if (this.lastCacheOutcome ===
30
- CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN) {
31
- this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
32
- // return the cached token, don't wait for the result of this request
33
- const refreshAccessToken = true;
34
- await this.executeTokenRequest(request, this.authority, refreshAccessToken);
35
- }
36
- // reset the last cache outcome
37
- this.lastCacheOutcome = CacheOutcome.NO_CACHE_HIT;
38
- // otherwise, the token is not expired and does not need to be refreshed
39
- return cachedAuthenticationResult;
40
- }
41
- else {
42
- return await this.executeTokenRequest(request, this.authority);
43
- }
44
- }
45
- /**
46
- * looks up cache if the tokens are cached already
47
- */
48
- async getCachedAuthenticationResult(request) {
49
- // read the user-supplied cache into memory, if applicable
50
- let cacheContext;
51
- if (this.config.serializableCache && this.config.persistencePlugin) {
52
- cacheContext = new TokenCacheContext(this.config.serializableCache, false);
53
- await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
54
- }
55
- const cachedAccessToken = this.readAccessTokenFromCache();
56
- if (this.config.serializableCache &&
57
- this.config.persistencePlugin &&
58
- cacheContext) {
59
- await this.config.persistencePlugin.afterCacheAccess(cacheContext);
60
- }
61
- // must refresh due to non-existent access_token
62
- if (!cachedAccessToken) {
63
- this.lastCacheOutcome = CacheOutcome.NO_CACHED_ACCESS_TOKEN;
64
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
65
- return null;
66
- }
67
- // must refresh due to the expires_in value
68
- if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
69
- this.lastCacheOutcome = CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED;
70
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
71
- return null;
72
- }
73
- // must refresh (in the background) due to the refresh_in value
74
- if (cachedAccessToken.refreshOn &&
75
- TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
76
- this.lastCacheOutcome = CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN;
77
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
78
- }
79
- return await ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
80
- account: null,
81
- idToken: null,
82
- accessToken: cachedAccessToken,
83
- refreshToken: null,
84
- appMetadata: null,
85
- }, true, request);
86
- }
87
- /**
88
- * Reads access token from the cache
89
- */
90
- readAccessTokenFromCache() {
91
- const accessTokenFilter = {
92
- homeAccountId: Constants.EMPTY_STRING,
93
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
94
- credentialType: CredentialType.ACCESS_TOKEN,
95
- clientId: this.config.authOptions.clientId,
96
- realm: this.authority.tenant,
97
- target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
98
- };
99
- const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
100
- if (accessTokens.length < 1) {
101
- return null;
102
- }
103
- else if (accessTokens.length > 1) {
104
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
105
- }
106
- return accessTokens[0];
107
- }
108
- /**
109
- * Makes a network call to request the token from the service
110
- * @param request
111
- * @param authority
112
- */
113
- async executeTokenRequest(request, authority, refreshAccessToken) {
114
- let serverTokenResponse;
115
- let reqTimestamp;
116
- if (this.appTokenProvider) {
117
- this.logger.info("Using appTokenProvider extensibility.");
118
- const appTokenPropviderParameters = {
119
- correlationId: request.correlationId,
120
- tenantId: this.config.authOptions.authority.tenant,
121
- scopes: request.scopes,
122
- claims: request.claims,
123
- };
124
- reqTimestamp = TimeUtils.nowSeconds();
125
- const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
126
- serverTokenResponse = {
127
- access_token: appTokenProviderResult.accessToken,
128
- expires_in: appTokenProviderResult.expiresInSeconds,
129
- refresh_in: appTokenProviderResult.refreshInSeconds,
130
- token_type: AuthenticationScheme.BEARER,
131
- };
132
- }
133
- else {
134
- const queryParametersString = this.createTokenQueryParameters(request);
135
- const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
136
- const requestBody = this.createTokenRequestBody(request);
137
- const headers = this.createTokenRequestHeaders();
138
- const thumbprint = {
139
- clientId: this.config.authOptions.clientId,
140
- authority: request.authority,
141
- scopes: request.scopes,
142
- claims: request.claims,
143
- authenticationScheme: request.authenticationScheme,
144
- resourceRequestMethod: request.resourceRequestMethod,
145
- resourceRequestUri: request.resourceRequestUri,
146
- shrClaims: request.shrClaims,
147
- sshKid: request.sshKid,
148
- };
149
- reqTimestamp = TimeUtils.nowSeconds();
150
- const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
151
- serverTokenResponse = response.body;
152
- serverTokenResponse.status = response.status;
153
- }
154
- const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
155
- responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
156
- const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
157
- return tokenResponse;
158
- }
159
- /**
160
- * generate the request to the server in the acceptable format
161
- * @param request
162
- */
163
- createTokenRequestBody(request) {
164
- const parameterBuilder = new RequestParameterBuilder();
165
- parameterBuilder.addClientId(this.config.authOptions.clientId);
166
- parameterBuilder.addScopes(request.scopes, false);
167
- parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
168
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
169
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
170
- parameterBuilder.addThrottling();
171
- if (this.serverTelemetryManager) {
172
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
173
- }
174
- const correlationId = request.correlationId ||
175
- this.config.cryptoInterface.createNewGuid();
176
- parameterBuilder.addCorrelationId(correlationId);
177
- if (this.config.clientCredentials.clientSecret) {
178
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
179
- }
180
- // Use clientAssertion from request, fallback to client assertion in base configuration
181
- const clientAssertion = request.clientAssertion ||
182
- this.config.clientCredentials.clientAssertion;
183
- if (clientAssertion) {
184
- parameterBuilder.addClientAssertion(clientAssertion.assertion);
185
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
186
- }
187
- if (!StringUtils.isEmptyObj(request.claims) ||
188
- (this.config.authOptions.clientCapabilities &&
189
- this.config.authOptions.clientCapabilities.length > 0)) {
190
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
191
- }
192
- return parameterBuilder.createQueryString();
193
- }
5
+ /*
6
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7
+ * Licensed under the MIT License.
8
+ */
9
+ /**
10
+ * OAuth2.0 client credential grant
11
+ */
12
+ class ClientCredentialClient extends BaseClient {
13
+ constructor(configuration, appTokenProvider) {
14
+ super(configuration);
15
+ this.appTokenProvider = appTokenProvider;
16
+ }
17
+ /**
18
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
19
+ * @param request
20
+ */
21
+ async acquireToken(request) {
22
+ this.scopeSet = new ScopeSet(request.scopes || []);
23
+ if (request.skipCache) {
24
+ return await this.executeTokenRequest(request, this.authority);
25
+ }
26
+ const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request);
27
+ if (cachedAuthenticationResult) {
28
+ // if the token is not expired but must be refreshed; get a new one in the background
29
+ if (lastCacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
30
+ this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
31
+ // refresh the access token in the background
32
+ const refreshAccessToken = true;
33
+ await this.executeTokenRequest(request, this.authority, refreshAccessToken);
34
+ }
35
+ // return the cached token
36
+ return cachedAuthenticationResult;
37
+ }
38
+ else {
39
+ return await this.executeTokenRequest(request, this.authority);
40
+ }
41
+ }
42
+ /**
43
+ * looks up cache if the tokens are cached already
44
+ */
45
+ async getCachedAuthenticationResult(request) {
46
+ let lastCacheOutcome = CacheOutcome.NOT_APPLICABLE;
47
+ // read the user-supplied cache into memory, if applicable
48
+ let cacheContext;
49
+ if (this.config.serializableCache && this.config.persistencePlugin) {
50
+ cacheContext = new TokenCacheContext(this.config.serializableCache, false);
51
+ await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
52
+ }
53
+ const cachedAccessToken = this.readAccessTokenFromCache();
54
+ if (this.config.serializableCache &&
55
+ this.config.persistencePlugin &&
56
+ cacheContext) {
57
+ await this.config.persistencePlugin.afterCacheAccess(cacheContext);
58
+ }
59
+ // must refresh due to non-existent access_token
60
+ if (!cachedAccessToken) {
61
+ this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
62
+ return [null, CacheOutcome.NO_CACHED_ACCESS_TOKEN];
63
+ }
64
+ // must refresh due to the expires_in value
65
+ if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
66
+ this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
67
+ return [null, CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
68
+ }
69
+ // must refresh (in the background) due to the refresh_in value
70
+ if (cachedAccessToken.refreshOn &&
71
+ TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
72
+ lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
73
+ this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.PROACTIVELY_REFRESHED);
74
+ }
75
+ return [
76
+ await ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
77
+ account: null,
78
+ idToken: null,
79
+ accessToken: cachedAccessToken,
80
+ refreshToken: null,
81
+ appMetadata: null,
82
+ }, true, request),
83
+ lastCacheOutcome,
84
+ ];
85
+ }
86
+ /**
87
+ * Reads access token from the cache
88
+ */
89
+ readAccessTokenFromCache() {
90
+ const accessTokenFilter = {
91
+ homeAccountId: Constants.EMPTY_STRING,
92
+ environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
93
+ credentialType: CredentialType.ACCESS_TOKEN,
94
+ clientId: this.config.authOptions.clientId,
95
+ realm: this.authority.tenant,
96
+ target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
97
+ };
98
+ const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
99
+ if (accessTokens.length < 1) {
100
+ return null;
101
+ }
102
+ else if (accessTokens.length > 1) {
103
+ throw createClientAuthError(ClientAuthErrorCodes.multipleMatchingTokens);
104
+ }
105
+ return accessTokens[0];
106
+ }
107
+ /**
108
+ * Makes a network call to request the token from the service
109
+ * @param request
110
+ * @param authority
111
+ */
112
+ async executeTokenRequest(request, authority, refreshAccessToken) {
113
+ let serverTokenResponse;
114
+ let reqTimestamp;
115
+ if (this.appTokenProvider) {
116
+ this.logger.info("Using appTokenProvider extensibility.");
117
+ const appTokenPropviderParameters = {
118
+ correlationId: request.correlationId,
119
+ tenantId: this.config.authOptions.authority.tenant,
120
+ scopes: request.scopes,
121
+ claims: request.claims,
122
+ };
123
+ reqTimestamp = TimeUtils.nowSeconds();
124
+ const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
125
+ serverTokenResponse = {
126
+ access_token: appTokenProviderResult.accessToken,
127
+ expires_in: appTokenProviderResult.expiresInSeconds,
128
+ refresh_in: appTokenProviderResult.refreshInSeconds,
129
+ token_type: AuthenticationScheme.BEARER,
130
+ };
131
+ }
132
+ else {
133
+ const queryParametersString = this.createTokenQueryParameters(request);
134
+ const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
135
+ const requestBody = this.createTokenRequestBody(request);
136
+ const headers = this.createTokenRequestHeaders();
137
+ const thumbprint = {
138
+ clientId: this.config.authOptions.clientId,
139
+ authority: request.authority,
140
+ scopes: request.scopes,
141
+ claims: request.claims,
142
+ authenticationScheme: request.authenticationScheme,
143
+ resourceRequestMethod: request.resourceRequestMethod,
144
+ resourceRequestUri: request.resourceRequestUri,
145
+ shrClaims: request.shrClaims,
146
+ sshKid: request.sshKid,
147
+ };
148
+ reqTimestamp = TimeUtils.nowSeconds();
149
+ const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
150
+ serverTokenResponse = response.body;
151
+ serverTokenResponse.status = response.status;
152
+ }
153
+ const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
154
+ responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
155
+ const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
156
+ return tokenResponse;
157
+ }
158
+ /**
159
+ * generate the request to the server in the acceptable format
160
+ * @param request
161
+ */
162
+ createTokenRequestBody(request) {
163
+ const parameterBuilder = new RequestParameterBuilder();
164
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
165
+ parameterBuilder.addScopes(request.scopes, false);
166
+ parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
167
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
168
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
169
+ parameterBuilder.addThrottling();
170
+ if (this.serverTelemetryManager) {
171
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
172
+ }
173
+ const correlationId = request.correlationId ||
174
+ this.config.cryptoInterface.createNewGuid();
175
+ parameterBuilder.addCorrelationId(correlationId);
176
+ if (this.config.clientCredentials.clientSecret) {
177
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
178
+ }
179
+ // Use clientAssertion from request, fallback to client assertion in base configuration
180
+ const clientAssertion = request.clientAssertion ||
181
+ this.config.clientCredentials.clientAssertion;
182
+ if (clientAssertion) {
183
+ parameterBuilder.addClientAssertion(clientAssertion.assertion);
184
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
185
+ }
186
+ if (!StringUtils.isEmptyObj(request.claims) ||
187
+ (this.config.authOptions.clientCapabilities &&
188
+ this.config.authOptions.clientCapabilities.length > 0)) {
189
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
190
+ }
191
+ return parameterBuilder.createQueryString();
192
+ }
194
193
  }
195
194
 
196
195
  export { ClientCredentialClient };
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.mjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AA0BA;;AAEG;;AAGC;;AAII,MAAA,sBAAkC,SAAA,UAClB,CAAA;AAMpB,IAAA,WAAA,CAAA,aAAA,EAAA,gBAAA,EAAA;;;AAGG,KAAA;;AA0CH;;AAEG;sBACwC,CAAA,OAAA,EAAA;AAyE3C,QAAA,IAAA,CAAA,QAAA,GAAA,IAAA,QAAA,CAAA,OAAA,CAAA,MAAA,IAAA,EAAA,CAAA,CAAA;;AAEG,YAAA,OAAA,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AACH,SAAA;AAqBA,QAAA,MAAA,0BAAA,GAAA,MAAA,IAAA,CAAA,6BAAA,CAAA,OAAA,CAAA,CAAA;;;;AAIG,gBAAA,YAAA,CAAA,2BAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,IAAA,CAAA,gBAAA,GAAA,YAAA,CAAA,YAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ClientCredentialClient.mjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AA2BA;;AAEG;;AAGC;AAGI;AAOJ,MAAA,sBAAA,SAAA,UAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA,CAAA;KACsB;AAmCzB;;AAEG;;AA4EH,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;;AAEG,QAAA,IAAA,OAAA,CAAA,SAAA,EAAA;AACH,YAAQ,OAAwB,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AAuBhC,SAAA;;;;AAIG,YAAA,IAAA,gBAAA,KAAA,YAAA,CAAA,qBAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,OAAA,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}