@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,198 +1,197 @@
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
3
  'use strict';
4
4
 
5
5
  var msalCommon = require('@azure/msal-common');
6
6
 
7
- /*
8
- * Copyright (c) Microsoft Corporation. All rights reserved.
9
- * Licensed under the MIT License.
10
- */
11
- /**
12
- * OAuth2.0 client credential grant
13
- */
14
- class ClientCredentialClient extends msalCommon.BaseClient {
15
- constructor(configuration, appTokenProvider) {
16
- super(configuration);
17
- this.appTokenProvider = appTokenProvider;
18
- }
19
- /**
20
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
- * @param request
22
- */
23
- async acquireToken(request) {
24
- this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
25
- if (request.skipCache) {
26
- return await this.executeTokenRequest(request, this.authority);
27
- }
28
- const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);
29
- if (cachedAuthenticationResult) {
30
- // if the token is not expired but must be refreshed; get a new one in the background
31
- if (this.lastCacheOutcome ===
32
- msalCommon.CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN) {
33
- this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
34
- // return the cached token, don't wait for the result of this request
35
- const refreshAccessToken = true;
36
- await this.executeTokenRequest(request, this.authority, refreshAccessToken);
37
- }
38
- // reset the last cache outcome
39
- this.lastCacheOutcome = msalCommon.CacheOutcome.NO_CACHE_HIT;
40
- // otherwise, the token is not expired and does not need to be refreshed
41
- return cachedAuthenticationResult;
42
- }
43
- else {
44
- return await this.executeTokenRequest(request, this.authority);
45
- }
46
- }
47
- /**
48
- * looks up cache if the tokens are cached already
49
- */
50
- async getCachedAuthenticationResult(request) {
51
- // read the user-supplied cache into memory, if applicable
52
- let cacheContext;
53
- if (this.config.serializableCache && this.config.persistencePlugin) {
54
- cacheContext = new msalCommon.TokenCacheContext(this.config.serializableCache, false);
55
- await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
56
- }
57
- const cachedAccessToken = this.readAccessTokenFromCache();
58
- if (this.config.serializableCache &&
59
- this.config.persistencePlugin &&
60
- cacheContext) {
61
- await this.config.persistencePlugin.afterCacheAccess(cacheContext);
62
- }
63
- // must refresh due to non-existent access_token
64
- if (!cachedAccessToken) {
65
- this.lastCacheOutcome = msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN;
66
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
67
- return null;
68
- }
69
- // must refresh due to the expires_in value
70
- if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
71
- this.lastCacheOutcome = msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED;
72
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
73
- return null;
74
- }
75
- // must refresh (in the background) due to the refresh_in value
76
- if (cachedAccessToken.refreshOn &&
77
- msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
78
- this.lastCacheOutcome = msalCommon.CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN;
79
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
80
- }
81
- return await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
82
- account: null,
83
- idToken: null,
84
- accessToken: cachedAccessToken,
85
- refreshToken: null,
86
- appMetadata: null,
87
- }, true, request);
88
- }
89
- /**
90
- * Reads access token from the cache
91
- */
92
- readAccessTokenFromCache() {
93
- const accessTokenFilter = {
94
- homeAccountId: msalCommon.Constants.EMPTY_STRING,
95
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
96
- credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
97
- clientId: this.config.authOptions.clientId,
98
- realm: this.authority.tenant,
99
- target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
100
- };
101
- const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
102
- if (accessTokens.length < 1) {
103
- return null;
104
- }
105
- else if (accessTokens.length > 1) {
106
- throw msalCommon.ClientAuthError.createMultipleMatchingTokensInCacheError();
107
- }
108
- return accessTokens[0];
109
- }
110
- /**
111
- * Makes a network call to request the token from the service
112
- * @param request
113
- * @param authority
114
- */
115
- async executeTokenRequest(request, authority, refreshAccessToken) {
116
- let serverTokenResponse;
117
- let reqTimestamp;
118
- if (this.appTokenProvider) {
119
- this.logger.info("Using appTokenProvider extensibility.");
120
- const appTokenPropviderParameters = {
121
- correlationId: request.correlationId,
122
- tenantId: this.config.authOptions.authority.tenant,
123
- scopes: request.scopes,
124
- claims: request.claims,
125
- };
126
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
127
- const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
128
- serverTokenResponse = {
129
- access_token: appTokenProviderResult.accessToken,
130
- expires_in: appTokenProviderResult.expiresInSeconds,
131
- refresh_in: appTokenProviderResult.refreshInSeconds,
132
- token_type: msalCommon.AuthenticationScheme.BEARER,
133
- };
134
- }
135
- else {
136
- const queryParametersString = this.createTokenQueryParameters(request);
137
- const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
138
- const requestBody = this.createTokenRequestBody(request);
139
- const headers = this.createTokenRequestHeaders();
140
- const thumbprint = {
141
- clientId: this.config.authOptions.clientId,
142
- authority: request.authority,
143
- scopes: request.scopes,
144
- claims: request.claims,
145
- authenticationScheme: request.authenticationScheme,
146
- resourceRequestMethod: request.resourceRequestMethod,
147
- resourceRequestUri: request.resourceRequestUri,
148
- shrClaims: request.shrClaims,
149
- sshKid: request.sshKid,
150
- };
151
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
152
- const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
153
- serverTokenResponse = response.body;
154
- serverTokenResponse.status = response.status;
155
- }
156
- const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
157
- responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
158
- const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
159
- return tokenResponse;
160
- }
161
- /**
162
- * generate the request to the server in the acceptable format
163
- * @param request
164
- */
165
- createTokenRequestBody(request) {
166
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
167
- parameterBuilder.addClientId(this.config.authOptions.clientId);
168
- parameterBuilder.addScopes(request.scopes, false);
169
- parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
170
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
171
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
172
- parameterBuilder.addThrottling();
173
- if (this.serverTelemetryManager) {
174
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
175
- }
176
- const correlationId = request.correlationId ||
177
- this.config.cryptoInterface.createNewGuid();
178
- parameterBuilder.addCorrelationId(correlationId);
179
- if (this.config.clientCredentials.clientSecret) {
180
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
181
- }
182
- // Use clientAssertion from request, fallback to client assertion in base configuration
183
- const clientAssertion = request.clientAssertion ||
184
- this.config.clientCredentials.clientAssertion;
185
- if (clientAssertion) {
186
- parameterBuilder.addClientAssertion(clientAssertion.assertion);
187
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
188
- }
189
- if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
190
- (this.config.authOptions.clientCapabilities &&
191
- this.config.authOptions.clientCapabilities.length > 0)) {
192
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
193
- }
194
- return parameterBuilder.createQueryString();
195
- }
7
+ /*
8
+ * Copyright (c) Microsoft Corporation. All rights reserved.
9
+ * Licensed under the MIT License.
10
+ */
11
+ /**
12
+ * OAuth2.0 client credential grant
13
+ */
14
+ class ClientCredentialClient extends msalCommon.BaseClient {
15
+ constructor(configuration, appTokenProvider) {
16
+ super(configuration);
17
+ this.appTokenProvider = appTokenProvider;
18
+ }
19
+ /**
20
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
+ * @param request
22
+ */
23
+ async acquireToken(request) {
24
+ this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
25
+ if (request.skipCache) {
26
+ return await this.executeTokenRequest(request, this.authority);
27
+ }
28
+ const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request);
29
+ if (cachedAuthenticationResult) {
30
+ // if the token is not expired but must be refreshed; get a new one in the background
31
+ if (lastCacheOutcome === msalCommon.CacheOutcome.PROACTIVELY_REFRESHED) {
32
+ this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
33
+ // refresh the access token in the background
34
+ const refreshAccessToken = true;
35
+ await this.executeTokenRequest(request, this.authority, refreshAccessToken);
36
+ }
37
+ // return the cached token
38
+ return cachedAuthenticationResult;
39
+ }
40
+ else {
41
+ return await this.executeTokenRequest(request, this.authority);
42
+ }
43
+ }
44
+ /**
45
+ * looks up cache if the tokens are cached already
46
+ */
47
+ async getCachedAuthenticationResult(request) {
48
+ let lastCacheOutcome = msalCommon.CacheOutcome.NOT_APPLICABLE;
49
+ // read the user-supplied cache into memory, if applicable
50
+ let cacheContext;
51
+ if (this.config.serializableCache && this.config.persistencePlugin) {
52
+ cacheContext = new msalCommon.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.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
64
+ return [null, msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN];
65
+ }
66
+ // must refresh due to the expires_in value
67
+ if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
68
+ this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
69
+ return [null, msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
70
+ }
71
+ // must refresh (in the background) due to the refresh_in value
72
+ if (cachedAccessToken.refreshOn &&
73
+ msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
74
+ lastCacheOutcome = msalCommon.CacheOutcome.PROACTIVELY_REFRESHED;
75
+ this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.PROACTIVELY_REFRESHED);
76
+ }
77
+ return [
78
+ await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
79
+ account: null,
80
+ idToken: null,
81
+ accessToken: cachedAccessToken,
82
+ refreshToken: null,
83
+ appMetadata: null,
84
+ }, true, request),
85
+ lastCacheOutcome,
86
+ ];
87
+ }
88
+ /**
89
+ * Reads access token from the cache
90
+ */
91
+ readAccessTokenFromCache() {
92
+ const accessTokenFilter = {
93
+ homeAccountId: msalCommon.Constants.EMPTY_STRING,
94
+ environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
95
+ credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
96
+ clientId: this.config.authOptions.clientId,
97
+ realm: this.authority.tenant,
98
+ target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
99
+ };
100
+ const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
101
+ if (accessTokens.length < 1) {
102
+ return null;
103
+ }
104
+ else if (accessTokens.length > 1) {
105
+ throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
106
+ }
107
+ return accessTokens[0];
108
+ }
109
+ /**
110
+ * Makes a network call to request the token from the service
111
+ * @param request
112
+ * @param authority
113
+ */
114
+ async executeTokenRequest(request, authority, refreshAccessToken) {
115
+ let serverTokenResponse;
116
+ let reqTimestamp;
117
+ if (this.appTokenProvider) {
118
+ this.logger.info("Using appTokenProvider extensibility.");
119
+ const appTokenPropviderParameters = {
120
+ correlationId: request.correlationId,
121
+ tenantId: this.config.authOptions.authority.tenant,
122
+ scopes: request.scopes,
123
+ claims: request.claims,
124
+ };
125
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
126
+ const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
127
+ serverTokenResponse = {
128
+ access_token: appTokenProviderResult.accessToken,
129
+ expires_in: appTokenProviderResult.expiresInSeconds,
130
+ refresh_in: appTokenProviderResult.refreshInSeconds,
131
+ token_type: msalCommon.AuthenticationScheme.BEARER,
132
+ };
133
+ }
134
+ else {
135
+ const queryParametersString = this.createTokenQueryParameters(request);
136
+ const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
137
+ const requestBody = this.createTokenRequestBody(request);
138
+ const headers = this.createTokenRequestHeaders();
139
+ const thumbprint = {
140
+ clientId: this.config.authOptions.clientId,
141
+ authority: request.authority,
142
+ scopes: request.scopes,
143
+ claims: request.claims,
144
+ authenticationScheme: request.authenticationScheme,
145
+ resourceRequestMethod: request.resourceRequestMethod,
146
+ resourceRequestUri: request.resourceRequestUri,
147
+ shrClaims: request.shrClaims,
148
+ sshKid: request.sshKid,
149
+ };
150
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
151
+ const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
152
+ serverTokenResponse = response.body;
153
+ serverTokenResponse.status = response.status;
154
+ }
155
+ const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
156
+ responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
157
+ const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
158
+ return tokenResponse;
159
+ }
160
+ /**
161
+ * generate the request to the server in the acceptable format
162
+ * @param request
163
+ */
164
+ createTokenRequestBody(request) {
165
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
166
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
167
+ parameterBuilder.addScopes(request.scopes, false);
168
+ parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
169
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
170
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
171
+ parameterBuilder.addThrottling();
172
+ if (this.serverTelemetryManager) {
173
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
174
+ }
175
+ const correlationId = request.correlationId ||
176
+ this.config.cryptoInterface.createNewGuid();
177
+ parameterBuilder.addCorrelationId(correlationId);
178
+ if (this.config.clientCredentials.clientSecret) {
179
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
180
+ }
181
+ // Use clientAssertion from request, fallback to client assertion in base configuration
182
+ const clientAssertion = request.clientAssertion ||
183
+ this.config.clientCredentials.clientAssertion;
184
+ if (clientAssertion) {
185
+ parameterBuilder.addClientAssertion(clientAssertion.assertion);
186
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
187
+ }
188
+ if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
189
+ (this.config.authOptions.clientCapabilities &&
190
+ this.config.authOptions.clientCapabilities.length > 0)) {
191
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
192
+ }
193
+ return parameterBuilder.createQueryString();
194
+ }
196
195
  }
