@azure/msal-common 7.1.0 → 7.4.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 (165) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AccountInfo.d.ts +6 -0
  3. package/dist/account/AccountInfo.d.ts.map +1 -1
  4. package/dist/account/AuthToken.js +1 -1
  5. package/dist/account/AuthToken.js.map +1 -1
  6. package/dist/account/CcsCredential.js +1 -1
  7. package/dist/account/CcsCredential.js.map +1 -1
  8. package/dist/account/ClientInfo.js +3 -3
  9. package/dist/account/ClientInfo.js.map +1 -1
  10. package/dist/authority/Authority.js +1 -1
  11. package/dist/authority/Authority.js.map +1 -1
  12. package/dist/authority/AuthorityFactory.js +1 -1
  13. package/dist/authority/AuthorityFactory.js.map +1 -1
  14. package/dist/authority/AuthorityMetadata.js +1 -1
  15. package/dist/authority/AuthorityMetadata.js.map +1 -1
  16. package/dist/authority/AuthorityOptions.js +1 -1
  17. package/dist/authority/AuthorityOptions.js.map +1 -1
  18. package/dist/authority/AuthorityType.js +1 -1
  19. package/dist/authority/AuthorityType.js.map +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  21. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  22. package/dist/authority/OpenIdConfigResponse.js +1 -1
  23. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  24. package/dist/authority/ProtocolMode.js +1 -1
  25. package/dist/authority/ProtocolMode.js.map +1 -1
  26. package/dist/authority/RegionDiscovery.js +1 -1
  27. package/dist/authority/RegionDiscovery.js.map +1 -1
  28. package/dist/cache/CacheManager.d.ts +13 -0
  29. package/dist/cache/CacheManager.d.ts.map +1 -1
  30. package/dist/cache/CacheManager.js +36 -3
  31. package/dist/cache/CacheManager.js.map +1 -1
  32. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  33. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  34. package/dist/cache/entities/AccountEntity.js +1 -1
  35. package/dist/cache/entities/AccountEntity.js.map +1 -1
  36. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  37. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  38. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  39. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  40. package/dist/cache/entities/CacheRecord.js +1 -1
  41. package/dist/cache/entities/CacheRecord.js.map +1 -1
  42. package/dist/cache/entities/CredentialEntity.js +1 -1
  43. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  44. package/dist/cache/entities/IdTokenEntity.js +1 -1
  45. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  46. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  47. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  48. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  49. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  50. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  51. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  52. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  53. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  54. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  55. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  56. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  57. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  58. package/dist/client/AuthorizationCodeClient.js +30 -14
  59. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  60. package/dist/client/BaseClient.d.ts +3 -1
  61. package/dist/client/BaseClient.d.ts.map +1 -1
  62. package/dist/client/BaseClient.js +4 -2
  63. package/dist/client/BaseClient.js.map +1 -1
  64. package/dist/client/ClientCredentialClient.d.ts +3 -1
  65. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  66. package/dist/client/ClientCredentialClient.js +34 -9
  67. package/dist/client/ClientCredentialClient.js.map +1 -1
  68. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  69. package/dist/client/DeviceCodeClient.js +13 -7
  70. package/dist/client/DeviceCodeClient.js.map +1 -1
  71. package/dist/client/OnBehalfOfClient.js +1 -1
  72. package/dist/client/OnBehalfOfClient.js.map +1 -1
  73. package/dist/client/RefreshTokenClient.d.ts +2 -1
  74. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  75. package/dist/client/RefreshTokenClient.js +40 -16
  76. package/dist/client/RefreshTokenClient.js.map +1 -1
  77. package/dist/client/SilentFlowClient.d.ts +2 -1
  78. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  79. package/dist/client/SilentFlowClient.js +4 -4
  80. package/dist/client/SilentFlowClient.js.map +1 -1
  81. package/dist/client/UsernamePasswordClient.js +1 -1
  82. package/dist/client/UsernamePasswordClient.js.map +1 -1
  83. package/dist/config/AppTokenProvider.d.ts +39 -0
  84. package/dist/config/AppTokenProvider.d.ts.map +1 -0
  85. package/dist/config/ClientConfiguration.d.ts +1 -1
  86. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  87. package/dist/config/ClientConfiguration.js +2 -2
  88. package/dist/config/ClientConfiguration.js.map +1 -1
  89. package/dist/crypto/ICrypto.js +1 -1
  90. package/dist/crypto/ICrypto.js.map +1 -1
  91. package/dist/crypto/JoseHeader.js +1 -1
  92. package/dist/crypto/JoseHeader.js.map +1 -1
  93. package/dist/crypto/PopTokenGenerator.js +1 -1
  94. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  95. package/dist/error/AuthError.d.ts +10 -0
  96. package/dist/error/AuthError.d.ts.map +1 -1
  97. package/dist/error/AuthError.js +13 -1
  98. package/dist/error/AuthError.js.map +1 -1
  99. package/dist/error/ClientAuthError.js +1 -1
  100. package/dist/error/ClientAuthError.js.map +1 -1
  101. package/dist/error/ClientConfigurationError.js +1 -1
  102. package/dist/error/ClientConfigurationError.js.map +1 -1
  103. package/dist/error/InteractionRequiredAuthError.js +1 -1
  104. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  105. package/dist/error/JoseHeaderError.js +1 -1
  106. package/dist/error/JoseHeaderError.js.map +1 -1
  107. package/dist/error/ServerError.js +1 -1
  108. package/dist/error/ServerError.js.map +1 -1
  109. package/dist/index.cjs.js +344 -153
  110. package/dist/index.cjs.js.map +1 -1
  111. package/dist/index.d.ts +4 -2
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +3 -2
  114. package/dist/index.js.map +1 -1
  115. package/dist/logger/Logger.js +1 -1
  116. package/dist/logger/Logger.js.map +1 -1
  117. package/dist/network/INetworkModule.js +1 -1
  118. package/dist/network/INetworkModule.js.map +1 -1
  119. package/dist/network/NetworkManager.js +1 -1
  120. package/dist/network/NetworkManager.js.map +1 -1
  121. package/dist/network/ThrottlingUtils.js +1 -1
  122. package/dist/network/ThrottlingUtils.js.map +1 -1
  123. package/dist/packageMetadata.d.ts +1 -1
  124. package/dist/packageMetadata.js +2 -2
  125. package/dist/packageMetadata.js.map +1 -1
  126. package/dist/request/AuthenticationHeaderParser.js +1 -1
  127. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  128. package/dist/request/CommonRefreshTokenRequest.d.ts +4 -2
  129. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  130. package/dist/request/RequestParameterBuilder.js +1 -1
  131. package/dist/request/RequestParameterBuilder.js.map +1 -1
  132. package/dist/request/RequestValidator.js +1 -1
  133. package/dist/request/RequestValidator.js.map +1 -1
  134. package/dist/request/ScopeSet.js +1 -1
  135. package/dist/request/ScopeSet.js.map +1 -1
  136. package/dist/response/ResponseHandler.d.ts +1 -1
  137. package/dist/response/ResponseHandler.d.ts.map +1 -1
  138. package/dist/response/ResponseHandler.js +6 -5
  139. package/dist/response/ResponseHandler.js.map +1 -1
  140. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  141. package/dist/telemetry/performance/PerformanceClient.js +8 -2
  142. package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
  143. package/dist/telemetry/performance/PerformanceEvent.d.ts +35 -1
  144. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  145. package/dist/telemetry/performance/PerformanceEvent.js +22 -1
  146. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  147. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  148. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
  149. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  150. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  151. package/dist/url/UrlString.d.ts +9 -0
  152. package/dist/url/UrlString.d.ts.map +1 -1
  153. package/dist/url/UrlString.js +34 -1
  154. package/dist/url/UrlString.js.map +1 -1
  155. package/dist/utils/Constants.d.ts +3 -1
  156. package/dist/utils/Constants.d.ts.map +1 -1
  157. package/dist/utils/Constants.js +4 -2
  158. package/dist/utils/Constants.js.map +1 -1
  159. package/dist/utils/ProtocolUtils.js +1 -1
  160. package/dist/utils/ProtocolUtils.js.map +1 -1
  161. package/dist/utils/StringUtils.js +1 -1
  162. package/dist/utils/StringUtils.js.map +1 -1
  163. package/dist/utils/TimeUtils.js +1 -1
  164. package/dist/utils/TimeUtils.js.map +1 -1
  165. package/package.json +4 -6
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAQzF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAElD,OAAO,CAAC,QAAQ,CAAW;gBAEf,aAAa,EAAE,mBAAmB;IAI9C;;;OAGG;IACU,YAAY,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAgBvG;;OAEG;YACW,6BAA6B;IA6B3C;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;;;OAIG;YACW,mBAAmB;IAwCjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAuCjC"}
1
+ {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAElD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAE1C,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,iBAAiB;IAKpF;;;OAGG;IACU,YAAY,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAgBvG;;OAEG;YACW,6BAA6B;IA6B3C;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;;;OAIG;YACW,mBAAmB;IAkEjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAuCjC"}
@@ -1,10 +1,10 @@
1
- /*! @azure/msal-common v7.1.0 2022-07-05 */
1
+ /*! @azure/msal-common v7.4.0 2022-09-06 */
2
2
  'use strict';
3
3
  import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { BaseClient } from './BaseClient.js';
5
5
  import { RequestParameterBuilder } from '../request/RequestParameterBuilder.js';
6
6
  import { ScopeSet } from '../request/ScopeSet.js';
7
- import { Constants, CredentialType, GrantType, CacheOutcome } from '../utils/Constants.js';
7
+ import { Constants, CredentialType, GrantType, CacheOutcome, AuthenticationScheme } from '../utils/Constants.js';
8
8
  import { ResponseHandler } from '../response/ResponseHandler.js';
9
9
  import { TimeUtils } from '../utils/TimeUtils.js';
10
10
  import { StringUtils } from '../utils/StringUtils.js';
@@ -19,8 +19,10 @@ import { ClientAuthError } from '../error/ClientAuthError.js';
19
19
  */
20
20
  var ClientCredentialClient = /** @class */ (function (_super) {
21
21
  __extends(ClientCredentialClient, _super);
22
- function ClientCredentialClient(configuration) {
23
- return _super.call(this, configuration) || this;
22
+ function ClientCredentialClient(configuration, appTokenProvider) {
23
+ var _this = _super.call(this, configuration) || this;
24
+ _this.appTokenProvider = appTokenProvider;
25
+ return _this;
24
26
  }
25
27
  /**
26
28
  * Public API to acquire a token with ClientCredential Flow for Confidential clients
@@ -108,10 +110,30 @@ var ClientCredentialClient = /** @class */ (function (_super) {
108
110
  */
109
111
  ClientCredentialClient.prototype.executeTokenRequest = function (request, authority) {
110
112
  return __awaiter(this, void 0, void 0, function () {
111
- var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
113
+ var serverTokenResponse, reqTimestamp, appTokenPropviderParameters, appTokenProviderResult, requestBody, headers, thumbprint, response, responseHandler, tokenResponse;
112
114
  return __generator(this, function (_a) {
113
115
  switch (_a.label) {
114
116
  case 0:
117
+ if (!this.appTokenProvider) return [3 /*break*/, 2];
118
+ this.logger.info("Using appTokenProvider extensibility.");
119
+ appTokenPropviderParameters = {
120
+ correlationId: request.correlationId,
121
+ tenantId: this.config.authOptions.authority.tenant,
122
+ scopes: request.scopes,
123
+ claims: request.claims,
124
+ };
125
+ reqTimestamp = TimeUtils.nowSeconds();
126
+ return [4 /*yield*/, this.appTokenProvider(appTokenPropviderParameters)];
127
+ case 1:
128
+ appTokenProviderResult = _a.sent();
129
+ serverTokenResponse = {
130
+ access_token: appTokenProviderResult.accessToken,
131
+ expires_in: appTokenProviderResult.expiresInSeconds,
132
+ refresh_in: appTokenProviderResult.refreshInSeconds,
133
+ token_type: AuthenticationScheme.BEARER
134
+ };
135
+ return [3 /*break*/, 4];
136
+ case 2:
115
137
  requestBody = this.createTokenRequestBody(request);
116
138
  headers = this.createTokenRequestHeaders();
117
139
  thumbprint = {
@@ -127,12 +149,15 @@ var ClientCredentialClient = /** @class */ (function (_super) {
127
149
  };
128
150
  reqTimestamp = TimeUtils.nowSeconds();
129
151
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
130
- case 1:
152
+ case 3:
131
153
  response = _a.sent();
154
+ serverTokenResponse = response.body;
155
+ _a.label = 4;
156
+ case 4:
132
157
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
133
- responseHandler.validateTokenResponse(response.body);
134
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
135
- case 2:
158
+ responseHandler.validateTokenResponse(serverTokenResponse);
159
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request)];
160
+ case 5:
136
161
  tokenResponse = _a.sent();
137
162
  return [2 /*return*/, tokenResponse];
138
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.js","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType , CredentialType, CacheOutcome, Constants } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonClientCredentialRequest } from \"../request/CommonClientCredentialRequest\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\n\n/**\n * OAuth2.0 client credential grant\n */\nexport class ClientCredentialClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Public API to acquire a token with ClientCredential Flow for Confidential clients\n * @param request\n */\n public async acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority);\n }\n\n const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);\n if (cachedAuthenticationResult) {\n return cachedAuthenticationResult;\n } else {\n return await this.executeTokenRequest(request, this.authority);\n }\n }\n\n /**\n * looks up cache if the tokens are cached already\n */\n private async getCachedAuthenticationResult(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n \n const cachedAccessToken = this.readAccessTokenFromCache();\n\n if (!cachedAccessToken) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n return null;\n }\n\n if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);\n return null;\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: null,\n idToken: null,\n accessToken: cachedAccessToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request\n );\n }\n\n /**\n * Reads access token from the cache\n * TODO: Move this call to cacheManager instead\n */\n private readAccessTokenFromCache(): AccessTokenEntity | null {\n const accessTokenFilter: CredentialFilter = {\n homeAccountId: Constants.EMPTY_STRING,\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ACCESS_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant,\n target: this.scopeSet.printScopesLowerCase()\n };\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n const accessTokens = Object.keys(credentialCache.accessTokens).map(key => credentialCache.accessTokens[key]);\n if (accessTokens.length < 1) {\n return null;\n } else if (accessTokens.length > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * Makes a network call to request the token from the service\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonClientCredentialRequest, authority: Authority)\n : Promise<AuthenticationResult | null> {\n\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(response.body);\n const tokenResponse = await responseHandler.handleServerTokenResponse(\n response.body,\n this.authority,\n reqTimestamp,\n request\n );\n\n return tokenResponse;\n }\n\n /**\n * generate the request to the server in the acceptable format\n * @param request\n */\n private createTokenRequestBody(request: CommonClientCredentialRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes, false);\n\n parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n\n parameterBuilder.addThrottling();\n \n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n // Use clientAssertion from request, fallback to client assertion in base configuration\n const clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;\n\n if (clientAssertion) {\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAqBA;;;;IAG4C,0CAAU;IAIlD,gCAAY,aAAkC;eAC1C,kBAAM,aAAa,CAAC;KACvB;;;;;IAMY,6CAAY,GAAzB,UAA0B,OAAsC;;;;;;wBAE5D,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;6BAE/C,OAAO,CAAC,SAAS,EAAjB,wBAAiB;wBACV,qBAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAA;4BAA9D,sBAAO,SAAuD,E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AC;QAEjC,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC7B,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;SACpE;QAED,IAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;QAC3F,gBAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAEjD,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE;YAC5C,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;SAChF;;QAGD,IAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,CAAC;QAEjG,IAAI,eAAe,EAAE;YACjB,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAC/D,gBAAgB,CAAC,sBAAsB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;SAC1E;QAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;YAChJ,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;SAC1F;QAED,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C;IACL,6BAAC;AAAD,CA3KA,CAA4C,UAAU;;;;"}
1
+ {"version":3,"file":"ClientCredentialClient.js","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType , CredentialType, CacheOutcome, Constants, AuthenticationScheme } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonClientCredentialRequest } from \"../request/CommonClientCredentialRequest\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { IAppTokenProvider } from \"../config/AppTokenProvider\";\n\n/**\n * OAuth2.0 client credential grant\n */\nexport class ClientCredentialClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n private readonly appTokenProvider?: IAppTokenProvider;\n\n constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider) {\n super(configuration);\n this.appTokenProvider = appTokenProvider;\n }\n\n /**\n * Public API to acquire a token with ClientCredential Flow for Confidential clients\n * @param request\n */\n public async acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority);\n }\n\n const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);\n if (cachedAuthenticationResult) {\n return cachedAuthenticationResult;\n } else {\n return await this.executeTokenRequest(request, this.authority);\n }\n }\n\n /**\n * looks up cache if the tokens are cached already\n */\n private async getCachedAuthenticationResult(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n \n const cachedAccessToken = this.readAccessTokenFromCache();\n\n if (!cachedAccessToken) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n return null;\n }\n\n if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);\n return null;\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: null,\n idToken: null,\n accessToken: cachedAccessToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request\n );\n }\n\n /**\n * Reads access token from the cache\n * TODO: Move this call to cacheManager instead\n */\n private readAccessTokenFromCache(): AccessTokenEntity | null {\n const accessTokenFilter: CredentialFilter = {\n homeAccountId: Constants.EMPTY_STRING,\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ACCESS_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant,\n target: this.scopeSet.printScopesLowerCase()\n };\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n const accessTokens = Object.keys(credentialCache.accessTokens).map(key => credentialCache.accessTokens[key]);\n if (accessTokens.length < 1) {\n return null;\n } else if (accessTokens.length > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * Makes a network call to request the token from the service\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonClientCredentialRequest, authority: Authority)\n : Promise<AuthenticationResult | null> {\n \n let serverTokenResponse: ServerAuthorizationTokenResponse;\n let reqTimestamp: number;\n\n if (this.appTokenProvider) {\n this.logger.info(\"Using appTokenProvider extensibility.\");\n\n const appTokenPropviderParameters = {\n correlationId: request.correlationId,\n tenantId: this.config.authOptions.authority.tenant,\n scopes: request.scopes,\n claims: request.claims,\n };\n\n reqTimestamp = TimeUtils.nowSeconds();\n const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);\n\n serverTokenResponse = {\n access_token: appTokenProviderResult.accessToken, \n expires_in: appTokenProviderResult.expiresInSeconds,\n refresh_in: appTokenProviderResult.refreshInSeconds,\n token_type : AuthenticationScheme.BEARER\n };\n } else {\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n \n reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n serverTokenResponse = response.body;\n }\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(serverTokenResponse);\n \n const tokenResponse = await responseHandler.handleServerTokenResponse(\n serverTokenResponse,\n this.authority,\n reqTimestamp,\n request\n );\n\n return tokenResponse;\n }\n\n /**\n * generate the request to the server in the acceptable format\n * @param request\n */\n private createTokenRequestBody(request: CommonClientCredentialRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes, false);\n\n parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n\n parameterBuilder.addThrottling();\n \n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n // Use clientAssertion from request, fallback to client assertion in base configuration\n const clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;\n\n if (clientAssertion) {\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAoBH;;AAEG;AACH,IAAA,sBAAA,kBAAA,UAAA,MAAA,EAAA;IAA4C,SAAU,CAAA,sBAAA,EAAA,MAAA,CAAA,CAAA;IAKlD,SAAY,sBAAA,CAAA,aAAkC,EAAE,gBAAoC,EAAA;QAApF,IACI,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAM,aAAa,CAAC,IAEvB,IAAA,CAAA;AADG,QAAA,KAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;;KAC5C;AAED;;;AAGG;IACU,sBAAY,CAAA,SAAA,CAAA,YAAA,GAAzB,UAA0B,OAAsC,EAAA;;;;;;AAE5D,wBAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;6BAE/C,OAAO,CAAC,SAAS,EAAjB,OAAiB,CAAA,CAAA,YAAA,CAAA,CAAA,CAAA;wBACV,OAAM,CAAA,CAAA,YAAA,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA,CAAA;AAA9D,oBAAA,KAAA,CAAA,EAAA,OAAA,CAAA,C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KG;YACW,sCAAsC;IAkCpD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAqBvB;;;;;OAKG;YACW,0BAA0B;IAoDxC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAwBjC"}
1
+ {"version":3,"file":"DeviceCodeClient.d.ts","sourceRoot":"","sources":["../../src/client/DeviceCodeClient.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAI7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;gBAEhC,aAAa,EAAE,mBAAmB;IAI9C;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IA2BjG;;;OAGG;YACW,aAAa;IAkB3B;;;;;OAKG;YACW,sCAAsC;IAkCpD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAqBvB;;;;;OAKG;YACW,0BAA0B;IA0DxC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAwBjC"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v7.1.0 2022-07-05 */
1
+ /*! @azure/msal-common v7.4.0 2022-09-06 */
2
2
  'use strict';
3
3
  import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { BaseClient } from './BaseClient.js';
@@ -8,6 +8,7 @@ import { GrantType, Constants } from '../utils/Constants.js';
8
8
  import { TimeUtils } from '../utils/TimeUtils.js';
9
9
  import { ResponseHandler } from '../response/ResponseHandler.js';
10
10
  import { StringUtils } from '../utils/StringUtils.js';
11
+ import { ServerError } from '../error/ServerError.js';
11
12
 
12
13
  /*
13
14
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -157,7 +158,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
157
158
  pollingIntervalMilli = deviceCodeResponse.interval * 1000;
158
159
  _a.label = 1;
159
160
  case 1:
160
- if (!this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) return [3 /*break*/, 6];
161
+ if (!this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) return [3 /*break*/, 8];
161
162
  thumbprint = {
162
163
  clientId: this.config.authOptions.clientId,
163
164
  authority: request.authority,
@@ -172,18 +173,23 @@ var DeviceCodeClient = /** @class */ (function (_super) {
172
173
  return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
173
174
  case 2:
174
175
  response = _a.sent();
175
- if (!(response.body && response.body.error === Constants.AUTHORIZATION_PENDING)) return [3 /*break*/, 4];
176
- // user authorization is pending. Sleep for polling interval and try again
177
- this.logger.info(response.body.error_description || "Authorization pending. Continue polling.");
176
+ if (!(response.body && response.body.error)) return [3 /*break*/, 6];
177
+ if (!(response.body.error === Constants.AUTHORIZATION_PENDING)) return [3 /*break*/, 4];
178
+ this.logger.info("Authorization pending. Continue polling.");
178
179
  return [4 /*yield*/, TimeUtils.delay(pollingIntervalMilli)];
179
180
  case 3:
180
181
  _a.sent();
181
182
  return [3 /*break*/, 5];
182
183
  case 4:
184
+ // for any other error, throw
185
+ this.logger.info("Unexpected error in polling from the server");
186
+ throw ServerError.createPostRequestFailed(response.body.error);
187
+ case 5: return [3 /*break*/, 7];
188
+ case 6:
183
189
  this.logger.verbose("Authorization completed successfully. Polling stopped.");
184
190
  return [2 /*return*/, response.body];
185
- case 5: return [3 /*break*/, 1];
186
- case 6:
191
+ case 7: return [3 /*break*/, 1];
192
+ case 8:
187
193
  /*
188
194
  * The above code should've thrown by this point, but to satisfy TypeScript,
189
195
  * and in the rare case the conditionals in continuePolling() may not catch everything...
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceCodeClient.js","sources":["../../src/client/DeviceCodeClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DeviceCodeResponse, ServerDeviceCodeResponse } from \"../response/DeviceCodeResponse\";\nimport { BaseClient } from \"./BaseClient\";\nimport { CommonDeviceCodeRequest } from \"../request/CommonDeviceCodeRequest\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { Constants, GrantType } from \"../utils/Constants\";\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\n\n/**\n * OAuth2.0 Device code client\n */\nexport class DeviceCodeClient extends BaseClient {\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Gets device code from device code endpoint, calls back to with device code response, and\n * polls token endpoint to exchange device code for tokens\n * @param request\n */\n public async acquireToken(request: CommonDeviceCodeRequest): Promise<AuthenticationResult | null> {\n const deviceCodeResponse: DeviceCodeResponse = await this.getDeviceCode(request);\n request.deviceCodeCallback(deviceCodeResponse);\n const reqTimestamp = TimeUtils.nowSeconds();\n const response: ServerAuthorizationTokenResponse = await this.acquireTokenWithDeviceCode(\n request,\n deviceCodeResponse);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n // Validate response. This function throws a server error if an error is returned by the server.\n responseHandler.validateTokenResponse(response);\n return await responseHandler.handleServerTokenResponse(\n response,\n this.authority,\n reqTimestamp,\n request\n );\n }\n\n /**\n * Creates device code request and executes http GET\n * @param request\n */\n private async getDeviceCode(request: CommonDeviceCodeRequest): Promise<DeviceCodeResponse> {\n const queryString = this.createQueryString(request);\n const headers = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n return this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint);\n }\n\n /**\n * Executes POST request to device code endpoint\n * @param deviceCodeEndpoint\n * @param queryString\n * @param headers\n */\n private async executePostRequestToDeviceCodeEndpoint(\n deviceCodeEndpoint: string,\n queryString: string,\n headers: Record<string, string>,\n thumbprint: RequestThumbprint): Promise<DeviceCodeResponse> {\n\n const {\n body: {\n user_code: userCode,\n device_code: deviceCode,\n verification_uri: verificationUri,\n expires_in: expiresIn,\n interval,\n message\n }\n } = await this.networkManager.sendPostRequest<ServerDeviceCodeResponse>(\n thumbprint,\n deviceCodeEndpoint,\n {\n body: queryString,\n headers: headers,\n proxyUrl: this.config.systemOptions.proxyUrl\n });\n\n return {\n userCode,\n deviceCode,\n verificationUri,\n expiresIn,\n interval,\n message\n };\n }\n\n /**\n * Create device code endpoint query parameters and returns string\n */\n private createQueryString(request: CommonDeviceCodeRequest): string {\n\n const parameterBuilder: RequestParameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addScopes(request.scopes);\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * Breaks the polling with specific conditions.\n * @param request CommonDeviceCodeRequest\n * @param deviceCodeResponse DeviceCodeResponse\n */\n private continuePolling(\n deviceCodeExpirationTime: number,\n userSpecifiedTimeout?: number,\n userSpecifiedCancelFlag?: boolean,\n ): boolean {\n if (userSpecifiedCancelFlag) {\n this.logger.error(\"Token request cancelled by setting DeviceCodeRequest.cancel = true\");\n throw ClientAuthError.createDeviceCodeCancelledError();\n } else if (userSpecifiedTimeout && userSpecifiedTimeout < deviceCodeExpirationTime && TimeUtils.nowSeconds() > userSpecifiedTimeout) {\n this.logger.error(`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`);\n throw ClientAuthError.createUserTimeoutReachedError();\n } else if (TimeUtils.nowSeconds() > deviceCodeExpirationTime) {\n if (userSpecifiedTimeout) {\n this.logger.verbose(`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`);\n }\n this.logger.error(`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`);\n throw ClientAuthError.createDeviceCodeExpiredError();\n }\n return true;\n }\n\n /**\n * Creates token request with device code response and polls token endpoint at interval set by the device code\n * response\n * @param request\n * @param deviceCodeResponse\n */\n private async acquireTokenWithDeviceCode(\n request: CommonDeviceCodeRequest,\n deviceCodeResponse: DeviceCodeResponse): Promise<ServerAuthorizationTokenResponse> {\n\n const requestBody = this.createTokenRequestBody(request, deviceCodeResponse);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n\n const userSpecifiedTimeout = request.timeout ? TimeUtils.nowSeconds() + request.timeout : undefined;\n const deviceCodeExpirationTime = TimeUtils.nowSeconds() + deviceCodeResponse.expiresIn;\n const pollingIntervalMilli = deviceCodeResponse.interval * 1000;\n\n /*\n * Poll token endpoint while (device code is not expired AND operation has not been cancelled by\n * setting CancellationToken.cancel = true). POST request is sent at interval set by pollingIntervalMilli\n */\n while (this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) {\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n const response = await this.executePostToTokenEndpoint(\n this.authority.tokenEndpoint,\n requestBody,\n headers,\n thumbprint);\n\n if (response.body && response.body.error === Constants.AUTHORIZATION_PENDING) {\n // user authorization is pending. Sleep for polling interval and try again\n this.logger.info(response.body.error_description || \"Authorization pending. Continue polling.\");\n \n await TimeUtils.delay(pollingIntervalMilli);\n } else {\n this.logger.verbose(\"Authorization completed successfully. Polling stopped.\");\n return response.body;\n }\n }\n\n /*\n * The above code should've thrown by this point, but to satisfy TypeScript,\n * and in the rare case the conditionals in continuePolling() may not catch everything...\n */\n this.logger.error(\"Polling stopped for unknown reasons.\");\n throw ClientAuthError.createDeviceCodeUnknownError();\n }\n\n /**\n * Creates query parameters and converts to string.\n * @param request\n * @param deviceCodeResponse\n */\n private createTokenRequestBody(request: CommonDeviceCodeRequest, deviceCodeResponse: DeviceCodeResponse): string {\n\n const requestParameters: RequestParameterBuilder = new RequestParameterBuilder();\n\n requestParameters.addScopes(request.scopes);\n requestParameters.addClientId(this.config.authOptions.clientId);\n requestParameters.addGrantType(GrantType.DEVICE_CODE_GRANT);\n requestParameters.addDeviceCode(deviceCodeResponse.deviceCode);\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n requestParameters.addCorrelationId(correlationId);\n requestParameters.addClientInfo();\n requestParameters.addLibraryInfo(this.config.libraryInfo);\n requestParameters.addApplicationTelemetry(this.config.telemetry.application);\n requestParameters.addThrottling();\n \n if (this.serverTelemetryManager) {\n requestParameters.addServerTelemetry(this.serverTelemetryManager);\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n requestParameters.addClaims(request.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AAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;YAChJ,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;SAC3F;QACD,OAAO,iBAAiB,CAAC,iBAAiB,EAAE,CAAC;KAChD;IACL,uBAAC;AAAD,CAtOA,CAAsC,UAAU;;;;"}
1
+ {"version":3,"file":"DeviceCodeClient.js","sources":["../../src/client/DeviceCodeClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DeviceCodeResponse, ServerDeviceCodeResponse } from \"../response/DeviceCodeResponse\";\nimport { BaseClient } from \"./BaseClient\";\nimport { CommonDeviceCodeRequest } from \"../request/CommonDeviceCodeRequest\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { Constants, GrantType } from \"../utils/Constants\";\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { ServerError } from \"../error/ServerError\";\n\n/**\n * OAuth2.0 Device code client\n */\nexport class DeviceCodeClient extends BaseClient {\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Gets device code from device code endpoint, calls back to with device code response, and\n * polls token endpoint to exchange device code for tokens\n * @param request\n */\n public async acquireToken(request: CommonDeviceCodeRequest): Promise<AuthenticationResult | null> {\n const deviceCodeResponse: DeviceCodeResponse = await this.getDeviceCode(request);\n request.deviceCodeCallback(deviceCodeResponse);\n const reqTimestamp = TimeUtils.nowSeconds();\n const response: ServerAuthorizationTokenResponse = await this.acquireTokenWithDeviceCode(\n request,\n deviceCodeResponse);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n // Validate response. This function throws a server error if an error is returned by the server.\n responseHandler.validateTokenResponse(response);\n return await responseHandler.handleServerTokenResponse(\n response,\n this.authority,\n reqTimestamp,\n request\n );\n }\n\n /**\n * Creates device code request and executes http GET\n * @param request\n */\n private async getDeviceCode(request: CommonDeviceCodeRequest): Promise<DeviceCodeResponse> {\n const queryString = this.createQueryString(request);\n const headers = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n return this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint);\n }\n\n /**\n * Executes POST request to device code endpoint\n * @param deviceCodeEndpoint\n * @param queryString\n * @param headers\n */\n private async executePostRequestToDeviceCodeEndpoint(\n deviceCodeEndpoint: string,\n queryString: string,\n headers: Record<string, string>,\n thumbprint: RequestThumbprint): Promise<DeviceCodeResponse> {\n\n const {\n body: {\n user_code: userCode,\n device_code: deviceCode,\n verification_uri: verificationUri,\n expires_in: expiresIn,\n interval,\n message\n }\n } = await this.networkManager.sendPostRequest<ServerDeviceCodeResponse>(\n thumbprint,\n deviceCodeEndpoint,\n {\n body: queryString,\n headers: headers,\n proxyUrl: this.config.systemOptions.proxyUrl\n });\n\n return {\n userCode,\n deviceCode,\n verificationUri,\n expiresIn,\n interval,\n message\n };\n }\n\n /**\n * Create device code endpoint query parameters and returns string\n */\n private createQueryString(request: CommonDeviceCodeRequest): string {\n\n const parameterBuilder: RequestParameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addScopes(request.scopes);\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * Breaks the polling with specific conditions.\n * @param request CommonDeviceCodeRequest\n * @param deviceCodeResponse DeviceCodeResponse\n */\n private continuePolling(\n deviceCodeExpirationTime: number,\n userSpecifiedTimeout?: number,\n userSpecifiedCancelFlag?: boolean,\n ): boolean {\n if (userSpecifiedCancelFlag) {\n this.logger.error(\"Token request cancelled by setting DeviceCodeRequest.cancel = true\");\n throw ClientAuthError.createDeviceCodeCancelledError();\n } else if (userSpecifiedTimeout && userSpecifiedTimeout < deviceCodeExpirationTime && TimeUtils.nowSeconds() > userSpecifiedTimeout) {\n this.logger.error(`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`);\n throw ClientAuthError.createUserTimeoutReachedError();\n } else if (TimeUtils.nowSeconds() > deviceCodeExpirationTime) {\n if (userSpecifiedTimeout) {\n this.logger.verbose(`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`);\n }\n this.logger.error(`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`);\n throw ClientAuthError.createDeviceCodeExpiredError();\n }\n return true;\n }\n\n /**\n * Creates token request with device code response and polls token endpoint at interval set by the device code\n * response\n * @param request\n * @param deviceCodeResponse\n */\n private async acquireTokenWithDeviceCode(\n request: CommonDeviceCodeRequest,\n deviceCodeResponse: DeviceCodeResponse): Promise<ServerAuthorizationTokenResponse> {\n\n const requestBody = this.createTokenRequestBody(request, deviceCodeResponse);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n\n const userSpecifiedTimeout = request.timeout ? TimeUtils.nowSeconds() + request.timeout : undefined;\n const deviceCodeExpirationTime = TimeUtils.nowSeconds() + deviceCodeResponse.expiresIn;\n const pollingIntervalMilli = deviceCodeResponse.interval * 1000;\n\n /*\n * Poll token endpoint while (device code is not expired AND operation has not been cancelled by\n * setting CancellationToken.cancel = true). POST request is sent at interval set by pollingIntervalMilli\n */\n while (this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) {\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n const response = await this.executePostToTokenEndpoint(\n this.authority.tokenEndpoint,\n requestBody,\n headers,\n thumbprint);\n\n if (response.body && response.body.error) {\n // user authorization is pending. Sleep for polling interval and try again\n if(response.body.error === Constants.AUTHORIZATION_PENDING) {\n this.logger.info(\"Authorization pending. Continue polling.\");\n await TimeUtils.delay(pollingIntervalMilli);\n } else {\n // for any other error, throw\n this.logger.info(\"Unexpected error in polling from the server\");\n throw ServerError.createPostRequestFailed(response.body.error);\n }\n } else {\n this.logger.verbose(\"Authorization completed successfully. Polling stopped.\");\n return response.body;\n }\n }\n\n /*\n * The above code should've thrown by this point, but to satisfy TypeScript,\n * and in the rare case the conditionals in continuePolling() may not catch everything...\n */\n this.logger.error(\"Polling stopped for unknown reasons.\");\n throw ClientAuthError.createDeviceCodeUnknownError();\n }\n\n /**\n * Creates query parameters and converts to string.\n * @param request\n * @param deviceCodeResponse\n */\n private createTokenRequestBody(request: CommonDeviceCodeRequest, deviceCodeResponse: DeviceCodeResponse): string {\n\n const requestParameters: RequestParameterBuilder = new RequestParameterBuilder();\n\n requestParameters.addScopes(request.scopes);\n requestParameters.addClientId(this.config.authOptions.clientId);\n requestParameters.addGrantType(GrantType.DEVICE_CODE_GRANT);\n requestParameters.addDeviceCode(deviceCodeResponse.deviceCode);\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n requestParameters.addCorrelationId(correlationId);\n requestParameters.addClientInfo();\n requestParameters.addLibraryInfo(this.config.libraryInfo);\n requestParameters.addApplicationTelemetry(this.config.telemetry.application);\n requestParameters.addThrottling();\n \n if (this.serverTelemetryManager) {\n requestParameters.addServerTelemetry(this.serverTelemetryManager);\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n requestParameters.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n return requestParameters.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAiBH;;AAEG;AACH,IAAA,gBAAA,kBAAA,UAAA,MAAA,EAAA;IAAsC,SAAU,CAAA,gBAAA,EAAA,MAAA,CAAA,CAAA;AAE5C,IAAA,SAAA,gBAAA,CAAY,aAAkC,EAAA;AAC1C,QAAA,OAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAM,aAAa,CAAC,IAAA,IAAA,CAAA;KACvB;AAED;;;;AAIG;IACU,gBAAY,CAAA,SAAA,CAAA,YAAA,GAAzB,UAA0B,OAAgC,EAAA;;;;;AACP,oBAAA,KAAA,CAAA,EAAA,OAAA,CAAA,CAAA,YAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA,CAAA;;AAA1E,wBAAA,kBAAkB,GAAuB,EAAiC,CAAA,IAAA,EAAA,CAAA;AAChF,wBAAA,OAAO,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AACzC,wBAAA,YAAY,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;wBACO,OAAM,CAAA,CAAA,YAAA,IAAI,CAAC,0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,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;AAC3F,SAAA;AACD,QAAA,OAAO,iBAAiB,CAAC,iBAAiB,EAAE,CAAC;KAChD,CAAA;IACL,OAAC,gBAAA,CAAA;AAAD,CA5OA,CAAsC,UAAU,CA4O/C;;;;"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v7.1.0 2022-07-05 */
1
+ /*! @azure/msal-common v7.4.0 2022-09-06 */
2
2
  'use strict';
3
3
  import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { BaseClient } from './BaseClient.js';
@@ -1 +1 @@
1
- {"version":3,"file":"OnBehalfOfClient.js","sources":["../../src/client/OnBehalfOfClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType, AADServerParamKeys , CredentialType, Constants, CacheOutcome, AuthenticationScheme } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonOnBehalfOfRequest } from \"../request/CommonOnBehalfOfRequest\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { AccountInfo } from \"../account/AccountInfo\";\n\n/**\n * On-Behalf-Of client\n */\nexport class OnBehalfOfClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n private userAssertionHash: string;\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Public API to acquire tokens with on behalf of flow\n * @param request\n */\n public async acquireToken(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n // generate the user_assertion_hash for OBOAssertion\n this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);\n }\n\n try {\n return await this.getCachedAuthenticationResult(request);\n } catch (e) {\n // Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT\n return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);\n }\n }\n\n /**\n * look up cache for tokens\n * Find idtoken in the cache\n * Find accessToken based on user assertion and account info in the cache\n * Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires\n * This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session\n * @param request\n */\n private async getCachedAuthenticationResult(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n\n // look in the cache for the access_token which matches the incoming_assertion\n const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);\n if (!cachedAccessToken) {\n // Must refresh due to non-existent access_token.\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n this.logger.info(\"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.\");\n throw ClientAuthError.createRefreshRequiredError();\n } else if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n // Access token expired, will need to renewed\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);\n this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);\n throw ClientAuthError.createRefreshRequiredError();\n }\n\n // fetch the idToken from cache\n const cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);\n let idTokenObject: AuthToken | undefined;\n let cachedAccount: AccountEntity | null = null;\n if (cachedIdToken) {\n idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);\n const localAccountId = idTokenObject.claims.oid ? idTokenObject.claims.oid : idTokenObject.claims.sub;\n const accountInfo: AccountInfo = {\n homeAccountId: cachedIdToken.homeAccountId,\n environment: cachedIdToken.environment,\n tenantId: cachedIdToken.realm,\n username: Constants.EMPTY_STRING,\n localAccountId: localAccountId || Constants.EMPTY_STRING\n };\n\n cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);\n }\n\n // increment telemetry cache hit counter\n if (this.config.serverTelemetryManager) {\n this.config.serverTelemetryManager.incrementCacheHits();\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: cachedAccount,\n accessToken: cachedAccessToken,\n idToken: cachedIdToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request,\n idTokenObject);\n }\n\n /**\n * read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager\n * Certain use cases of OBO flow do not expect an idToken in the cache/or from the service\n * @param request\n */\n private readIdTokenFromCacheForOBO(request: CommonOnBehalfOfRequest, atHomeAccountId: string): IdTokenEntity | null {\n\n const idTokenFilter: CredentialFilter = {\n homeAccountId: atHomeAccountId,\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ID_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);\n const idTokens = Object.keys(credentialCache.idTokens).map(key => credentialCache.idTokens[key]);\n // When acquiring a token on behalf of an application, there might not be an id token in the cache\n if (idTokens.length < 1) {\n return null;\n }\n return idTokens[0] as IdTokenEntity;\n }\n\n /**\n * Fetches the cached access token based on incoming assertion\n * @param clientId\n * @param request\n * @param userAssertionHash\n */\n private readAccessTokenFromCacheForOBO(clientId: string, request: CommonOnBehalfOfRequest) {\n const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;\n /*\n * Distinguish between Bearer and PoP/SSH token cache types\n * Cast to lowercase to handle \"bearer\" from ADFS\n */\n const credentialType = (authScheme && authScheme.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;\n\n const accessTokenFilter: CredentialFilter = {\n credentialType: credentialType,\n clientId,\n target: this.scopeSet.printScopesLowerCase(),\n tokenType: authScheme,\n keyId: request.sshKid,\n requestedClaimsHash: request.requestedClaimsHash,\n userAssertionHash: this.userAssertionHash\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n\n const accessTokens = Object.keys(credentialCache.accessTokens).map((key) => credentialCache.accessTokens[key]);\n\n const numAccessTokens = accessTokens.length;\n if (numAccessTokens < 1) {\n return null;\n } else if (numAccessTokens > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * Make a network call to the server requesting credentials\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonOnBehalfOfRequest, authority: Authority, userAssertionHash: string)\n : Promise<AuthenticationResult | null> {\n\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(response.body);\n const tokenResponse = await responseHandler.handleServerTokenResponse(\n response.body,\n this.authority,\n reqTimestamp,\n request,\n undefined,\n userAssertionHash\n );\n\n return tokenResponse;\n }\n\n /**\n * generate a server request in accepable format\n * @param request\n */\n private createTokenRequestBody(request: CommonOnBehalfOfRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes);\n\n parameterBuilder.addGrantType(GrantType.JWT_BEARER);\n\n parameterBuilder.addClientInfo();\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n parameterBuilder.addThrottling();\n\n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n parameterBuilder.addRequestTokenUse(AADServerParamKeys.ON_BEHALF_OF);\n\n parameterBuilder.addOboAssertion(request.oboAssertion);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n if (this.config.clientCredentials.clientAssertion) {\n const clientAssertion = this.config.clientCredentials.clientAssertion;\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAwBA;;;;IAGsC,oCAAU;IAK5C,0BAAY,aAAkC;eAC1C,kBAAM,aAAa,CAAC;KAC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M,CAAC,WAAW,CAAC,CAAC;QACzD,gBAAgB,CAAC,uBAAuB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5E,gBAAgB,CAAC,aAAa,EAAE,CAAC;QAEjC,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC7B,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;SACpE;QAED,IAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;QAC3F,gBAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAEjD,gBAAgB,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAErE,gBAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAEvD,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE;YAC5C,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;SAChF;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,EAAE;YAC/C,IAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,CAAC;YACtE,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAC/D,gBAAgB,CAAC,sBAAsB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;SAC1E;QAED,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C;IACL,uBAAC;AAAD,CApPA,CAAsC,UAAU;;;;"}
1
+ {"version":3,"file":"OnBehalfOfClient.js","sources":["../../src/client/OnBehalfOfClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType, AADServerParamKeys , CredentialType, Constants, CacheOutcome, AuthenticationScheme } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonOnBehalfOfRequest } from \"../request/CommonOnBehalfOfRequest\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { AccountInfo } from \"../account/AccountInfo\";\n\n/**\n * On-Behalf-Of client\n */\nexport class OnBehalfOfClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n private userAssertionHash: string;\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Public API to acquire tokens with on behalf of flow\n * @param request\n */\n public async acquireToken(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n // generate the user_assertion_hash for OBOAssertion\n this.userAssertionHash = await this.cryptoUtils.hashString(request.oboAssertion);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);\n }\n\n try {\n return await this.getCachedAuthenticationResult(request);\n } catch (e) {\n // Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT\n return await this.executeTokenRequest(request, this.authority, this.userAssertionHash);\n }\n }\n\n /**\n * look up cache for tokens\n * Find idtoken in the cache\n * Find accessToken based on user assertion and account info in the cache\n * Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires\n * This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session\n * @param request\n */\n private async getCachedAuthenticationResult(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n\n // look in the cache for the access_token which matches the incoming_assertion\n const cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);\n if (!cachedAccessToken) {\n // Must refresh due to non-existent access_token.\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n this.logger.info(\"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.\");\n throw ClientAuthError.createRefreshRequiredError();\n } else if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n // Access token expired, will need to renewed\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);\n this.logger.info(`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);\n throw ClientAuthError.createRefreshRequiredError();\n }\n\n // fetch the idToken from cache\n const cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);\n let idTokenObject: AuthToken | undefined;\n let cachedAccount: AccountEntity | null = null;\n if (cachedIdToken) {\n idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);\n const localAccountId = idTokenObject.claims.oid ? idTokenObject.claims.oid : idTokenObject.claims.sub;\n const accountInfo: AccountInfo = {\n homeAccountId: cachedIdToken.homeAccountId,\n environment: cachedIdToken.environment,\n tenantId: cachedIdToken.realm,\n username: Constants.EMPTY_STRING,\n localAccountId: localAccountId || Constants.EMPTY_STRING\n };\n\n cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);\n }\n\n // increment telemetry cache hit counter\n if (this.config.serverTelemetryManager) {\n this.config.serverTelemetryManager.incrementCacheHits();\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: cachedAccount,\n accessToken: cachedAccessToken,\n idToken: cachedIdToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request,\n idTokenObject);\n }\n\n /**\n * read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager\n * Certain use cases of OBO flow do not expect an idToken in the cache/or from the service\n * @param request\n */\n private readIdTokenFromCacheForOBO(request: CommonOnBehalfOfRequest, atHomeAccountId: string): IdTokenEntity | null {\n\n const idTokenFilter: CredentialFilter = {\n homeAccountId: atHomeAccountId,\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ID_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);\n const idTokens = Object.keys(credentialCache.idTokens).map(key => credentialCache.idTokens[key]);\n // When acquiring a token on behalf of an application, there might not be an id token in the cache\n if (idTokens.length < 1) {\n return null;\n }\n return idTokens[0] as IdTokenEntity;\n }\n\n /**\n * Fetches the cached access token based on incoming assertion\n * @param clientId\n * @param request\n * @param userAssertionHash\n */\n private readAccessTokenFromCacheForOBO(clientId: string, request: CommonOnBehalfOfRequest) {\n const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;\n /*\n * Distinguish between Bearer and PoP/SSH token cache types\n * Cast to lowercase to handle \"bearer\" from ADFS\n */\n const credentialType = (authScheme && authScheme.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;\n\n const accessTokenFilter: CredentialFilter = {\n credentialType: credentialType,\n clientId,\n target: this.scopeSet.printScopesLowerCase(),\n tokenType: authScheme,\n keyId: request.sshKid,\n requestedClaimsHash: request.requestedClaimsHash,\n userAssertionHash: this.userAssertionHash\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n\n const accessTokens = Object.keys(credentialCache.accessTokens).map((key) => credentialCache.accessTokens[key]);\n\n const numAccessTokens = accessTokens.length;\n if (numAccessTokens < 1) {\n return null;\n } else if (numAccessTokens > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * Make a network call to the server requesting credentials\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonOnBehalfOfRequest, authority: Authority, userAssertionHash: string)\n : Promise<AuthenticationResult | null> {\n\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(response.body);\n const tokenResponse = await responseHandler.handleServerTokenResponse(\n response.body,\n this.authority,\n reqTimestamp,\n request,\n undefined,\n userAssertionHash\n );\n\n return tokenResponse;\n }\n\n /**\n * generate a server request in accepable format\n * @param request\n */\n private createTokenRequestBody(request: CommonOnBehalfOfRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes);\n\n parameterBuilder.addGrantType(GrantType.JWT_BEARER);\n\n parameterBuilder.addClientInfo();\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n parameterBuilder.addThrottling();\n\n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n parameterBuilder.addRequestTokenUse(AADServerParamKeys.ON_BEHALF_OF);\n\n parameterBuilder.addOboAssertion(request.oboAssertion);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n if (this.config.clientCredentials.clientAssertion) {\n const clientAssertion = this.config.clientCredentials.clientAssertion;\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAqBH;;AAEG;AACH,IAAA,gBAAA,kBAAA,UAAA,MAAA,EAAA;IAAsC,SAAU,CAAA,gBAAA,EAAA,MAAA,CAAA,CAAA;AAK5C,IAAA,SAAA,gBAAA,CAAY,aAAkC,EAAA;AAC1C,QAAA,OAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAM,aAAa,CAAC,IAAA,IAAA,CAAA;KACvB;AAED;;;AAGG;IACU,gBAAY,CAAA,SAAA,CAAA,YAAA,GAAzB,UAA0B,OAAgC,EAAA;;;;;;AACtD,wBAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;;AAGnD,wBAAA,EAAA,GAAA,IAAI,CAAA;wBAAqB,OAAM,CAAA,CAAA,YAAA,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA,CAAA;;;wBAAhF,EAAK,CAAA,iBAAiB,GAAG,EAA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I,CAAC,sBAAsB,CAAC,CAAC;AACpE,SAAA;AAED,QAAA,IAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;AAC3F,QAAA,gBAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;AAEjD,QAAA,gBAAgB,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAErE,QAAA,gBAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAEvD,QAAA,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE;YAC5C,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAChF,SAAA;AAED,QAAA,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,EAAE;YAC/C,IAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,CAAC;AACtE,YAAA,gBAAgB,CAAC,kBAAkB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;AAC/D,YAAA,gBAAgB,CAAC,sBAAsB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAC1E,SAAA;AAED,QAAA,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C,CAAA;IACL,OAAC,gBAAA,CAAA;AAAD,CApPA,CAAsC,UAAU,CAoP/C;;;;"}
@@ -3,11 +3,12 @@ import { BaseClient } from "./BaseClient";
3
3
  import { CommonRefreshTokenRequest } from "../request/CommonRefreshTokenRequest";
4
4
  import { AuthenticationResult } from "../response/AuthenticationResult";
5
5
  import { CommonSilentFlowRequest } from "../request/CommonSilentFlowRequest";
6
+ import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
6
7
  /**
7
8
  * OAuth2.0 refresh token client
8
9
  */
9
10
  export declare class RefreshTokenClient extends BaseClient {
10
- constructor(configuration: ClientConfiguration);
11
+ constructor(configuration: ClientConfiguration, performanceClient?: IPerformanceClient);
11
12
  acquireToken(request: CommonRefreshTokenRequest): Promise<AuthenticationResult>;
12
13
  /**
13
14
  * Gets cached refresh token and attaches to request, then calls acquireToken API
@@ -1 +1 @@
1
- {"version":3,"file":"RefreshTokenClient.d.ts","sourceRoot":"","sources":["../../src/client/RefreshTokenClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAU7E;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;gBAElC,aAAa,EAAE,mBAAmB;IAIjC,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAyB5F;;;OAGG;IACU,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCxG;;;OAGG;YACW,kCAAkC;IAsBhD;;;;OAIG;YACW,mBAAmB;IAsBjC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAUlC;;;OAGG;YACW,sBAAsB;CAqEvC"}
1
+ {"version":3,"file":"RefreshTokenClient.d.ts","sourceRoot":"","sources":["../../src/client/RefreshTokenClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAS7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAGjF;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;gBAClC,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,EAAE,kBAAkB;IAIzE,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0B5F;;;OAGG;IACU,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCxG;;;OAGG;YACW,kCAAkC;IAsBhD;;;;OAIG;YACW,mBAAmB;IAkCjC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAUlC;;;OAGG;YACW,sBAAsB;CA2EvC"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v7.1.0 2022-07-05 */
1
+ /*! @azure/msal-common v7.4.0 2022-09-06 */
2
2
  'use strict';
3
3
  import { __extends, __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
4
4
  import { BaseClient } from './BaseClient.js';
@@ -15,6 +15,7 @@ import { UrlString } from '../url/UrlString.js';
15
15
  import { CcsCredentialType } from '../account/CcsCredential.js';
16
16
  import { buildClientInfoFromHomeAccountId } from '../account/ClientInfo.js';
17
17
  import { InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage } from '../error/InteractionRequiredAuthError.js';
18
+ import { PerformanceEvents } from '../telemetry/performance/PerformanceEvent.js';
18
19
 
19
20
  /*
20
21
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -25,8 +26,8 @@ import { InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage } fro
25
26
  */
26
27
  var RefreshTokenClient = /** @class */ (function (_super) {
27
28
  __extends(RefreshTokenClient, _super);
28
- function RefreshTokenClient(configuration) {
29
- return _super.call(this, configuration) || this;
29
+ function RefreshTokenClient(configuration, performanceClient) {
30
+ return _super.call(this, configuration, performanceClient) || this;
30
31
  }
31
32
  RefreshTokenClient.prototype.acquireToken = function (request) {
32
33
  return __awaiter(this, void 0, void 0, function () {
@@ -40,7 +41,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
40
41
  response = _a.sent();
41
42
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
42
43
  responseHandler.validateTokenResponse(response.body);
43
- return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true)];
44
+ return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache)];
44
45
  }
45
46
  });
46
47
  });
@@ -112,13 +113,16 @@ var RefreshTokenClient = /** @class */ (function (_super) {
112
113
  * @param authority
113
114
  */
114
115
  RefreshTokenClient.prototype.executeTokenRequest = function (request, authority) {
116
+ var _a;
115
117
  return __awaiter(this, void 0, void 0, function () {
116
- var requestBody, queryParameters, headers, thumbprint, endpoint;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0: return [4 /*yield*/, this.createTokenRequestBody(request)];
118
+ var acquireTokenMeasurement, requestBody, queryParameters, headers, thumbprint, endpoint;
119
+ return __generator(this, function (_b) {
120
+ switch (_b.label) {
121
+ case 0:
122
+ acquireTokenMeasurement = (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.startMeasurement(PerformanceEvents.RefreshTokenClientExecuteTokenRequest, request.correlationId);
123
+ return [4 /*yield*/, this.createTokenRequestBody(request)];
120
124
  case 1:
121
- requestBody = _a.sent();
125
+ requestBody = _b.sent();
122
126
  queryParameters = this.createTokenQueryParameters(request);
123
127
  headers = this.createTokenRequestHeaders(request.ccsCredential);
124
128
  thumbprint = {
@@ -133,7 +137,19 @@ var RefreshTokenClient = /** @class */ (function (_super) {
133
137
  sshKid: request.sshKid
134
138
  };
135
139
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
136
- return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
140
+ return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)
141
+ .then(function (result) {
142
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
143
+ success: true
144
+ });
145
+ return result;
146
+ })
147
+ .catch(function (error) {
148
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
149
+ success: false
150
+ });
151
+ throw error;
152
+ })];
137
153
  }
138
154
  });
139
155
  });
@@ -154,11 +170,14 @@ var RefreshTokenClient = /** @class */ (function (_super) {
154
170
  * @param request
155
171
  */
156
172
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
173
+ var _a;
157
174
  return __awaiter(this, void 0, void 0, function () {
158
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
175
+ var correlationId, acquireTokenMeasurement, parameterBuilder, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
176
+ return __generator(this, function (_b) {
177
+ switch (_b.label) {
161
178
  case 0:
179
+ correlationId = request.correlationId;
180
+ acquireTokenMeasurement = (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.startMeasurement(PerformanceEvents.BaseClientCreateTokenRequestHeaders, correlationId);
162
181
  parameterBuilder = new RequestParameterBuilder();
163
182
  parameterBuilder.addClientId(this.config.authOptions.clientId);
164
183
  parameterBuilder.addScopes(request.scopes);
@@ -170,7 +189,6 @@ var RefreshTokenClient = /** @class */ (function (_super) {
170
189
  if (this.serverTelemetryManager) {
171
190
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
172
191
  }
173
- correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
174
192
  parameterBuilder.addCorrelationId(correlationId);
175
193
  parameterBuilder.addRefreshToken(request.refreshToken);
176
194
  if (this.config.clientCredentials.clientSecret) {
@@ -185,7 +203,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
185
203
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
186
204
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
187
205
  case 1:
188
- reqCnfData = _a.sent();
206
+ reqCnfData = _b.sent();
189
207
  // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
190
208
  parameterBuilder.addPopToken(reqCnfData.reqCnfString);
191
209
  return [3 /*break*/, 3];
@@ -195,10 +213,13 @@ var RefreshTokenClient = /** @class */ (function (_super) {
195
213
  parameterBuilder.addSshJwk(request.sshJwk);
196
214
  }
197
215
  else {
216
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
217
+ success: false
218
+ });
198
219
  throw ClientConfigurationError.createMissingSshJwkError();
199
220
  }
200
221
  }
201
- _a.label = 3;
222
+ _b.label = 3;
202
223
  case 3:
203
224
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
204
225
  parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
@@ -219,6 +240,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
219
240
  break;
220
241
  }
221
242
  }
243
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
244
+ success: true
245
+ });
222
246
  return [2 /*return*/, parameterBuilder.createQueryString()];
223
247
  }
224
248
  });