@azure/msal-node 2.2.0-alpha.0 → 2.2.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 (106) 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.d.ts +142 -142
  22. package/dist/client/ClientApplication.mjs +333 -333
  23. package/dist/client/ClientAssertion.cjs +116 -116
  24. package/dist/client/ClientAssertion.d.ts +46 -46
  25. package/dist/client/ClientAssertion.mjs +116 -116
  26. package/dist/client/ClientCredentialClient.cjs +189 -189
  27. package/dist/client/ClientCredentialClient.d.ts +33 -33
  28. package/dist/client/ClientCredentialClient.mjs +189 -189
  29. package/dist/client/ConfidentialClientApplication.cjs +163 -163
  30. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  31. package/dist/client/ConfidentialClientApplication.mjs +163 -163
  32. package/dist/client/DeviceCodeClient.cjs +207 -207
  33. package/dist/client/DeviceCodeClient.d.ts +53 -53
  34. package/dist/client/DeviceCodeClient.mjs +207 -207
  35. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  36. package/dist/client/IPublicClientApplication.d.ts +42 -42
  37. package/dist/client/OnBehalfOfClient.cjs +202 -202
  38. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  39. package/dist/client/OnBehalfOfClient.mjs +202 -202
  40. package/dist/client/PublicClientApplication.cjs +229 -229
  41. package/dist/client/PublicClientApplication.d.ts +71 -71
  42. package/dist/client/PublicClientApplication.mjs +229 -229
  43. package/dist/client/UsernamePasswordClient.cjs +95 -95
  44. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  45. package/dist/client/UsernamePasswordClient.mjs +95 -95
  46. package/dist/config/Configuration.cjs +72 -72
  47. package/dist/config/Configuration.d.ts +107 -107
  48. package/dist/config/Configuration.mjs +72 -72
  49. package/dist/crypto/CryptoProvider.cjs +75 -75
  50. package/dist/crypto/CryptoProvider.d.ts +52 -52
  51. package/dist/crypto/CryptoProvider.mjs +75 -75
  52. package/dist/crypto/GuidGenerator.cjs +22 -22
  53. package/dist/crypto/GuidGenerator.d.ts +14 -14
  54. package/dist/crypto/GuidGenerator.mjs +22 -22
  55. package/dist/crypto/HashUtils.cjs +13 -13
  56. package/dist/crypto/HashUtils.d.ts +8 -8
  57. package/dist/crypto/HashUtils.mjs +13 -13
  58. package/dist/crypto/PkceGenerator.cjs +49 -49
  59. package/dist/crypto/PkceGenerator.d.ts +22 -22
  60. package/dist/crypto/PkceGenerator.mjs +49 -49
  61. package/dist/error/NodeAuthError.cjs +85 -85
  62. package/dist/error/NodeAuthError.d.ts +65 -65
  63. package/dist/error/NodeAuthError.mjs +85 -85
  64. package/dist/index.cjs +1 -1
  65. package/dist/index.d.ts +42 -42
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.mjs +1 -1
  68. package/dist/internals.cjs +8 -8
  69. package/dist/internals.d.ts +6 -6
  70. package/dist/internals.mjs +8 -8
  71. package/dist/network/HttpClient.cjs +276 -276
  72. package/dist/network/HttpClient.d.ts +25 -25
  73. package/dist/network/HttpClient.mjs +276 -276
  74. package/dist/network/ILoopbackClient.d.ts +10 -10
  75. package/dist/network/LoopbackClient.cjs +76 -75
  76. package/dist/network/LoopbackClient.cjs.map +1 -1
  77. package/dist/network/LoopbackClient.d.ts +21 -21
  78. package/dist/network/LoopbackClient.d.ts.map +1 -1
  79. package/dist/network/LoopbackClient.mjs +76 -75
  80. package/dist/network/LoopbackClient.mjs.map +1 -1
  81. package/dist/packageMetadata.cjs +4 -4
  82. package/dist/packageMetadata.d.ts +2 -2
  83. package/dist/packageMetadata.mjs +4 -4
  84. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  85. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  86. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  87. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  88. package/dist/request/InteractiveRequest.d.ts +22 -22
  89. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  90. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  91. package/dist/request/SignOutRequest.d.ts +5 -5
  92. package/dist/request/SilentFlowRequest.d.ts +16 -16
  93. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  94. package/dist/utils/Constants.cjs +80 -80
  95. package/dist/utils/Constants.d.ts +86 -86
  96. package/dist/utils/Constants.mjs +80 -80
  97. package/dist/utils/EncodingUtils.cjs +44 -44
  98. package/dist/utils/EncodingUtils.d.ts +26 -26
  99. package/dist/utils/EncodingUtils.mjs +44 -44
  100. package/dist/utils/NetworkUtils.cjs +38 -38
  101. package/dist/utils/NetworkUtils.d.ts +5 -5
  102. package/dist/utils/NetworkUtils.mjs +38 -38
  103. package/package.json +2 -2
  104. package/src/index.ts +1 -0
  105. package/src/network/LoopbackClient.ts +1 -0
  106. package/src/packageMetadata.ts +1 -1
@@ -1,195 +1,195 @@
1
- /*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
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, 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
- }
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
+ }
193
193
  }
194
194
 
195
195
  export { ClientCredentialClient };