197
196
 
198
197
  exports.ClientCredentialClient = ClientCredentialClient;
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient","ScopeSet","CacheOutcome"],"mappings":";;;;;;AAKA;AA0BA;;AAEG;;AAGC;;AAII,MAAA,sBAAkC,SAAAA,qBAClB,CAAA;AAMpB,IAAA,WAAA,CAAA,aAAA,EAAA,gBAAA,EAAA;;;AAGG,KAAA;;AA0CH;;AAEG;sBACwC,CAAA,OAAA,EAAA;AAyE3C,QAAA,IAAA,CAAA,QAAA,GAAA,IAAAC,mBAAA,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,gBAAAC,uBAAA,CAAA,2BAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,IAAA,CAAA,gBAAA,GAAAA,uBAAA,CAAA,YAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient","CacheOutcome"],"mappings":";;;;;;AAKA;AA2BA;;AAEG;;AAGC;AAGI;AAOJ,MAAA,sBAAA,SAAAA,qBAAA,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,KAAAC,uBAAA,CAAA,qBAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,OAAA,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,35 +1,34 @@
1
- import { AuthenticationResult, BaseClient, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider } from "@azure/msal-common";
2
- /**
3
- * OAuth2.0 client credential grant
4
- */
5
- export declare class ClientCredentialClient extends BaseClient {
6
- private scopeSet;
7
- private readonly appTokenProvider?;
8
- private lastCacheOutcome;
9
- constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
10
- /**
11
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
12
- * @param request
13
- */
14
- acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
15
- /**
16
- * looks up cache if the tokens are cached already
17
- */
18
- private getCachedAuthenticationResult;
19
- /**
20
- * Reads access token from the cache
21
- */
22
- private readAccessTokenFromCache;
23
- /**
24
- * Makes a network call to request the token from the service
25
- * @param request
26
- * @param authority
27
- */
28
- private executeTokenRequest;
29
- /**
30
- * generate the request to the server in the acceptable format
31
- * @param request
32
- */
33
- private createTokenRequestBody;
34
- }
1
+ import { AuthenticationResult, BaseClient, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider } from "@azure/msal-common";
2
+ /**
3
+ * OAuth2.0 client credential grant
4
+ */
5
+ export declare class ClientCredentialClient extends BaseClient {
6
+ private scopeSet;
7
+ private readonly appTokenProvider?;
8
+ constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
9
+ /**
10
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
11
+ * @param request
12
+ */
13
+ acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
14
+ /**
15
+ * looks up cache if the tokens are cached already
16
+ */
17
+ private getCachedAuthenticationResult;
18
+ /**
19
+ * Reads access token from the cache
20
+ */
21
+ private readAccessTokenFromCache;
22
+ /**
23
+ * Makes a network call to request the token from the service
24
+ * @param request
25
+ * @param authority
26
+ */
27
+ private executeTokenRequest;
28
+ /**
29
+ * generate the request to the server in the acceptable format
30
+ * @param request
31
+ */
32
+ private createTokenRequestBody;
33
+ }
35
34
  //# sourceMappingURL=ClientCredentialClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAGpB,UAAU,EAGV,mBAAmB,EACnB,6BAA6B,EAK7B,iBAAiB,EAUpB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;IACtD,OAAO,CAAC,gBAAgB,CAAe;gBAGnC,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,CAAC,EAAE,iBAAiB;IAMxC;;;OAGG;IACU,YAAY,CACrB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAuCvC;;OAEG;YACW,6BAA6B;IAyE3C;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAqBhC;;;;OAIG;YACW,mBAAmB;IAwFjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA0DjC"}
1
+ {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAGpB,UAAU,EAGV,mBAAmB,EACnB,6BAA6B,EAK7B,iBAAiB,EAWpB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAGlD,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,CAAC,EAAE,iBAAiB;IAMxC;;;OAGG;IACU,YAAY,CACrB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAiCvC;;OAEG;YACW,6BAA6B;IA2E3C;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAuBhC;;;;OAIG;YACW,mBAAmB;IAwFjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA0DjC"}