@azure/msal-node 1.0.0-beta.1 → 1.0.0-beta.2

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.
@@ -1,4 +1,4 @@
1
- import { ProtocolMode, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, ThrottlingEntity, TokenCacheContext, Constants as Constants$1, ServerTelemetryManager, Logger, TrustedAuthority, AuthorityFactory, AuthorizationCodeClient, RefreshTokenClient, SilentFlowClient, ClientAuthError, DeviceCodeClient, UsernamePasswordClient, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
1
+ import { Constants as Constants$1, ProtocolMode, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, ThrottlingEntity, TokenCacheContext, ServerTelemetryManager, Logger, TrustedAuthority, AuthorityFactory, AuthorizationCodeClient, ResponseMode, AuthenticationScheme, RefreshTokenClient, SilentFlowClient, ClientAuthError, DeviceCodeClient, UsernamePasswordClient, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
2
2
  export { AuthError, AuthErrorMessage, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
3
3
  import axios from 'axios';
4
4
  import { v4 } from 'uuid';
@@ -1041,7 +1041,7 @@ var NetworkUtils = /*#__PURE__*/function () {
1041
1041
 
1042
1042
  var DEFAULT_AUTH_OPTIONS = {
1043
1043
  clientId: "",
1044
- authority: "",
1044
+ authority: Constants$1.DEFAULT_AUTHORITY,
1045
1045
  clientSecret: "",
1046
1046
  clientAssertion: "",
1047
1047
  clientCertificate: {
@@ -1666,10 +1666,10 @@ var Serializer = /*#__PURE__*/function () {
1666
1666
  var Storage = /*#__PURE__*/function (_CacheManager) {
1667
1667
  _inheritsLoose(Storage, _CacheManager);
1668
1668
 
1669
- function Storage(logger) {
1669
+ function Storage(logger, clientId, cryptoImpl) {
1670
1670
  var _this;
1671
1671
 
1672
- _this = _CacheManager.call(this) || this;
1672
+ _this = _CacheManager.call(this, clientId, cryptoImpl) || this;
1673
1673
  _this.cache = {};
1674
1674
  _this.changeEmitters = [];
1675
1675
  _this.logger = logger;
@@ -2410,11 +2410,11 @@ var TokenCache = /*#__PURE__*/function () {
2410
2410
 
2411
2411
  _proto.mergeRemovals = function mergeRemovals(oldState, newState) {
2412
2412
  this.logger.verbose("Remove updated entries in cache");
2413
- var accounts = oldState.Account != null ? this.mergeRemovalsDict(oldState.Account, newState.Account) : oldState.Account;
2414
- var accessTokens = oldState.AccessToken != null ? this.mergeRemovalsDict(oldState.AccessToken, newState.AccessToken) : oldState.AccessToken;
2415
- var refreshTokens = oldState.RefreshToken != null ? this.mergeRemovalsDict(oldState.RefreshToken, newState.RefreshToken) : oldState.RefreshToken;
2416
- var idTokens = oldState.IdToken != null ? this.mergeRemovalsDict(oldState.IdToken, newState.IdToken) : oldState.IdToken;
2417
- var appMetadata = oldState.AppMetadata != null ? this.mergeRemovalsDict(oldState.AppMetadata, newState.AppMetadata) : oldState.AppMetadata;
2413
+ var accounts = oldState.Account ? this.mergeRemovalsDict(oldState.Account, newState.Account) : oldState.Account;
2414
+ var accessTokens = oldState.AccessToken ? this.mergeRemovalsDict(oldState.AccessToken, newState.AccessToken) : oldState.AccessToken;
2415
+ var refreshTokens = oldState.RefreshToken ? this.mergeRemovalsDict(oldState.RefreshToken, newState.RefreshToken) : oldState.RefreshToken;
2416
+ var idTokens = oldState.IdToken ? this.mergeRemovalsDict(oldState.IdToken, newState.IdToken) : oldState.IdToken;
2417
+ var appMetadata = oldState.AppMetadata ? this.mergeRemovalsDict(oldState.AppMetadata, newState.AppMetadata) : oldState.AppMetadata;
2418
2418
  return _extends({}, oldState, {
2419
2419
  Account: accounts,
2420
2420
  AccessToken: accessTokens,
@@ -2449,7 +2449,8 @@ var TokenCache = /*#__PURE__*/function () {
2449
2449
  return TokenCache;
2450
2450
  }();
2451
2451
 
2452
- var version = "1.0.0-beta.1";
2452
+ var name = "@azure/msal-node";
2453
+ var version = "1.0.0-beta.2";
2453
2454
 
2454
2455
  var ClientApplication = /*#__PURE__*/function () {
2455
2456
  /**
@@ -2457,10 +2458,10 @@ var ClientApplication = /*#__PURE__*/function () {
2457
2458
  */
2458
2459
  function ClientApplication(configuration) {
2459
2460
  this.config = buildAppConfiguration(configuration);
2460
- this.logger = new Logger(this.config.system.loggerOptions);
2461
- this.storage = new Storage(this.logger);
2462
- this.tokenCache = new TokenCache(this.storage, this.logger, this.config.cache.cachePlugin);
2463
2461
  this.cryptoProvider = new CryptoProvider();
2462
+ this.logger = new Logger(this.config.system.loggerOptions, name, version);
2463
+ this.storage = new Storage(this.logger, this.config.auth.clientId, this.cryptoProvider);
2464
+ this.tokenCache = new TokenCache(this.storage, this.logger, this.config.cache.cachePlugin);
2464
2465
  TrustedAuthority.setTrustedAuthoritiesFromConfig(this.config.auth.knownAuthorities, this.config.auth.cloudDiscoveryMetadata);
2465
2466
  }
2466
2467
  /**
@@ -2480,22 +2481,26 @@ var ClientApplication = /*#__PURE__*/function () {
2480
2481
  /*#__PURE__*/
2481
2482
  function () {
2482
2483
  var _getAuthCodeUrl = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(request) {
2483
- var authClientConfig, authorizationCodeClient;
2484
+ var validRequest, authClientConfig, authorizationCodeClient;
2484
2485
  return runtime_1.wrap(function _callee$(_context) {
2485
2486
  while (1) {
2486
2487
  switch (_context.prev = _context.next) {
2487
2488
  case 0:
2488
2489
  this.logger.info("getAuthCodeUrl called");
2489
- _context.next = 3;
2490
- return this.buildOauthClientConfiguration(request.authority);
2490
+ validRequest = _extends({}, request, this.initializeBaseRequest(request), {
2491
+ responseMode: request.responseMode || ResponseMode.QUERY,
2492
+ authenticationScheme: AuthenticationScheme.BEARER
2493
+ });
2494
+ _context.next = 4;
2495
+ return this.buildOauthClientConfiguration(validRequest.authority);
2491
2496
 
2492
- case 3:
2497
+ case 4:
2493
2498
  authClientConfig = _context.sent;
2494
2499
  this.logger.verbose("Auth client config generated");
2495
2500
  authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
2496
- return _context.abrupt("return", authorizationCodeClient.getAuthCodeUrl(this.initializeRequest(request)));
2501
+ return _context.abrupt("return", authorizationCodeClient.getAuthCodeUrl(validRequest));
2497
2502
 
2498
- case 7:
2503
+ case 8:
2499
2504
  case "end":
2500
2505
  return _context.stop();
2501
2506
  }
@@ -2529,11 +2534,13 @@ var ClientApplication = /*#__PURE__*/function () {
2529
2534
  switch (_context2.prev = _context2.next) {
2530
2535
  case 0:
2531
2536
  this.logger.info("acquireTokenByCode called");
2532
- validRequest = this.initializeRequest(request);
2537
+ validRequest = _extends({}, request, this.initializeBaseRequest(request), {
2538
+ authenticationScheme: AuthenticationScheme.BEARER
2539
+ });
2533
2540
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
2534
2541
  _context2.prev = 3;
2535
2542
  _context2.next = 6;
2536
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
2543
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
2537
2544
 
2538
2545
  case 6:
2539
2546
  authClientConfig = _context2.sent;
@@ -2580,11 +2587,13 @@ var ClientApplication = /*#__PURE__*/function () {
2580
2587
  switch (_context3.prev = _context3.next) {
2581
2588
  case 0:
2582
2589
  this.logger.info("acquireTokenByRefreshToken called");
2583
- validRequest = this.initializeRequest(request);
2590
+ validRequest = _extends({}, request, this.initializeBaseRequest(request), {
2591
+ authenticationScheme: AuthenticationScheme.BEARER
2592
+ });
2584
2593
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
2585
2594
  _context3.prev = 3;
2586
2595
  _context3.next = 6;
2587
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
2596
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
2588
2597
 
2589
2598
  case 6:
2590
2599
  refreshTokenClientConfig = _context3.sent;
@@ -2631,11 +2640,13 @@ var ClientApplication = /*#__PURE__*/function () {
2631
2640
  while (1) {
2632
2641
  switch (_context4.prev = _context4.next) {
2633
2642
  case 0:
2634
- validRequest = this.initializeRequest(request);
2643
+ validRequest = _extends({}, request, this.initializeBaseRequest(request), {
2644
+ forceRefresh: request.forceRefresh || false
2645
+ });
2635
2646
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
2636
2647
  _context4.prev = 2;
2637
2648
  _context4.next = 5;
2638
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
2649
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
2639
2650
 
2640
2651
  case 5:
2641
2652
  silentFlowClientConfig = _context4.sent;
@@ -2775,11 +2786,12 @@ var ClientApplication = /*#__PURE__*/function () {
2775
2786
  */
2776
2787
  ;
2777
2788
 
2778
- _proto.initializeRequest = function initializeRequest(authRequest) {
2789
+ _proto.initializeBaseRequest = function initializeBaseRequest(authRequest) {
2779
2790
  this.logger.verbose("initializeRequestScopes called");
2780
2791
  return _extends({}, authRequest, {
2781
2792
  scopes: [].concat(authRequest && authRequest.scopes || [], [Constants$1.OPENID_SCOPE, Constants$1.PROFILE_SCOPE, Constants$1.OFFLINE_ACCESS_SCOPE]),
2782
- correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid()
2793
+ correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
2794
+ authority: authRequest.authority || this.config.auth.authority
2783
2795
  });
2784
2796
  };
2785
2797
 
@@ -2810,11 +2822,11 @@ var ClientApplication = /*#__PURE__*/function () {
2810
2822
  case 0:
2811
2823
  this.logger.verbose("createAuthority called");
2812
2824
 
2813
- if (authorityString) {
2825
+ if (this.authority.canonicalAuthority !== authorityString) {
2814
2826
  this.logger.verbose("Authority passed in, creating authority instance");
2815
2827
  authority = AuthorityFactory.createInstance(authorityString, this.config.system.networkClient, this.config.auth.protocolMode);
2816
2828
  } else {
2817
- this.logger.verbose("No authority passed in request, defaulting to authority set on application object");
2829
+ this.logger.verbose("Authority on request is the same as on application object, defaulting to authority set on application object");
2818
2830
  authority = this.authority;
2819
2831
  }
2820
2832
 
@@ -2860,7 +2872,7 @@ var ClientApplication = /*#__PURE__*/function () {
2860
2872
  return this._authority;
2861
2873
  }
2862
2874
 
2863
- this._authority = AuthorityFactory.createInstance(this.config.auth.authority || Constants$1.DEFAULT_AUTHORITY, this.config.system.networkClient, this.config.auth.protocolMode);
2875
+ this._authority = AuthorityFactory.createInstance(this.config.auth.authority, this.config.system.networkClient, this.config.auth.protocolMode);
2864
2876
  return this._authority;
2865
2877
  }
2866
2878
  }]);
@@ -2919,11 +2931,11 @@ var PublicClientApplication = /*#__PURE__*/function (_ClientApplication) {
2919
2931
  switch (_context.prev = _context.next) {
2920
2932
  case 0:
2921
2933
  this.logger.info("acquireTokenByDeviceCode called");
2922
- validRequest = this.initializeRequest(request);
2934
+ validRequest = _extends({}, request, this.initializeBaseRequest(request));
2923
2935
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
2924
2936
  _context.prev = 3;
2925
2937
  _context.next = 6;
2926
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
2938
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
2927
2939
 
2928
2940
  case 6:
2929
2941
  deviceCodeConfig = _context.sent;
@@ -2973,11 +2985,11 @@ var PublicClientApplication = /*#__PURE__*/function (_ClientApplication) {
2973
2985
  switch (_context2.prev = _context2.next) {
2974
2986
  case 0:
2975
2987
  this.logger.info("acquireTokenByUsernamePassword called");
2976
- validRequest = this.initializeRequest(request);
2988
+ validRequest = _extends({}, request, this.initializeBaseRequest(request));
2977
2989
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
2978
2990
  _context2.prev = 3;
2979
2991
  _context2.next = 6;
2980
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
2992
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
2981
2993
 
2982
2994
  case 6:
2983
2995
  usernamePasswordClientConfig = _context2.sent;
@@ -3042,8 +3054,8 @@ var ClientAssertion = /*#__PURE__*/function () {
3042
3054
 
3043
3055
  _proto.getJwt = function getJwt(cryptoProvider, issuer, jwtAudience) {
3044
3056
  // if assertion was created from certificate, check if jwt is expired and create new one.
3045
- if (this.privateKey != null && this.thumbprint != null) {
3046
- if (this.jwt != null && !this.isExpired() && issuer == this.issuer && jwtAudience == this.jwtAudience) {
3057
+ if (this.privateKey && this.thumbprint) {
3058
+ if (this.jwt && !this.isExpired() && issuer === this.issuer && jwtAudience === this.jwtAudience) {
3047
3059
  return this.jwt;
3048
3060
  }
3049
3061
 
@@ -3055,7 +3067,7 @@ var ClientAssertion = /*#__PURE__*/function () {
3055
3067
  */
3056
3068
 
3057
3069
 
3058
- if (this.jwt != null) {
3070
+ if (this.jwt) {
3059
3071
  return this.jwt;
3060
3072
  }
3061
3073
 
@@ -3166,17 +3178,17 @@ var ConfidentialClientApplication = /*#__PURE__*/function (_ClientApplication) {
3166
3178
  switch (_context.prev = _context.next) {
3167
3179
  case 0:
3168
3180
  this.logger.info("acquireTokenByClientCredential called");
3169
- validRequest = this.initializeRequest(request);
3181
+ validRequest = _extends({}, request, this.initializeBaseRequest(request));
3170
3182
  serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
3171
3183
  _context.prev = 3;
3172
3184
  _context.next = 6;
3173
- return this.buildOauthClientConfiguration(request.authority, serverTelemetryManager);
3185
+ return this.buildOauthClientConfiguration(validRequest.authority, serverTelemetryManager);
3174
3186
 
3175
3187
  case 6:
3176
3188
  clientCredentialConfig = _context.sent;
3177
3189
  this.logger.verbose("Auth client config generated");
3178
3190
  clientCredentialClient = new ClientCredentialClient(clientCredentialConfig);
3179
- return _context.abrupt("return", clientCredentialClient.acquireToken(request));
3191
+ return _context.abrupt("return", clientCredentialClient.acquireToken(validRequest));
3180
3192
 
3181
3193
  case 12:
3182
3194
  _context.prev = 12;
@@ -3215,22 +3227,23 @@ var ConfidentialClientApplication = /*#__PURE__*/function (_ClientApplication) {
3215
3227
  /*#__PURE__*/
3216
3228
  function () {
3217
3229
  var _acquireTokenOnBehalfOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(request) {
3218
- var clientCredentialConfig, oboClient;
3230
+ var validRequest, clientCredentialConfig, oboClient;
3219
3231
  return runtime_1.wrap(function _callee2$(_context2) {
3220
3232
  while (1) {
3221
3233
  switch (_context2.prev = _context2.next) {
3222
3234
  case 0:
3223
3235
  this.logger.info("acquireTokenOnBehalfOf called");
3224
- _context2.next = 3;
3225
- return this.buildOauthClientConfiguration(request.authority);
3236
+ validRequest = _extends({}, request, this.initializeBaseRequest(request));
3237
+ _context2.next = 4;
3238
+ return this.buildOauthClientConfiguration(validRequest.authority);
3226
3239
 
3227
- case 3:
3240
+ case 4:
3228
3241
  clientCredentialConfig = _context2.sent;
3229
3242
  this.logger.verbose("Auth client config generated");
3230
3243
  oboClient = new OnBehalfOfClient(clientCredentialConfig);
3231
- return _context2.abrupt("return", oboClient.acquireToken(this.initializeRequest(request)));
3244
+ return _context2.abrupt("return", oboClient.acquireToken(validRequest));
3232
3245
 
3233
- case 7:
3246
+ case 8:
3234
3247
  case "end":
3235
3248
  return _context2.stop();
3236
3249
  }
@@ -3249,7 +3262,7 @@ var ConfidentialClientApplication = /*#__PURE__*/function (_ClientApplication) {
3249
3262
  var clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
3250
3263
  var clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
3251
3264
  var certificate = configuration.auth.clientCertificate;
3252
- var certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) || !StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
3265
+ var certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) || !StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
3253
3266
 
3254
3267
  if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
3255
3268
  throw ClientAuthError.createInvalidCredentialError();