@azure/msal-common 4.5.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +194 -0
- package/{changelog.md → CHANGELOG.md} +61 -1
- package/README.md +7 -6
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/account/AuthToken.js +1 -1
- package/dist/account/CcsCredential.js +1 -1
- package/dist/account/ClientInfo.js +1 -1
- package/dist/account/TokenClaims.d.ts +5 -0
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.js +8 -2
- package/dist/authority/Authority.js.map +1 -1
- package/dist/authority/AuthorityFactory.js +1 -1
- package/dist/authority/AuthorityType.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
- package/dist/authority/OpenIdConfigResponse.d.ts +1 -1
- package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
- package/dist/authority/OpenIdConfigResponse.js +1 -2
- package/dist/authority/OpenIdConfigResponse.js.map +1 -1
- package/dist/authority/ProtocolMode.js +1 -1
- package/dist/authority/RegionDiscovery.js +1 -1
- package/dist/cache/CacheManager.d.ts +23 -9
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +206 -76
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +3 -2
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.js +15 -9
- package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts +2 -2
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.js +8 -8
- package/dist/cache/entities/AccountEntity.js.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.js +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.js +1 -2
- package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
- package/dist/cache/entities/CacheRecord.js +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts +7 -3
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.js +13 -6
- package/dist/cache/entities/CredentialEntity.js.map +1 -1
- package/dist/cache/entities/IdTokenEntity.js +1 -1
- package/dist/cache/entities/RefreshTokenEntity.js +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
- package/dist/cache/entities/ThrottlingEntity.js +1 -1
- package/dist/cache/interface/ICacheManager.d.ts +5 -5
- package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.js +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +4 -1
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts +2 -1
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.js +58 -21
- package/dist/client/AuthorizationCodeClient.js.map +1 -1
- package/dist/client/BaseClient.js +1 -1
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.js +8 -2
- package/dist/client/ClientCredentialClient.js.map +1 -1
- package/dist/client/DeviceCodeClient.d.ts.map +1 -1
- package/dist/client/DeviceCodeClient.js +15 -3
- package/dist/client/DeviceCodeClient.js.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.js +8 -2
- package/dist/client/OnBehalfOfClient.js.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.js +28 -11
- package/dist/client/RefreshTokenClient.js.map +1 -1
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.js +17 -12
- package/dist/client/SilentFlowClient.js.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.js +8 -2
- package/dist/client/UsernamePasswordClient.js.map +1 -1
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.js +3 -2
- package/dist/config/ClientConfiguration.js.map +1 -1
- package/dist/crypto/ICrypto.d.ts +11 -1
- package/dist/crypto/ICrypto.d.ts.map +1 -1
- package/dist/crypto/ICrypto.js +19 -1
- package/dist/crypto/ICrypto.js.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +21 -4
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.js +37 -26
- package/dist/crypto/PopTokenGenerator.js.map +1 -1
- package/dist/error/AuthError.d.ts +5 -0
- package/dist/error/AuthError.d.ts.map +1 -1
- package/dist/error/AuthError.js +4 -1
- package/dist/error/AuthError.js.map +1 -1
- package/dist/error/ClientAuthError.d.ts +13 -4
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.js +18 -7
- package/dist/error/ClientAuthError.js.map +1 -1
- package/dist/error/ClientConfigurationError.d.ts +29 -0
- package/dist/error/ClientConfigurationError.d.ts.map +1 -1
- package/dist/error/ClientConfigurationError.js +43 -3
- package/dist/error/ClientConfigurationError.js.map +1 -1
- package/dist/error/InteractionRequiredAuthError.d.ts +24 -5
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.js +30 -9
- package/dist/error/InteractionRequiredAuthError.js.map +1 -1
- package/dist/error/ServerError.js +1 -1
- package/dist/index.cjs.js +641 -226
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +5 -3
- package/dist/logger/Logger.js.map +1 -1
- package/dist/network/INetworkModule.js +1 -1
- package/dist/network/NetworkManager.js +1 -1
- package/dist/network/RequestThumbprint.d.ts +7 -0
- package/dist/network/RequestThumbprint.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.d.ts +2 -1
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.js +11 -5
- package/dist/network/ThrottlingUtils.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
- package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
- package/dist/request/AuthenticationHeaderParser.js +64 -0
- package/dist/request/AuthenticationHeaderParser.js.map +1 -0
- package/dist/request/BaseAuthRequest.d.ts +7 -1
- package/dist/request/BaseAuthRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +3 -0
- package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonEndSessionRequest.d.ts +4 -0
- package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts +4 -0
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.js +10 -1
- package/dist/request/RequestParameterBuilder.js.map +1 -1
- package/dist/request/RequestValidator.js +1 -1
- package/dist/request/ScopeSet.js +1 -1
- package/dist/response/AuthenticationResult.d.ts +3 -1
- package/dist/response/AuthenticationResult.d.ts.map +1 -1
- package/dist/response/ExternalTokenResponse.d.ts +15 -0
- package/dist/response/ExternalTokenResponse.d.ts.map +1 -0
- package/dist/response/ResponseHandler.d.ts +1 -1
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.js +21 -15
- package/dist/response/ResponseHandler.js.map +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +6 -2
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
- package/dist/url/UrlString.d.ts +0 -6
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.js +3 -18
- package/dist/url/UrlString.js.map +1 -1
- package/dist/utils/Constants.d.ts +7 -3
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +6 -2
- package/dist/utils/Constants.js.map +1 -1
- package/dist/utils/ProtocolUtils.js +1 -1
- package/dist/utils/StringUtils.d.ts.map +1 -1
- package/dist/utils/StringUtils.js +12 -11
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/TimeUtils.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-common
|
|
1
|
+
/*! @azure/msal-common v5.2.0 2021-12-07 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -153,6 +153,8 @@ var HeaderNames;
|
|
|
153
153
|
HeaderNames["CONTENT_TYPE"] = "Content-Type";
|
|
154
154
|
HeaderNames["RETRY_AFTER"] = "Retry-After";
|
|
155
155
|
HeaderNames["CCS_HEADER"] = "X-AnchorMailbox";
|
|
156
|
+
HeaderNames["WWWAuthenticate"] = "WWW-Authenticate";
|
|
157
|
+
HeaderNames["AuthenticationInfo"] = "Authentication-Info";
|
|
156
158
|
})(HeaderNames || (HeaderNames = {}));
|
|
157
159
|
/**
|
|
158
160
|
* Persistent cache keys MSAL which stay while user is logged in.
|
|
@@ -223,6 +225,7 @@ var AADServerParamKeys;
|
|
|
223
225
|
AADServerParamKeys["ON_BEHALF_OF"] = "on_behalf_of";
|
|
224
226
|
AADServerParamKeys["FOCI"] = "foci";
|
|
225
227
|
AADServerParamKeys["CCS_HEADER"] = "X-AnchorMailbox";
|
|
228
|
+
AADServerParamKeys["RETURN_SPA_CODE"] = "return_spa_code";
|
|
226
229
|
})(AADServerParamKeys || (AADServerParamKeys = {}));
|
|
227
230
|
/**
|
|
228
231
|
* Claims request keys
|
|
@@ -387,8 +390,9 @@ var SERVER_TELEM_CONSTANTS = {
|
|
|
387
390
|
*/
|
|
388
391
|
exports.AuthenticationScheme = void 0;
|
|
389
392
|
(function (AuthenticationScheme) {
|
|
390
|
-
AuthenticationScheme["POP"] = "pop";
|
|
391
393
|
AuthenticationScheme["BEARER"] = "Bearer";
|
|
394
|
+
AuthenticationScheme["POP"] = "pop";
|
|
395
|
+
AuthenticationScheme["SSH"] = "ssh-cert";
|
|
392
396
|
})(exports.AuthenticationScheme || (exports.AuthenticationScheme = {}));
|
|
393
397
|
/**
|
|
394
398
|
* Constants related to throttling
|
|
@@ -482,6 +486,9 @@ var AuthError = /** @class */ (function (_super) {
|
|
|
482
486
|
_this.name = "AuthError";
|
|
483
487
|
return _this;
|
|
484
488
|
}
|
|
489
|
+
AuthError.prototype.setCorrelationId = function (correlationId) {
|
|
490
|
+
this.correlationId = correlationId;
|
|
491
|
+
};
|
|
485
492
|
/**
|
|
486
493
|
* Creates an error that is thrown when something unexpected happens in the library.
|
|
487
494
|
* @param errDesc
|
|
@@ -527,6 +534,24 @@ var DEFAULT_CRYPTO_IMPLEMENTATION = {
|
|
|
527
534
|
});
|
|
528
535
|
});
|
|
529
536
|
},
|
|
537
|
+
removeTokenBindingKey: function () {
|
|
538
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
539
|
+
var notImplErr;
|
|
540
|
+
return __generator(this, function (_a) {
|
|
541
|
+
notImplErr = "Crypto interface - removeTokenBindingKey() has not been implemented";
|
|
542
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
},
|
|
546
|
+
clearKeystore: function () {
|
|
547
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
548
|
+
var notImplErr;
|
|
549
|
+
return __generator(this, function (_a) {
|
|
550
|
+
notImplErr = "Crypto interface - clearKeystore() has not been implemented";
|
|
551
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
},
|
|
530
555
|
signJwt: function () {
|
|
531
556
|
return __awaiter(this, void 0, void 0, function () {
|
|
532
557
|
var notImplErr;
|
|
@@ -718,6 +743,14 @@ var ClientAuthErrorMessage = {
|
|
|
718
743
|
accessTokenEntityNullError: {
|
|
719
744
|
code: "access_token_entity_null",
|
|
720
745
|
desc: "Access token entity is null, please check logs and cache to ensure a valid access token is present."
|
|
746
|
+
},
|
|
747
|
+
bindingKeyNotRemovedError: {
|
|
748
|
+
code: "binding_key_not_removed",
|
|
749
|
+
desc: "Could not remove the credential's binding key from storage."
|
|
750
|
+
},
|
|
751
|
+
logoutNotSupported: {
|
|
752
|
+
code: "end_session_endpoint_not_supported",
|
|
753
|
+
desc: "Provided authority does not support logout."
|
|
721
754
|
}
|
|
722
755
|
};
|
|
723
756
|
/**
|
|
@@ -817,12 +850,6 @@ var ClientAuthError = /** @class */ (function (_super) {
|
|
|
817
850
|
ClientAuthError.createNonceNotFoundError = function (missingNonce) {
|
|
818
851
|
return new ClientAuthError(ClientAuthErrorMessage.nonceNotFoundError.code, ClientAuthErrorMessage.nonceNotFoundError.desc + ": " + missingNonce);
|
|
819
852
|
};
|
|
820
|
-
/**
|
|
821
|
-
* Creates an error thrown when the authorization code required for a token request is null or empty.
|
|
822
|
-
*/
|
|
823
|
-
ClientAuthError.createNoTokensFoundError = function () {
|
|
824
|
-
return new ClientAuthError(ClientAuthErrorMessage.noTokensFoundError.code, ClientAuthErrorMessage.noTokensFoundError.desc);
|
|
825
|
-
};
|
|
826
853
|
/**
|
|
827
854
|
* Throws error when multiple tokens are in cache.
|
|
828
855
|
*/
|
|
@@ -984,6 +1011,15 @@ var ClientAuthError = /** @class */ (function (_super) {
|
|
|
984
1011
|
ClientAuthError.createNoAuthCodeInServerResponseError = function () {
|
|
985
1012
|
return new ClientAuthError(ClientAuthErrorMessage.noAuthorizationCodeFromServer.code, ClientAuthErrorMessage.noAuthorizationCodeFromServer.desc);
|
|
986
1013
|
};
|
|
1014
|
+
ClientAuthError.createBindingKeyNotRemovedError = function () {
|
|
1015
|
+
return new ClientAuthError(ClientAuthErrorMessage.bindingKeyNotRemovedError.code, ClientAuthErrorMessage.bindingKeyNotRemovedError.desc);
|
|
1016
|
+
};
|
|
1017
|
+
/**
|
|
1018
|
+
* Thrown when logout is attempted for an authority that doesnt have an end_session_endpoint
|
|
1019
|
+
*/
|
|
1020
|
+
ClientAuthError.createLogoutNotSupportedError = function () {
|
|
1021
|
+
return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);
|
|
1022
|
+
};
|
|
987
1023
|
return ClientAuthError;
|
|
988
1024
|
}(AuthError));
|
|
989
1025
|
|
|
@@ -1052,16 +1088,17 @@ var StringUtils = /** @class */ (function () {
|
|
|
1052
1088
|
* @param query
|
|
1053
1089
|
*/
|
|
1054
1090
|
StringUtils.queryStringToObject = function (query) {
|
|
1055
|
-
var match; // Regex for replacing addition symbol with a space
|
|
1056
|
-
var pl = /\+/g;
|
|
1057
|
-
var search = /([^&=]+)=([^&]*)/g;
|
|
1058
|
-
var decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); };
|
|
1059
1091
|
var obj = {};
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1092
|
+
var params = query.split("&");
|
|
1093
|
+
var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
|
|
1094
|
+
params.forEach(function (pair) {
|
|
1095
|
+
if (pair.trim()) {
|
|
1096
|
+
var _a = pair.split(/=(.+)/g, 2), key = _a[0], value = _a[1]; // Split on the first occurence of the '=' character
|
|
1097
|
+
if (key && value) {
|
|
1098
|
+
obj[decode(key)] = decode(value);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1065
1102
|
return obj;
|
|
1066
1103
|
};
|
|
1067
1104
|
/**
|
|
@@ -1103,7 +1140,7 @@ var StringUtils = /** @class */ (function () {
|
|
|
1103
1140
|
* Wildcard support: https://stackoverflow.com/a/3117248/4888559
|
|
1104
1141
|
* Queries: replaces "?" in string with escaped "\?" for regex test
|
|
1105
1142
|
*/
|
|
1106
|
-
var regex = new RegExp(pattern.replace(/\*/g, "[^ ]*").replace(/\?/g, "\\\?"));
|
|
1143
|
+
var regex = new RegExp(pattern.replace(/\\/g, "\\\\").replace(/\*/g, "[^ ]*").replace(/\?/g, "\\\?")); // eslint-disable-line security/detect-non-literal-regexp
|
|
1107
1144
|
return regex.test(input);
|
|
1108
1145
|
};
|
|
1109
1146
|
return StringUtils;
|
|
@@ -1131,10 +1168,12 @@ var Logger = /** @class */ (function () {
|
|
|
1131
1168
|
function Logger(loggerOptions, packageName, packageVersion) {
|
|
1132
1169
|
// Current log level, defaults to info.
|
|
1133
1170
|
this.level = exports.LogLevel.Info;
|
|
1134
|
-
var defaultLoggerCallback = function () {
|
|
1171
|
+
var defaultLoggerCallback = function () {
|
|
1172
|
+
return;
|
|
1173
|
+
};
|
|
1135
1174
|
this.localCallback = loggerOptions.loggerCallback || defaultLoggerCallback;
|
|
1136
1175
|
this.piiLoggingEnabled = loggerOptions.piiLoggingEnabled || false;
|
|
1137
|
-
this.level = loggerOptions.logLevel
|
|
1176
|
+
this.level = typeof (loggerOptions.logLevel) === "number" ? loggerOptions.logLevel : exports.LogLevel.Info;
|
|
1138
1177
|
this.correlationId = loggerOptions.correlationId || "";
|
|
1139
1178
|
this.packageName = packageName || Constants.EMPTY_STRING;
|
|
1140
1179
|
this.packageVersion = packageVersion || Constants.EMPTY_STRING;
|
|
@@ -1287,7 +1326,7 @@ var Logger = /** @class */ (function () {
|
|
|
1287
1326
|
|
|
1288
1327
|
/* eslint-disable header/header */
|
|
1289
1328
|
var name = "@azure/msal-common";
|
|
1290
|
-
var version = "
|
|
1329
|
+
var version = "5.2.0";
|
|
1291
1330
|
|
|
1292
1331
|
/*
|
|
1293
1332
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1298,7 +1337,7 @@ var version = "4.5.1";
|
|
|
1298
1337
|
*
|
|
1299
1338
|
* Key:Value Schema:
|
|
1300
1339
|
*
|
|
1301
|
-
* Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target
|
|
1340
|
+
* Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<scheme>
|
|
1302
1341
|
*
|
|
1303
1342
|
* Value Schema:
|
|
1304
1343
|
* {
|
|
@@ -1311,6 +1350,7 @@ var version = "4.5.1";
|
|
|
1311
1350
|
* realm: Full tenant or organizational identifier that the account belongs to
|
|
1312
1351
|
* target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
|
|
1313
1352
|
* oboAssertion: access token passed in as part of OBO request
|
|
1353
|
+
* tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
|
|
1314
1354
|
* }
|
|
1315
1355
|
*/
|
|
1316
1356
|
var CredentialEntity = /** @class */ (function () {
|
|
@@ -1338,7 +1378,7 @@ var CredentialEntity = /** @class */ (function () {
|
|
|
1338
1378
|
* generates credential key
|
|
1339
1379
|
*/
|
|
1340
1380
|
CredentialEntity.prototype.generateCredentialKey = function () {
|
|
1341
|
-
return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId);
|
|
1381
|
+
return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType);
|
|
1342
1382
|
};
|
|
1343
1383
|
/**
|
|
1344
1384
|
* returns the type of the cache (in this case credential)
|
|
@@ -1348,6 +1388,7 @@ var CredentialEntity = /** @class */ (function () {
|
|
|
1348
1388
|
case exports.CredentialType.ID_TOKEN:
|
|
1349
1389
|
return exports.CacheType.ID_TOKEN;
|
|
1350
1390
|
case exports.CredentialType.ACCESS_TOKEN:
|
|
1391
|
+
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
1351
1392
|
return exports.CacheType.ACCESS_TOKEN;
|
|
1352
1393
|
case exports.CredentialType.REFRESH_TOKEN:
|
|
1353
1394
|
return exports.CacheType.REFRESH_TOKEN;
|
|
@@ -1379,13 +1420,18 @@ var CredentialEntity = /** @class */ (function () {
|
|
|
1379
1420
|
};
|
|
1380
1421
|
/**
|
|
1381
1422
|
* generates credential key
|
|
1423
|
+
* <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
|
|
1382
1424
|
*/
|
|
1383
|
-
CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId) {
|
|
1425
|
+
CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType) {
|
|
1384
1426
|
var credentialKey = [
|
|
1385
1427
|
this.generateAccountIdForCacheKey(homeAccountId, environment),
|
|
1386
1428
|
this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
|
|
1387
|
-
this.generateTargetForCacheKey(target)
|
|
1429
|
+
this.generateTargetForCacheKey(target)
|
|
1388
1430
|
];
|
|
1431
|
+
// PoP Tokens and SSH certs include scheme in cache key
|
|
1432
|
+
if (tokenType && tokenType !== exports.AuthenticationScheme.BEARER) {
|
|
1433
|
+
credentialKey.push(tokenType.toLowerCase());
|
|
1434
|
+
}
|
|
1389
1435
|
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
1390
1436
|
};
|
|
1391
1437
|
/**
|
|
@@ -1494,15 +1540,31 @@ var ClientConfigurationErrorMessage = {
|
|
|
1494
1540
|
},
|
|
1495
1541
|
invalidCloudDiscoveryMetadata: {
|
|
1496
1542
|
code: "invalid_cloud_discovery_metadata",
|
|
1497
|
-
desc: "Invalid cloudDiscoveryMetadata provided. Must be a JSON object containing tenant_discovery_endpoint and metadata fields"
|
|
1543
|
+
desc: "Invalid cloudDiscoveryMetadata provided. Must be a stringified JSON object containing tenant_discovery_endpoint and metadata fields"
|
|
1498
1544
|
},
|
|
1499
1545
|
invalidAuthorityMetadata: {
|
|
1500
1546
|
code: "invalid_authority_metadata",
|
|
1501
|
-
desc: "Invalid authorityMetadata provided. Must by a JSON object containing authorization_endpoint, token_endpoint,
|
|
1547
|
+
desc: "Invalid authorityMetadata provided. Must by a stringified JSON object containing authorization_endpoint, token_endpoint, issuer fields."
|
|
1502
1548
|
},
|
|
1503
1549
|
untrustedAuthority: {
|
|
1504
1550
|
code: "untrusted_authority",
|
|
1505
1551
|
desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter."
|
|
1552
|
+
},
|
|
1553
|
+
missingSshJwk: {
|
|
1554
|
+
code: "missing_ssh_jwk",
|
|
1555
|
+
desc: "Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme."
|
|
1556
|
+
},
|
|
1557
|
+
missingSshKid: {
|
|
1558
|
+
code: "missing_ssh_kid",
|
|
1559
|
+
desc: "Missing sshKid in SSH certificate request. A string that uniquely identifies the public SSH key is required when using the SSH authentication scheme."
|
|
1560
|
+
},
|
|
1561
|
+
missingNonceAuthenticationHeader: {
|
|
1562
|
+
code: "missing_nonce_authentication_header",
|
|
1563
|
+
desc: "Unable to find an authentication header containing server nonce. Either the Authentication-Info or WWW-Authenticate headers must be present in order to obtain a server nonce."
|
|
1564
|
+
},
|
|
1565
|
+
invalidAuthenticationHeader: {
|
|
1566
|
+
code: "invalid_authentication_header",
|
|
1567
|
+
desc: "Invalid authentication header provided"
|
|
1506
1568
|
}
|
|
1507
1569
|
};
|
|
1508
1570
|
/**
|
|
@@ -1624,6 +1686,30 @@ var ClientConfigurationError = /** @class */ (function (_super) {
|
|
|
1624
1686
|
ClientConfigurationError.createUntrustedAuthorityError = function () {
|
|
1625
1687
|
return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code, ClientConfigurationErrorMessage.untrustedAuthority.desc);
|
|
1626
1688
|
};
|
|
1689
|
+
/*
|
|
1690
|
+
* Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request
|
|
1691
|
+
*/
|
|
1692
|
+
ClientConfigurationError.createMissingSshJwkError = function () {
|
|
1693
|
+
return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshJwk.code, ClientConfigurationErrorMessage.missingSshJwk.desc);
|
|
1694
|
+
};
|
|
1695
|
+
/**
|
|
1696
|
+
* Throws an error when the authentication scheme is set to SSH but the SSH public key ID is omitted from the request
|
|
1697
|
+
*/
|
|
1698
|
+
ClientConfigurationError.createMissingSshKidError = function () {
|
|
1699
|
+
return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshKid.code, ClientConfigurationErrorMessage.missingSshKid.desc);
|
|
1700
|
+
};
|
|
1701
|
+
/**
|
|
1702
|
+
* Throws error when provided headers don't contain a header that a server nonce can be extracted from
|
|
1703
|
+
*/
|
|
1704
|
+
ClientConfigurationError.createMissingNonceAuthenticationHeadersError = function () {
|
|
1705
|
+
return new ClientConfigurationError(ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.code, ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.desc);
|
|
1706
|
+
};
|
|
1707
|
+
/**
|
|
1708
|
+
* Throws error when a provided header is invalid in any way
|
|
1709
|
+
*/
|
|
1710
|
+
ClientConfigurationError.createInvalidAuthenticationHeaderError = function (invalidHeaderName, details) {
|
|
1711
|
+
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code, ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc + ". Invalid header: " + invalidHeaderName + ". Details: " + details);
|
|
1712
|
+
};
|
|
1627
1713
|
return ClientConfigurationError;
|
|
1628
1714
|
}(ClientAuthError));
|
|
1629
1715
|
|
|
@@ -1958,14 +2044,14 @@ var AccountEntity = /** @class */ (function () {
|
|
|
1958
2044
|
* @param idToken
|
|
1959
2045
|
* @param policy
|
|
1960
2046
|
*/
|
|
1961
|
-
AccountEntity.createAccount = function (clientInfo, homeAccountId,
|
|
2047
|
+
AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
|
|
1962
2048
|
var _a, _b, _c, _d, _e, _f;
|
|
1963
2049
|
var account = new AccountEntity();
|
|
1964
2050
|
account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
|
|
1965
2051
|
account.clientInfo = clientInfo;
|
|
1966
2052
|
account.homeAccountId = homeAccountId;
|
|
1967
|
-
var env = authority.getPreferredCache();
|
|
1968
|
-
if (
|
|
2053
|
+
var env = environment || (authority && authority.getPreferredCache());
|
|
2054
|
+
if (!env) {
|
|
1969
2055
|
throw ClientAuthError.createInvalidCacheEnvironmentError();
|
|
1970
2056
|
}
|
|
1971
2057
|
account.environment = env;
|
|
@@ -1992,16 +2078,16 @@ var AccountEntity = /** @class */ (function () {
|
|
|
1992
2078
|
* @param authority
|
|
1993
2079
|
* @param idToken
|
|
1994
2080
|
*/
|
|
1995
|
-
AccountEntity.createGenericAccount = function (
|
|
2081
|
+
AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
|
|
1996
2082
|
var _a, _b, _c, _d;
|
|
1997
2083
|
var account = new AccountEntity();
|
|
1998
|
-
account.authorityType = (authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
|
|
2084
|
+
account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
|
|
1999
2085
|
account.homeAccountId = homeAccountId;
|
|
2000
2086
|
// non AAD scenarios can have empty realm
|
|
2001
2087
|
account.realm = "";
|
|
2002
2088
|
account.oboAssertion = oboAssertion;
|
|
2003
|
-
var env = authority.getPreferredCache();
|
|
2004
|
-
if (
|
|
2089
|
+
var env = environment || authority && authority.getPreferredCache();
|
|
2090
|
+
if (!env) {
|
|
2005
2091
|
throw ClientAuthError.createInvalidCacheEnvironmentError();
|
|
2006
2092
|
}
|
|
2007
2093
|
if (idToken) {
|
|
@@ -2167,49 +2253,75 @@ var CacheManager = /** @class */ (function () {
|
|
|
2167
2253
|
* @param cacheRecord
|
|
2168
2254
|
*/
|
|
2169
2255
|
CacheManager.prototype.saveCacheRecord = function (cacheRecord) {
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2256
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2257
|
+
return __generator(this, function (_a) {
|
|
2258
|
+
switch (_a.label) {
|
|
2259
|
+
case 0:
|
|
2260
|
+
if (!cacheRecord) {
|
|
2261
|
+
throw ClientAuthError.createNullOrUndefinedCacheRecord();
|
|
2262
|
+
}
|
|
2263
|
+
if (!!cacheRecord.account) {
|
|
2264
|
+
this.setAccount(cacheRecord.account);
|
|
2265
|
+
}
|
|
2266
|
+
if (!!cacheRecord.idToken) {
|
|
2267
|
+
this.setIdTokenCredential(cacheRecord.idToken);
|
|
2268
|
+
}
|
|
2269
|
+
if (!!!cacheRecord.accessToken) return [3 /*break*/, 2];
|
|
2270
|
+
return [4 /*yield*/, this.saveAccessToken(cacheRecord.accessToken)];
|
|
2271
|
+
case 1:
|
|
2272
|
+
_a.sent();
|
|
2273
|
+
_a.label = 2;
|
|
2274
|
+
case 2:
|
|
2275
|
+
if (!!cacheRecord.refreshToken) {
|
|
2276
|
+
this.setRefreshTokenCredential(cacheRecord.refreshToken);
|
|
2277
|
+
}
|
|
2278
|
+
if (!!cacheRecord.appMetadata) {
|
|
2279
|
+
this.setAppMetadata(cacheRecord.appMetadata);
|
|
2280
|
+
}
|
|
2281
|
+
return [2 /*return*/];
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
});
|
|
2188
2285
|
};
|
|
2189
2286
|
/**
|
|
2190
2287
|
* saves access token credential
|
|
2191
2288
|
* @param credential
|
|
2192
2289
|
*/
|
|
2193
2290
|
CacheManager.prototype.saveAccessToken = function (credential) {
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2292
|
+
var currentTokenCache, currentScopes, currentAccessTokens, removedAccessTokens_1;
|
|
2293
|
+
var _this = this;
|
|
2294
|
+
return __generator(this, function (_a) {
|
|
2295
|
+
switch (_a.label) {
|
|
2296
|
+
case 0:
|
|
2297
|
+
currentTokenCache = this.getCredentialsFilteredBy({
|
|
2298
|
+
clientId: credential.clientId,
|
|
2299
|
+
credentialType: credential.credentialType,
|
|
2300
|
+
environment: credential.environment,
|
|
2301
|
+
homeAccountId: credential.homeAccountId,
|
|
2302
|
+
realm: credential.realm,
|
|
2303
|
+
tokenType: credential.tokenType
|
|
2304
|
+
});
|
|
2305
|
+
currentScopes = ScopeSet.fromString(credential.target);
|
|
2306
|
+
currentAccessTokens = Object.keys(currentTokenCache.accessTokens).map(function (key) { return currentTokenCache.accessTokens[key]; });
|
|
2307
|
+
if (!currentAccessTokens) return [3 /*break*/, 2];
|
|
2308
|
+
removedAccessTokens_1 = [];
|
|
2309
|
+
currentAccessTokens.forEach(function (tokenEntity) {
|
|
2310
|
+
var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
|
|
2311
|
+
if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
|
|
2312
|
+
removedAccessTokens_1.push(_this.removeCredential(tokenEntity));
|
|
2313
|
+
}
|
|
2314
|
+
});
|
|
2315
|
+
return [4 /*yield*/, Promise.all(removedAccessTokens_1)];
|
|
2316
|
+
case 1:
|
|
2317
|
+
_a.sent();
|
|
2318
|
+
_a.label = 2;
|
|
2319
|
+
case 2:
|
|
2320
|
+
this.setAccessTokenCredential(credential);
|
|
2321
|
+
return [2 /*return*/];
|
|
2209
2322
|
}
|
|
2210
2323
|
});
|
|
2211
|
-
}
|
|
2212
|
-
this.setAccessTokenCredential(credential);
|
|
2324
|
+
});
|
|
2213
2325
|
};
|
|
2214
2326
|
/**
|
|
2215
2327
|
* retrieve accounts matching all provided filters; if no filter is set, get all accounts
|
|
@@ -2260,7 +2372,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2260
2372
|
* @param target
|
|
2261
2373
|
*/
|
|
2262
2374
|
CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
|
|
2263
|
-
return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion);
|
|
2375
|
+
return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType, filter.keyId);
|
|
2264
2376
|
};
|
|
2265
2377
|
/**
|
|
2266
2378
|
* Support function to help match credentials
|
|
@@ -2270,8 +2382,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2270
2382
|
* @param clientId
|
|
2271
2383
|
* @param realm
|
|
2272
2384
|
* @param target
|
|
2385
|
+
* @param oboAssertion
|
|
2386
|
+
* @param tokenType
|
|
2273
2387
|
*/
|
|
2274
|
-
CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion) {
|
|
2388
|
+
CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId) {
|
|
2275
2389
|
var _this = this;
|
|
2276
2390
|
var allCacheKeys = this.getKeys();
|
|
2277
2391
|
var matchingCredentials = {
|
|
@@ -2318,6 +2432,28 @@ var CacheManager = /** @class */ (function () {
|
|
|
2318
2432
|
if (!!target && !_this.matchTarget(entity, target)) {
|
|
2319
2433
|
return;
|
|
2320
2434
|
}
|
|
2435
|
+
// Access Token with Auth Scheme specific matching
|
|
2436
|
+
if (credentialType === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
|
|
2437
|
+
if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
switch (tokenType) {
|
|
2441
|
+
case exports.AuthenticationScheme.POP:
|
|
2442
|
+
// This check avoids matching outdated POP tokens that don't have the <-scheme> in the cache key
|
|
2443
|
+
if (cacheKey.indexOf(exports.AuthenticationScheme.POP) === -1) {
|
|
2444
|
+
// AccessToken_With_AuthScheme that doesn't have "-pop" in the key is outdated and needs to be removed
|
|
2445
|
+
_this.removeItem(cacheKey, exports.CacheSchemaType.CREDENTIAL);
|
|
2446
|
+
return;
|
|
2447
|
+
}
|
|
2448
|
+
break;
|
|
2449
|
+
case exports.AuthenticationScheme.SSH:
|
|
2450
|
+
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
2451
|
+
if (keyId && !_this.matchKeyId(entity, keyId)) {
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
break;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2321
2457
|
switch (credType) {
|
|
2322
2458
|
case exports.CredentialType.ID_TOKEN:
|
|
2323
2459
|
matchingCredentials.idTokens[cacheKey] = entity;
|
|
@@ -2398,56 +2534,112 @@ var CacheManager = /** @class */ (function () {
|
|
|
2398
2534
|
* Removes all accounts and related tokens from cache.
|
|
2399
2535
|
*/
|
|
2400
2536
|
CacheManager.prototype.removeAllAccounts = function () {
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2537
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2538
|
+
var allCacheKeys, removedAccounts;
|
|
2539
|
+
var _this = this;
|
|
2540
|
+
return __generator(this, function (_a) {
|
|
2541
|
+
switch (_a.label) {
|
|
2542
|
+
case 0:
|
|
2543
|
+
allCacheKeys = this.getKeys();
|
|
2544
|
+
removedAccounts = [];
|
|
2545
|
+
allCacheKeys.forEach(function (cacheKey) {
|
|
2546
|
+
var entity = _this.getAccount(cacheKey);
|
|
2547
|
+
if (!entity) {
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
removedAccounts.push(_this.removeAccount(cacheKey));
|
|
2551
|
+
});
|
|
2552
|
+
return [4 /*yield*/, Promise.all(removedAccounts)];
|
|
2553
|
+
case 1:
|
|
2554
|
+
_a.sent();
|
|
2555
|
+
return [2 /*return*/, true];
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2409
2558
|
});
|
|
2410
|
-
return true;
|
|
2411
2559
|
};
|
|
2412
2560
|
/**
|
|
2413
2561
|
* returns a boolean if the given account is removed
|
|
2414
2562
|
* @param account
|
|
2415
2563
|
*/
|
|
2416
2564
|
CacheManager.prototype.removeAccount = function (accountKey) {
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2565
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2566
|
+
var account;
|
|
2567
|
+
return __generator(this, function (_a) {
|
|
2568
|
+
switch (_a.label) {
|
|
2569
|
+
case 0:
|
|
2570
|
+
account = this.getAccount(accountKey);
|
|
2571
|
+
if (!account) {
|
|
2572
|
+
throw ClientAuthError.createNoAccountFoundError();
|
|
2573
|
+
}
|
|
2574
|
+
return [4 /*yield*/, this.removeAccountContext(account)];
|
|
2575
|
+
case 1: return [2 /*return*/, ((_a.sent()) && this.removeItem(accountKey, exports.CacheSchemaType.ACCOUNT))];
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
});
|
|
2422
2579
|
};
|
|
2423
2580
|
/**
|
|
2424
2581
|
* returns a boolean if the given account is removed
|
|
2425
2582
|
* @param account
|
|
2426
2583
|
*/
|
|
2427
2584
|
CacheManager.prototype.removeAccountContext = function (account) {
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2585
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2586
|
+
var allCacheKeys, accountId, removedCredentials;
|
|
2587
|
+
var _this = this;
|
|
2588
|
+
return __generator(this, function (_a) {
|
|
2589
|
+
switch (_a.label) {
|
|
2590
|
+
case 0:
|
|
2591
|
+
allCacheKeys = this.getKeys();
|
|
2592
|
+
accountId = account.generateAccountId();
|
|
2593
|
+
removedCredentials = [];
|
|
2594
|
+
allCacheKeys.forEach(function (cacheKey) {
|
|
2595
|
+
// don't parse any non-credential type cache entities
|
|
2596
|
+
var credType = CredentialEntity.getCredentialType(cacheKey);
|
|
2597
|
+
if (credType === Constants.NOT_DEFINED) {
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
var cacheEntity = _this.getSpecificCredential(cacheKey, credType);
|
|
2601
|
+
if (!!cacheEntity && accountId === cacheEntity.generateAccountId()) {
|
|
2602
|
+
removedCredentials.push(_this.removeCredential(cacheEntity));
|
|
2603
|
+
}
|
|
2604
|
+
});
|
|
2605
|
+
return [4 /*yield*/, Promise.all(removedCredentials)];
|
|
2606
|
+
case 1:
|
|
2607
|
+
_a.sent();
|
|
2608
|
+
return [2 /*return*/, true];
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2441
2611
|
});
|
|
2442
|
-
return true;
|
|
2443
2612
|
};
|
|
2444
2613
|
/**
|
|
2445
2614
|
* returns a boolean if the given credential is removed
|
|
2446
2615
|
* @param credential
|
|
2447
2616
|
*/
|
|
2448
2617
|
CacheManager.prototype.removeCredential = function (credential) {
|
|
2449
|
-
|
|
2450
|
-
|
|
2618
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2619
|
+
var key, accessTokenWithAuthSchemeEntity, kid;
|
|
2620
|
+
return __generator(this, function (_a) {
|
|
2621
|
+
switch (_a.label) {
|
|
2622
|
+
case 0:
|
|
2623
|
+
key = credential.generateCredentialKey();
|
|
2624
|
+
if (!(credential.credentialType.toLowerCase() === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
|
|
2625
|
+
if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
|
|
2626
|
+
accessTokenWithAuthSchemeEntity = credential;
|
|
2627
|
+
kid = accessTokenWithAuthSchemeEntity.keyId;
|
|
2628
|
+
if (!kid) return [3 /*break*/, 4];
|
|
2629
|
+
_a.label = 1;
|
|
2630
|
+
case 1:
|
|
2631
|
+
_a.trys.push([1, 3, , 4]);
|
|
2632
|
+
return [4 /*yield*/, this.cryptoImpl.removeTokenBindingKey(kid)];
|
|
2633
|
+
case 2:
|
|
2634
|
+
_a.sent();
|
|
2635
|
+
return [3 /*break*/, 4];
|
|
2636
|
+
case 3:
|
|
2637
|
+
_a.sent();
|
|
2638
|
+
throw ClientAuthError.createBindingKeyNotRemovedError();
|
|
2639
|
+
case 4: return [2 /*return*/, this.removeItem(key, exports.CacheSchemaType.CREDENTIAL)];
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
});
|
|
2451
2643
|
};
|
|
2452
2644
|
/**
|
|
2453
2645
|
* Removes all app metadata objects from cache.
|
|
@@ -2470,10 +2662,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2470
2662
|
* @param environment
|
|
2471
2663
|
* @param authScheme
|
|
2472
2664
|
*/
|
|
2473
|
-
CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme) {
|
|
2665
|
+
CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme, keyId) {
|
|
2474
2666
|
var cachedAccount = this.readAccountFromCache(account);
|
|
2475
2667
|
var cachedIdToken = this.readIdTokenFromCache(clientId, account);
|
|
2476
|
-
var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme);
|
|
2668
|
+
var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme, keyId);
|
|
2477
2669
|
var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
|
|
2478
2670
|
var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
|
|
2479
2671
|
if (cachedAccount && cachedIdToken) {
|
|
@@ -2527,8 +2719,9 @@ var CacheManager = /** @class */ (function () {
|
|
|
2527
2719
|
* @param scopes
|
|
2528
2720
|
* @param authScheme
|
|
2529
2721
|
*/
|
|
2530
|
-
CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme) {
|
|
2531
|
-
|
|
2722
|
+
CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme, keyId) {
|
|
2723
|
+
// Distinguish between Bearer and PoP/SSH token cache types
|
|
2724
|
+
var credentialType = (authScheme && authScheme !== exports.AuthenticationScheme.BEARER) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
|
|
2532
2725
|
var accessTokenFilter = {
|
|
2533
2726
|
homeAccountId: account.homeAccountId,
|
|
2534
2727
|
environment: account.environment,
|
|
@@ -2536,6 +2729,8 @@ var CacheManager = /** @class */ (function () {
|
|
|
2536
2729
|
clientId: clientId,
|
|
2537
2730
|
realm: account.tenantId,
|
|
2538
2731
|
target: scopes.printScopesLowerCase(),
|
|
2732
|
+
tokenType: authScheme,
|
|
2733
|
+
keyId: keyId
|
|
2539
2734
|
};
|
|
2540
2735
|
var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
|
|
2541
2736
|
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
@@ -2680,6 +2875,22 @@ var CacheManager = /** @class */ (function () {
|
|
|
2680
2875
|
}
|
|
2681
2876
|
return entityScopeSet.containsScopeSet(requestTargetScopeSet);
|
|
2682
2877
|
};
|
|
2878
|
+
/**
|
|
2879
|
+
* Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
|
|
2880
|
+
* @param entity
|
|
2881
|
+
* @param tokenType
|
|
2882
|
+
*/
|
|
2883
|
+
CacheManager.prototype.matchTokenType = function (entity, tokenType) {
|
|
2884
|
+
return !!(entity.tokenType && entity.tokenType === tokenType);
|
|
2885
|
+
};
|
|
2886
|
+
/**
|
|
2887
|
+
* Returns true if the credential's keyId matches the one in the request, false otherwise
|
|
2888
|
+
* @param entity
|
|
2889
|
+
* @param tokenType
|
|
2890
|
+
*/
|
|
2891
|
+
CacheManager.prototype.matchKeyId = function (entity, keyId) {
|
|
2892
|
+
return !!(entity.keyId && entity.keyId === keyId);
|
|
2893
|
+
};
|
|
2683
2894
|
/**
|
|
2684
2895
|
* returns if a given cache entity is of the type appmetadata
|
|
2685
2896
|
* @param key
|
|
@@ -2820,8 +3031,13 @@ var DefaultStorageClass = /** @class */ (function (_super) {
|
|
|
2820
3031
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
2821
3032
|
};
|
|
2822
3033
|
DefaultStorageClass.prototype.clear = function () {
|
|
2823
|
-
|
|
2824
|
-
|
|
3034
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3035
|
+
var notImplErr;
|
|
3036
|
+
return __generator(this, function (_a) {
|
|
3037
|
+
notImplErr = "Storage interface - clear() has not been implemented for the cacheStorage interface.";
|
|
3038
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
3039
|
+
});
|
|
3040
|
+
});
|
|
2825
3041
|
};
|
|
2826
3042
|
return DefaultStorageClass;
|
|
2827
3043
|
}(CacheManager));
|
|
@@ -2883,10 +3099,11 @@ var DEFAULT_CLIENT_CREDENTIALS = {
|
|
|
2883
3099
|
*/
|
|
2884
3100
|
function buildClientConfiguration(_a) {
|
|
2885
3101
|
var userAuthOptions = _a.authOptions, userSystemOptions = _a.systemOptions, userLoggerOption = _a.loggerOptions, storageImplementation = _a.storageInterface, networkImplementation = _a.networkInterface, cryptoImplementation = _a.cryptoInterface, clientCredentials = _a.clientCredentials, libraryInfo = _a.libraryInfo, serverTelemetryManager = _a.serverTelemetryManager, persistencePlugin = _a.persistencePlugin, serializableCache = _a.serializableCache;
|
|
3102
|
+
var loggerOptions = __assign(__assign({}, DEFAULT_LOGGER_IMPLEMENTATION), userLoggerOption);
|
|
2886
3103
|
return {
|
|
2887
3104
|
authOptions: buildAuthOptions(userAuthOptions),
|
|
2888
3105
|
systemOptions: __assign(__assign({}, DEFAULT_SYSTEM_OPTIONS), userSystemOptions),
|
|
2889
|
-
loggerOptions:
|
|
3106
|
+
loggerOptions: loggerOptions,
|
|
2890
3107
|
storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION),
|
|
2891
3108
|
networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
|
|
2892
3109
|
cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
@@ -2998,12 +3215,18 @@ var ThrottlingUtils = /** @class */ (function () {
|
|
|
2998
3215
|
var currentSeconds = Date.now() / 1000;
|
|
2999
3216
|
return Math.floor(Math.min(currentSeconds + (time || ThrottlingConstants.DEFAULT_THROTTLE_TIME_SECONDS), currentSeconds + ThrottlingConstants.DEFAULT_MAX_THROTTLE_TIME_SECONDS) * 1000);
|
|
3000
3217
|
};
|
|
3001
|
-
ThrottlingUtils.removeThrottle = function (cacheManager, clientId,
|
|
3218
|
+
ThrottlingUtils.removeThrottle = function (cacheManager, clientId, request, homeAccountIdentifier) {
|
|
3002
3219
|
var thumbprint = {
|
|
3003
3220
|
clientId: clientId,
|
|
3004
|
-
authority: authority,
|
|
3005
|
-
scopes: scopes,
|
|
3006
|
-
homeAccountIdentifier: homeAccountIdentifier
|
|
3221
|
+
authority: request.authority,
|
|
3222
|
+
scopes: request.scopes,
|
|
3223
|
+
homeAccountIdentifier: homeAccountIdentifier,
|
|
3224
|
+
authenticationScheme: request.authenticationScheme,
|
|
3225
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
3226
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
3227
|
+
shrClaims: request.shrClaims,
|
|
3228
|
+
sshJwk: request.sshJwk,
|
|
3229
|
+
sshKid: request.sshKid
|
|
3007
3230
|
};
|
|
3008
3231
|
var key = this.generateThrottlingStorageKey(thumbprint);
|
|
3009
3232
|
return cacheManager.removeItem(key, exports.CacheSchemaType.THROTTLING);
|
|
@@ -3541,6 +3764,15 @@ var RequestParameterBuilder = /** @class */ (function () {
|
|
|
3541
3764
|
this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(cnfString));
|
|
3542
3765
|
}
|
|
3543
3766
|
};
|
|
3767
|
+
/**
|
|
3768
|
+
* add SSH JWK and key ID to query params
|
|
3769
|
+
*/
|
|
3770
|
+
RequestParameterBuilder.prototype.addSshJwk = function (sshJwkString) {
|
|
3771
|
+
if (!StringUtils.isEmpty(sshJwkString)) {
|
|
3772
|
+
this.parameters.set(AADServerParamKeys.TOKEN_TYPE, exports.AuthenticationScheme.SSH);
|
|
3773
|
+
this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(sshJwkString));
|
|
3774
|
+
}
|
|
3775
|
+
};
|
|
3544
3776
|
/**
|
|
3545
3777
|
* add server telemetry fields
|
|
3546
3778
|
* @param serverTelemetryManager
|
|
@@ -3724,7 +3956,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
|
|
|
3724
3956
|
* @param expiresOn
|
|
3725
3957
|
* @param extExpiresOn
|
|
3726
3958
|
*/
|
|
3727
|
-
AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion) {
|
|
3959
|
+
AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId) {
|
|
3728
3960
|
var _a;
|
|
3729
3961
|
var atEntity = new AccessTokenEntity();
|
|
3730
3962
|
atEntity.homeAccountId = homeAccountId;
|
|
@@ -3747,15 +3979,21 @@ var AccessTokenEntity = /** @class */ (function (_super) {
|
|
|
3747
3979
|
atEntity.target = scopes;
|
|
3748
3980
|
atEntity.oboAssertion = oboAssertion;
|
|
3749
3981
|
atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
|
|
3750
|
-
// Create Access Token With
|
|
3751
|
-
if (atEntity.tokenType
|
|
3982
|
+
// Create Access Token With Auth Scheme instead of regular access token
|
|
3983
|
+
if (atEntity.tokenType !== exports.AuthenticationScheme.BEARER) {
|
|
3752
3984
|
atEntity.credentialType = exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3985
|
+
switch (atEntity.tokenType) {
|
|
3986
|
+
case exports.AuthenticationScheme.POP:
|
|
3987
|
+
// Make sure keyId is present and add it to credential
|
|
3988
|
+
var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
|
|
3989
|
+
if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
|
|
3990
|
+
throw ClientAuthError.createTokenClaimsRequiredError();
|
|
3991
|
+
}
|
|
3992
|
+
atEntity.keyId = tokenClaims.cnf.kid;
|
|
3993
|
+
break;
|
|
3994
|
+
case exports.AuthenticationScheme.SSH:
|
|
3995
|
+
atEntity.keyId = keyId;
|
|
3757
3996
|
}
|
|
3758
|
-
atEntity.keyId = tokenClaims.cnf.kid;
|
|
3759
3997
|
}
|
|
3760
3998
|
return atEntity;
|
|
3761
3999
|
};
|
|
@@ -3849,9 +4087,9 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
|
|
|
3849
4087
|
* Licensed under the MIT License.
|
|
3850
4088
|
*/
|
|
3851
4089
|
/**
|
|
3852
|
-
*
|
|
4090
|
+
* InteractionRequiredServerErrorMessage contains string constants used by error codes and messages returned by the server indicating interaction is required
|
|
3853
4091
|
*/
|
|
3854
|
-
var
|
|
4092
|
+
var InteractionRequiredServerErrorMessage = [
|
|
3855
4093
|
"interaction_required",
|
|
3856
4094
|
"consent_required",
|
|
3857
4095
|
"login_required"
|
|
@@ -3864,7 +4102,16 @@ var InteractionRequiredAuthSubErrorMessage = [
|
|
|
3864
4102
|
"consent_required"
|
|
3865
4103
|
];
|
|
3866
4104
|
/**
|
|
3867
|
-
*
|
|
4105
|
+
* Interaction required errors defined by the SDK
|
|
4106
|
+
*/
|
|
4107
|
+
var InteractionRequiredAuthErrorMessage = {
|
|
4108
|
+
noTokensFoundError: {
|
|
4109
|
+
code: "no_tokens_found",
|
|
4110
|
+
desc: "No refresh token found in the cache. Please sign-in."
|
|
4111
|
+
}
|
|
4112
|
+
};
|
|
4113
|
+
/**
|
|
4114
|
+
* Error thrown when user interaction is required.
|
|
3868
4115
|
*/
|
|
3869
4116
|
var InteractionRequiredAuthError = /** @class */ (function (_super) {
|
|
3870
4117
|
__extends(InteractionRequiredAuthError, _super);
|
|
@@ -3874,16 +4121,28 @@ var InteractionRequiredAuthError = /** @class */ (function (_super) {
|
|
|
3874
4121
|
Object.setPrototypeOf(_this, InteractionRequiredAuthError.prototype);
|
|
3875
4122
|
return _this;
|
|
3876
4123
|
}
|
|
4124
|
+
/**
|
|
4125
|
+
* Helper function used to determine if an error thrown by the server requires interaction to resolve
|
|
4126
|
+
* @param errorCode
|
|
4127
|
+
* @param errorString
|
|
4128
|
+
* @param subError
|
|
4129
|
+
*/
|
|
3877
4130
|
InteractionRequiredAuthError.isInteractionRequiredError = function (errorCode, errorString, subError) {
|
|
3878
|
-
var isInteractionRequiredErrorCode = !!errorCode &&
|
|
4131
|
+
var isInteractionRequiredErrorCode = !!errorCode && InteractionRequiredServerErrorMessage.indexOf(errorCode) > -1;
|
|
3879
4132
|
var isInteractionRequiredSubError = !!subError && InteractionRequiredAuthSubErrorMessage.indexOf(subError) > -1;
|
|
3880
|
-
var isInteractionRequiredErrorDesc = !!errorString &&
|
|
4133
|
+
var isInteractionRequiredErrorDesc = !!errorString && InteractionRequiredServerErrorMessage.some(function (irErrorCode) {
|
|
3881
4134
|
return errorString.indexOf(irErrorCode) > -1;
|
|
3882
4135
|
});
|
|
3883
4136
|
return isInteractionRequiredErrorCode || isInteractionRequiredErrorDesc || isInteractionRequiredSubError;
|
|
3884
4137
|
};
|
|
4138
|
+
/**
|
|
4139
|
+
* Creates an error thrown when the authorization code required for a token request is null or empty.
|
|
4140
|
+
*/
|
|
4141
|
+
InteractionRequiredAuthError.createNoTokensFoundError = function () {
|
|
4142
|
+
return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.noTokensFoundError.code, InteractionRequiredAuthErrorMessage.noTokensFoundError.desc);
|
|
4143
|
+
};
|
|
3885
4144
|
return InteractionRequiredAuthError;
|
|
3886
|
-
}(
|
|
4145
|
+
}(AuthError));
|
|
3887
4146
|
|
|
3888
4147
|
/*
|
|
3889
4148
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -4035,22 +4294,6 @@ var UrlString = /** @class */ (function () {
|
|
|
4035
4294
|
throw ClientConfigurationError.createInsecureAuthorityUriError(this.urlString);
|
|
4036
4295
|
}
|
|
4037
4296
|
};
|
|
4038
|
-
/**
|
|
4039
|
-
* Function to remove query string params from url. Returns the new url.
|
|
4040
|
-
* @param url
|
|
4041
|
-
* @param name
|
|
4042
|
-
*/
|
|
4043
|
-
UrlString.prototype.urlRemoveQueryStringParameter = function (name) {
|
|
4044
|
-
var regex = new RegExp("(\\&" + name + "=)[^\&]+");
|
|
4045
|
-
this._urlString = this.urlString.replace(regex, "");
|
|
4046
|
-
// name=value&
|
|
4047
|
-
regex = new RegExp("(" + name + "=)[^\&]+&");
|
|
4048
|
-
this._urlString = this.urlString.replace(regex, "");
|
|
4049
|
-
// name=value
|
|
4050
|
-
regex = new RegExp("(" + name + "=)[^\&]+");
|
|
4051
|
-
this._urlString = this.urlString.replace(regex, "");
|
|
4052
|
-
return this.urlString;
|
|
4053
|
-
};
|
|
4054
4297
|
/**
|
|
4055
4298
|
* Given a url and a query string return the url with provided query string appended
|
|
4056
4299
|
* @param url
|
|
@@ -4171,7 +4414,8 @@ var UrlString = /** @class */ (function () {
|
|
|
4171
4414
|
* Check if the hash of the URL string contains known properties
|
|
4172
4415
|
*/
|
|
4173
4416
|
UrlString.hashContainsKnownProperties = function (hash) {
|
|
4174
|
-
if (StringUtils.isEmpty(hash)) {
|
|
4417
|
+
if (StringUtils.isEmpty(hash) || hash.indexOf("=") < 0) {
|
|
4418
|
+
// Hash doesn't contain key/value pairs
|
|
4175
4419
|
return false;
|
|
4176
4420
|
}
|
|
4177
4421
|
var parameters = UrlString.getDeserializedHash(hash);
|
|
@@ -4198,17 +4442,29 @@ var PopTokenGenerator = /** @class */ (function () {
|
|
|
4198
4442
|
}
|
|
4199
4443
|
PopTokenGenerator.prototype.generateCnf = function (request) {
|
|
4200
4444
|
return __awaiter(this, void 0, void 0, function () {
|
|
4201
|
-
var
|
|
4445
|
+
var reqCnf;
|
|
4446
|
+
return __generator(this, function (_a) {
|
|
4447
|
+
switch (_a.label) {
|
|
4448
|
+
case 0: return [4 /*yield*/, this.generateKid(request)];
|
|
4449
|
+
case 1:
|
|
4450
|
+
reqCnf = _a.sent();
|
|
4451
|
+
return [2 /*return*/, this.cryptoUtils.base64Encode(JSON.stringify(reqCnf))];
|
|
4452
|
+
}
|
|
4453
|
+
});
|
|
4454
|
+
});
|
|
4455
|
+
};
|
|
4456
|
+
PopTokenGenerator.prototype.generateKid = function (request) {
|
|
4457
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4458
|
+
var kidThumbprint;
|
|
4202
4459
|
return __generator(this, function (_a) {
|
|
4203
4460
|
switch (_a.label) {
|
|
4204
4461
|
case 0: return [4 /*yield*/, this.cryptoUtils.getPublicKeyThumbprint(request)];
|
|
4205
4462
|
case 1:
|
|
4206
4463
|
kidThumbprint = _a.sent();
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
return [2 /*return*/, this.cryptoUtils.base64Encode(JSON.stringify(reqCnf))];
|
|
4464
|
+
return [2 /*return*/, {
|
|
4465
|
+
kid: kidThumbprint,
|
|
4466
|
+
xms_ksl: KeyLocation.SW
|
|
4467
|
+
}];
|
|
4212
4468
|
}
|
|
4213
4469
|
});
|
|
4214
4470
|
});
|
|
@@ -4216,28 +4472,27 @@ var PopTokenGenerator = /** @class */ (function () {
|
|
|
4216
4472
|
PopTokenGenerator.prototype.signPopToken = function (accessToken, request) {
|
|
4217
4473
|
var _a;
|
|
4218
4474
|
return __awaiter(this, void 0, void 0, function () {
|
|
4219
|
-
var tokenClaims
|
|
4475
|
+
var tokenClaims;
|
|
4220
4476
|
return __generator(this, function (_b) {
|
|
4221
|
-
|
|
4477
|
+
tokenClaims = AuthToken.extractTokenClaims(accessToken, this.cryptoUtils);
|
|
4478
|
+
if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
|
|
4479
|
+
throw ClientAuthError.createTokenClaimsRequiredError();
|
|
4480
|
+
}
|
|
4481
|
+
return [2 /*return*/, this.signPayload(accessToken, tokenClaims.cnf.kid, request)];
|
|
4482
|
+
});
|
|
4483
|
+
});
|
|
4484
|
+
};
|
|
4485
|
+
PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
|
|
4486
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4487
|
+
var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
|
|
4488
|
+
return __generator(this, function (_a) {
|
|
4489
|
+
switch (_a.label) {
|
|
4222
4490
|
case 0:
|
|
4223
|
-
|
|
4224
|
-
resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims;
|
|
4491
|
+
resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
|
|
4225
4492
|
resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
|
|
4226
4493
|
resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
}
|
|
4230
|
-
return [4 /*yield*/, this.cryptoUtils.signJwt({
|
|
4231
|
-
at: accessToken,
|
|
4232
|
-
ts: TimeUtils.nowSeconds(),
|
|
4233
|
-
m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(),
|
|
4234
|
-
u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort,
|
|
4235
|
-
nonce: this.cryptoUtils.createNewGuid(),
|
|
4236
|
-
p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath,
|
|
4237
|
-
q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined,
|
|
4238
|
-
client_claims: shrClaims || undefined
|
|
4239
|
-
}, tokenClaims.cnf.kid)];
|
|
4240
|
-
case 1: return [2 /*return*/, _b.sent()];
|
|
4494
|
+
return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid)];
|
|
4495
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
4241
4496
|
}
|
|
4242
4497
|
});
|
|
4243
4498
|
});
|
|
@@ -4427,10 +4682,12 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4427
4682
|
if (!!authCodePayload && !!authCodePayload.state) {
|
|
4428
4683
|
requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);
|
|
4429
4684
|
}
|
|
4685
|
+
// Add keyId from request to serverTokenResponse if defined
|
|
4686
|
+
serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
|
|
4430
4687
|
cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
|
|
4431
4688
|
_a.label = 1;
|
|
4432
4689
|
case 1:
|
|
4433
|
-
_a.trys.push([1, ,
|
|
4690
|
+
_a.trys.push([1, , 5, 8]);
|
|
4434
4691
|
if (!(this.persistencePlugin && this.serializableCache)) return [3 /*break*/, 3];
|
|
4435
4692
|
this.logger.verbose("Persistence enabled, calling beforeCacheAccess");
|
|
4436
4693
|
cacheContext = new TokenCacheContext(this.serializableCache, true);
|
|
@@ -4452,17 +4709,19 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4452
4709
|
return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
|
|
4453
4710
|
}
|
|
4454
4711
|
}
|
|
4455
|
-
this.cacheStorage.saveCacheRecord(cacheRecord);
|
|
4456
|
-
return [3 /*break*/, 7];
|
|
4712
|
+
return [4 /*yield*/, this.cacheStorage.saveCacheRecord(cacheRecord)];
|
|
4457
4713
|
case 4:
|
|
4458
|
-
|
|
4714
|
+
_a.sent();
|
|
4715
|
+
return [3 /*break*/, 8];
|
|
4716
|
+
case 5:
|
|
4717
|
+
if (!(this.persistencePlugin && this.serializableCache && cacheContext)) return [3 /*break*/, 7];
|
|
4459
4718
|
this.logger.verbose("Persistence enabled, calling afterCacheAccess");
|
|
4460
4719
|
return [4 /*yield*/, this.persistencePlugin.afterCacheAccess(cacheContext)];
|
|
4461
|
-
case
|
|
4720
|
+
case 6:
|
|
4462
4721
|
_a.sent();
|
|
4463
|
-
_a.label =
|
|
4464
|
-
case
|
|
4465
|
-
case
|
|
4722
|
+
_a.label = 7;
|
|
4723
|
+
case 7: return [7 /*endfinally*/];
|
|
4724
|
+
case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse.spa_code)];
|
|
4466
4725
|
}
|
|
4467
4726
|
});
|
|
4468
4727
|
});
|
|
@@ -4501,7 +4760,7 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4501
4760
|
var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
|
|
4502
4761
|
var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
|
|
4503
4762
|
// non AAD scenarios can have empty realm
|
|
4504
|
-
cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion);
|
|
4763
|
+
cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion, serverTokenResponse.key_id);
|
|
4505
4764
|
}
|
|
4506
4765
|
// refreshToken
|
|
4507
4766
|
var cachedRefreshToken = null;
|
|
@@ -4528,15 +4787,15 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4528
4787
|
// ADFS does not require client_info in the response
|
|
4529
4788
|
if (authorityType === exports.AuthorityType.Adfs) {
|
|
4530
4789
|
this.logger.verbose("Authority type is ADFS, creating ADFS account");
|
|
4531
|
-
return AccountEntity.createGenericAccount(
|
|
4790
|
+
return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
|
|
4532
4791
|
}
|
|
4533
4792
|
// This fallback applies to B2C as well as they fall under an AAD account type.
|
|
4534
4793
|
if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
|
|
4535
4794
|
throw ClientAuthError.createClientInfoEmptyError();
|
|
4536
4795
|
}
|
|
4537
4796
|
return serverTokenResponse.client_info ?
|
|
4538
|
-
AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier,
|
|
4539
|
-
AccountEntity.createGenericAccount(
|
|
4797
|
+
AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
|
|
4798
|
+
AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
|
|
4540
4799
|
};
|
|
4541
4800
|
/**
|
|
4542
4801
|
* Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
|
|
@@ -4548,7 +4807,7 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4548
4807
|
* @param fromTokenCache
|
|
4549
4808
|
* @param stateString
|
|
4550
4809
|
*/
|
|
4551
|
-
ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState) {
|
|
4810
|
+
ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState, code) {
|
|
4552
4811
|
var _a, _b, _c;
|
|
4553
4812
|
return __awaiter(this, void 0, void 0, function () {
|
|
4554
4813
|
var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, uid, tid;
|
|
@@ -4591,12 +4850,14 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4591
4850
|
accessToken: accessToken,
|
|
4592
4851
|
fromCache: fromTokenCache,
|
|
4593
4852
|
expiresOn: expiresOn,
|
|
4853
|
+
correlationId: request.correlationId,
|
|
4594
4854
|
extExpiresOn: extExpiresOn,
|
|
4595
4855
|
familyId: familyId,
|
|
4596
4856
|
tokenType: ((_a = cacheRecord.accessToken) === null || _a === void 0 ? void 0 : _a.tokenType) || Constants.EMPTY_STRING,
|
|
4597
4857
|
state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
|
|
4598
4858
|
cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
|
|
4599
|
-
msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING
|
|
4859
|
+
msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
|
|
4860
|
+
code: code
|
|
4600
4861
|
}];
|
|
4601
4862
|
}
|
|
4602
4863
|
});
|
|
@@ -4615,7 +4876,10 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
4615
4876
|
var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
4616
4877
|
__extends(AuthorizationCodeClient, _super);
|
|
4617
4878
|
function AuthorizationCodeClient(configuration) {
|
|
4618
|
-
|
|
4879
|
+
var _this = _super.call(this, configuration) || this;
|
|
4880
|
+
// Flag to indicate if client is for hybrid spa auth code redemption
|
|
4881
|
+
_this.includeRedirectUri = true;
|
|
4882
|
+
return _this;
|
|
4619
4883
|
}
|
|
4620
4884
|
/**
|
|
4621
4885
|
* Creates the URL of the authorization request letting the user input credentials and consent to the
|
|
@@ -4687,7 +4951,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4687
4951
|
code: serverParams.code });
|
|
4688
4952
|
};
|
|
4689
4953
|
/**
|
|
4690
|
-
*
|
|
4954
|
+
* Used to log out the current user, and redirect the user to the postLogoutRedirectUri.
|
|
4691
4955
|
* Default behaviour is to redirect the user to `window.location.href`.
|
|
4692
4956
|
* @param authorityUri
|
|
4693
4957
|
*/
|
|
@@ -4696,14 +4960,6 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4696
4960
|
if (!logoutRequest) {
|
|
4697
4961
|
throw ClientConfigurationError.createEmptyLogoutRequestError();
|
|
4698
4962
|
}
|
|
4699
|
-
if (logoutRequest.account) {
|
|
4700
|
-
// Clear given account.
|
|
4701
|
-
this.cacheManager.removeAccount(AccountEntity.generateAccountCacheKey(logoutRequest.account));
|
|
4702
|
-
}
|
|
4703
|
-
else {
|
|
4704
|
-
// Clear all accounts and tokens
|
|
4705
|
-
this.cacheManager.clear();
|
|
4706
|
-
}
|
|
4707
4963
|
var queryString = this.createLogoutUrlQueryString(logoutRequest);
|
|
4708
4964
|
// Construct logout URI.
|
|
4709
4965
|
return UrlString.appendQueryString(this.authority.endSessionEndpoint, queryString);
|
|
@@ -4722,7 +4978,13 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4722
4978
|
thumbprint = {
|
|
4723
4979
|
clientId: this.config.authOptions.clientId,
|
|
4724
4980
|
authority: authority.canonicalAuthority,
|
|
4725
|
-
scopes: request.scopes
|
|
4981
|
+
scopes: request.scopes,
|
|
4982
|
+
authenticationScheme: request.authenticationScheme,
|
|
4983
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
4984
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
4985
|
+
shrClaims: request.shrClaims,
|
|
4986
|
+
sshJwk: request.sshJwk,
|
|
4987
|
+
sshKid: request.sshKid
|
|
4726
4988
|
};
|
|
4727
4989
|
return [4 /*yield*/, this.createTokenRequestBody(request)];
|
|
4728
4990
|
case 1:
|
|
@@ -4766,13 +5028,24 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4766
5028
|
AuthorizationCodeClient.prototype.createTokenRequestBody = function (request) {
|
|
4767
5029
|
return __awaiter(this, void 0, void 0, function () {
|
|
4768
5030
|
var parameterBuilder, clientAssertion, popTokenGenerator, cnfString, correlationId, ccsCred, clientInfo, clientInfo;
|
|
4769
|
-
|
|
4770
|
-
|
|
5031
|
+
var _a;
|
|
5032
|
+
return __generator(this, function (_b) {
|
|
5033
|
+
switch (_b.label) {
|
|
4771
5034
|
case 0:
|
|
4772
5035
|
parameterBuilder = new RequestParameterBuilder();
|
|
4773
5036
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
4774
|
-
|
|
4775
|
-
|
|
5037
|
+
/*
|
|
5038
|
+
* For hybrid spa flow, there will be a code but no verifier
|
|
5039
|
+
* In this scenario, don't include redirect uri as auth code will not be bound to redirect URI
|
|
5040
|
+
*/
|
|
5041
|
+
if (!this.includeRedirectUri) {
|
|
5042
|
+
// Just validate
|
|
5043
|
+
RequestValidator.validateRedirectUri(request.redirectUri);
|
|
5044
|
+
}
|
|
5045
|
+
else {
|
|
5046
|
+
// Validate and include redirect uri
|
|
5047
|
+
parameterBuilder.addRedirectUri(request.redirectUri);
|
|
5048
|
+
}
|
|
4776
5049
|
// Add scope array, parameter builder will add default scopes and dedupe
|
|
4777
5050
|
parameterBuilder.addScopes(request.scopes);
|
|
4778
5051
|
// add code: user set, not validated
|
|
@@ -4801,10 +5074,20 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4801
5074
|
popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
|
|
4802
5075
|
return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
|
|
4803
5076
|
case 1:
|
|
4804
|
-
cnfString =
|
|
5077
|
+
cnfString = _b.sent();
|
|
4805
5078
|
parameterBuilder.addPopToken(cnfString);
|
|
4806
|
-
|
|
5079
|
+
return [3 /*break*/, 3];
|
|
4807
5080
|
case 2:
|
|
5081
|
+
if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
|
|
5082
|
+
if (request.sshJwk) {
|
|
5083
|
+
parameterBuilder.addSshJwk(request.sshJwk);
|
|
5084
|
+
}
|
|
5085
|
+
else {
|
|
5086
|
+
throw ClientConfigurationError.createMissingSshJwkError();
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
_b.label = 3;
|
|
5090
|
+
case 3:
|
|
4808
5091
|
correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
|
|
4809
5092
|
parameterBuilder.addCorrelationId(correlationId);
|
|
4810
5093
|
if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
|
|
@@ -4843,6 +5126,15 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4843
5126
|
break;
|
|
4844
5127
|
}
|
|
4845
5128
|
}
|
|
5129
|
+
if (request.tokenBodyParameters) {
|
|
5130
|
+
parameterBuilder.addExtraQueryParameters(request.tokenBodyParameters);
|
|
5131
|
+
}
|
|
5132
|
+
// Add hybrid spa parameters if not already provided
|
|
5133
|
+
if (request.enableSpaAuthorizationCode && (!request.tokenBodyParameters || !request.tokenBodyParameters[AADServerParamKeys.RETURN_SPA_CODE])) {
|
|
5134
|
+
parameterBuilder.addExtraQueryParameters((_a = {},
|
|
5135
|
+
_a[AADServerParamKeys.RETURN_SPA_CODE] = "1",
|
|
5136
|
+
_a));
|
|
5137
|
+
}
|
|
4846
5138
|
return [2 /*return*/, parameterBuilder.createQueryString()];
|
|
4847
5139
|
}
|
|
4848
5140
|
});
|
|
@@ -4958,6 +5250,12 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
|
|
|
4958
5250
|
if (request.idTokenHint) {
|
|
4959
5251
|
parameterBuilder.addIdTokenHint(request.idTokenHint);
|
|
4960
5252
|
}
|
|
5253
|
+
if (request.state) {
|
|
5254
|
+
parameterBuilder.addState(request.state);
|
|
5255
|
+
}
|
|
5256
|
+
if (request.extraQueryParameters) {
|
|
5257
|
+
parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
|
|
5258
|
+
}
|
|
4961
5259
|
return parameterBuilder.createQueryString();
|
|
4962
5260
|
};
|
|
4963
5261
|
/**
|
|
@@ -5026,7 +5324,13 @@ var DeviceCodeClient = /** @class */ (function (_super) {
|
|
|
5026
5324
|
thumbprint = {
|
|
5027
5325
|
clientId: this.config.authOptions.clientId,
|
|
5028
5326
|
authority: request.authority,
|
|
5029
|
-
scopes: request.scopes
|
|
5327
|
+
scopes: request.scopes,
|
|
5328
|
+
authenticationScheme: request.authenticationScheme,
|
|
5329
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
5330
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
5331
|
+
shrClaims: request.shrClaims,
|
|
5332
|
+
sshJwk: request.sshJwk,
|
|
5333
|
+
sshKid: request.sshKid
|
|
5030
5334
|
};
|
|
5031
5335
|
return [2 /*return*/, this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint)];
|
|
5032
5336
|
});
|
|
@@ -5119,7 +5423,13 @@ var DeviceCodeClient = /** @class */ (function (_super) {
|
|
|
5119
5423
|
thumbprint = {
|
|
5120
5424
|
clientId: this.config.authOptions.clientId,
|
|
5121
5425
|
authority: request.authority,
|
|
5122
|
-
scopes: request.scopes
|
|
5426
|
+
scopes: request.scopes,
|
|
5427
|
+
authenticationScheme: request.authenticationScheme,
|
|
5428
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
5429
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
5430
|
+
shrClaims: request.shrClaims,
|
|
5431
|
+
sshJwk: request.sshJwk,
|
|
5432
|
+
sshKid: request.sshKid
|
|
5123
5433
|
};
|
|
5124
5434
|
return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
|
|
5125
5435
|
case 2:
|
|
@@ -5225,7 +5535,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
5225
5535
|
return [2 /*return*/, this.acquireTokenWithCachedRefreshToken(request, true)];
|
|
5226
5536
|
}
|
|
5227
5537
|
catch (e) {
|
|
5228
|
-
noFamilyRTInCache = e instanceof
|
|
5538
|
+
noFamilyRTInCache = e instanceof InteractionRequiredAuthError && e.errorCode === InteractionRequiredAuthErrorMessage.noTokensFoundError.code;
|
|
5229
5539
|
clientMismatchErrorWithFamilyRT = e instanceof ServerError && e.errorCode === Errors.INVALID_GRANT_ERROR && e.subError === Errors.CLIENT_MISMATCH_ERROR;
|
|
5230
5540
|
// if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)
|
|
5231
5541
|
if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {
|
|
@@ -5253,7 +5563,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
5253
5563
|
refreshToken = this.cacheManager.readRefreshTokenFromCache(this.config.authOptions.clientId, request.account, foci);
|
|
5254
5564
|
// no refresh Token
|
|
5255
5565
|
if (!refreshToken) {
|
|
5256
|
-
throw
|
|
5566
|
+
throw InteractionRequiredAuthError.createNoTokensFoundError();
|
|
5257
5567
|
}
|
|
5258
5568
|
refreshTokenRequest = __assign(__assign({}, request), { refreshToken: refreshToken.secret, authenticationScheme: request.authenticationScheme || exports.AuthenticationScheme.BEARER, ccsCredential: {
|
|
5259
5569
|
credential: request.account.homeAccountId,
|
|
@@ -5281,7 +5591,13 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
5281
5591
|
thumbprint = {
|
|
5282
5592
|
clientId: this.config.authOptions.clientId,
|
|
5283
5593
|
authority: authority.canonicalAuthority,
|
|
5284
|
-
scopes: request.scopes
|
|
5594
|
+
scopes: request.scopes,
|
|
5595
|
+
authenticationScheme: request.authenticationScheme,
|
|
5596
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
5597
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
5598
|
+
shrClaims: request.shrClaims,
|
|
5599
|
+
sshJwk: request.sshJwk,
|
|
5600
|
+
sshKid: request.sshKid
|
|
5285
5601
|
};
|
|
5286
5602
|
endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
|
|
5287
5603
|
return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
|
|
@@ -5306,9 +5622,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
5306
5622
|
*/
|
|
5307
5623
|
RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
|
|
5308
5624
|
return __awaiter(this, void 0, void 0, function () {
|
|
5309
|
-
var parameterBuilder, correlationId, clientAssertion, popTokenGenerator,
|
|
5310
|
-
return __generator(this, function (
|
|
5311
|
-
switch (
|
|
5625
|
+
var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
|
|
5626
|
+
return __generator(this, function (_a) {
|
|
5627
|
+
switch (_a.label) {
|
|
5312
5628
|
case 0:
|
|
5313
5629
|
parameterBuilder = new RequestParameterBuilder();
|
|
5314
5630
|
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
@@ -5333,12 +5649,22 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
5333
5649
|
}
|
|
5334
5650
|
if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
|
|
5335
5651
|
popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
|
|
5336
|
-
_b = (_a = parameterBuilder).addPopToken;
|
|
5337
5652
|
return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
|
|
5338
5653
|
case 1:
|
|
5339
|
-
|
|
5340
|
-
|
|
5654
|
+
cnfString = _a.sent();
|
|
5655
|
+
parameterBuilder.addPopToken(cnfString);
|
|
5656
|
+
return [3 /*break*/, 3];
|
|
5341
5657
|
case 2:
|
|
5658
|
+
if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
|
|
5659
|
+
if (request.sshJwk) {
|
|
5660
|
+
parameterBuilder.addSshJwk(request.sshJwk);
|
|
5661
|
+
}
|
|
5662
|
+
else {
|
|
5663
|
+
throw ClientConfigurationError.createMissingSshJwkError();
|
|
5664
|
+
}
|
|
5665
|
+
}
|
|
5666
|
+
_a.label = 3;
|
|
5667
|
+
case 3:
|
|
5342
5668
|
if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
|
|
5343
5669
|
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
5344
5670
|
}
|
|
@@ -5473,7 +5799,13 @@ var ClientCredentialClient = /** @class */ (function (_super) {
|
|
|
5473
5799
|
thumbprint = {
|
|
5474
5800
|
clientId: this.config.authOptions.clientId,
|
|
5475
5801
|
authority: request.authority,
|
|
5476
|
-
scopes: request.scopes
|
|
5802
|
+
scopes: request.scopes,
|
|
5803
|
+
authenticationScheme: request.authenticationScheme,
|
|
5804
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
5805
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
5806
|
+
shrClaims: request.shrClaims,
|
|
5807
|
+
sshJwk: request.sshJwk,
|
|
5808
|
+
sshKid: request.sshKid
|
|
5477
5809
|
};
|
|
5478
5810
|
reqTimestamp = TimeUtils.nowSeconds();
|
|
5479
5811
|
return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
|
|
@@ -5668,7 +6000,13 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
5668
6000
|
thumbprint = {
|
|
5669
6001
|
clientId: this.config.authOptions.clientId,
|
|
5670
6002
|
authority: request.authority,
|
|
5671
|
-
scopes: request.scopes
|
|
6003
|
+
scopes: request.scopes,
|
|
6004
|
+
authenticationScheme: request.authenticationScheme,
|
|
6005
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
6006
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
6007
|
+
shrClaims: request.shrClaims,
|
|
6008
|
+
sshJwk: request.sshJwk,
|
|
6009
|
+
sshKid: request.sshKid
|
|
5672
6010
|
};
|
|
5673
6011
|
reqTimestamp = TimeUtils.nowSeconds();
|
|
5674
6012
|
return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
|
|
@@ -5768,6 +6106,17 @@ var SilentFlowClient = /** @class */ (function (_super) {
|
|
|
5768
6106
|
if (!request) {
|
|
5769
6107
|
throw ClientConfigurationError.createEmptyTokenRequestError();
|
|
5770
6108
|
}
|
|
6109
|
+
if (request.forceRefresh) {
|
|
6110
|
+
// Must refresh due to present force_refresh flag.
|
|
6111
|
+
(_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
|
|
6112
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
|
|
6113
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
6114
|
+
}
|
|
6115
|
+
else if (!StringUtils.isEmptyObj(request.claims)) {
|
|
6116
|
+
// Must refresh due to request parameters.
|
|
6117
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims are requested.");
|
|
6118
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
6119
|
+
}
|
|
5771
6120
|
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
5772
6121
|
if (!request.account) {
|
|
5773
6122
|
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
@@ -5775,30 +6124,24 @@ var SilentFlowClient = /** @class */ (function (_super) {
|
|
|
5775
6124
|
requestScopes = new ScopeSet(request.scopes || []);
|
|
5776
6125
|
environment = request.authority || this.authority.getPreferredCache();
|
|
5777
6126
|
authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
|
|
5778
|
-
cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme);
|
|
5779
|
-
if (
|
|
5780
|
-
// Must refresh due to present force_refresh flag.
|
|
5781
|
-
(_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
|
|
5782
|
-
throw ClientAuthError.createRefreshRequiredError();
|
|
5783
|
-
}
|
|
5784
|
-
else if (!cacheRecord.accessToken) {
|
|
6127
|
+
cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme, request.sshKid);
|
|
6128
|
+
if (!cacheRecord.accessToken) {
|
|
5785
6129
|
// Must refresh due to non-existent access_token.
|
|
5786
6130
|
(_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
6131
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
|
|
5787
6132
|
throw ClientAuthError.createRefreshRequiredError();
|
|
5788
6133
|
}
|
|
5789
6134
|
else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
|
|
5790
6135
|
TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
5791
6136
|
// Must refresh due to expired access_token.
|
|
5792
6137
|
(_c = this.serverTelemetryManager) === null || _c === void 0 ? void 0 : _c.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
6138
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
|
|
5793
6139
|
throw ClientAuthError.createRefreshRequiredError();
|
|
5794
6140
|
}
|
|
5795
6141
|
else if (cacheRecord.accessToken.refreshOn && TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
|
|
5796
6142
|
// Must refresh due to the refresh_in value.
|
|
5797
6143
|
(_d = this.serverTelemetryManager) === null || _d === void 0 ? void 0 : _d.setCacheOutcome(CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
|
|
5798
|
-
|
|
5799
|
-
}
|
|
5800
|
-
else if (!StringUtils.isEmptyObj(request.claims)) {
|
|
5801
|
-
// Must refresh due to request parameters.
|
|
6144
|
+
this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'.");
|
|
5802
6145
|
throw ClientAuthError.createRefreshRequiredError();
|
|
5803
6146
|
}
|
|
5804
6147
|
if (this.config.serverTelemetryManager) {
|
|
@@ -5882,7 +6225,13 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
|
|
|
5882
6225
|
thumbprint = {
|
|
5883
6226
|
clientId: this.config.authOptions.clientId,
|
|
5884
6227
|
authority: authority.canonicalAuthority,
|
|
5885
|
-
scopes: request.scopes
|
|
6228
|
+
scopes: request.scopes,
|
|
6229
|
+
authenticationScheme: request.authenticationScheme,
|
|
6230
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
6231
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
6232
|
+
shrClaims: request.shrClaims,
|
|
6233
|
+
sshJwk: request.sshJwk,
|
|
6234
|
+
sshKid: request.sshKid
|
|
5886
6235
|
};
|
|
5887
6236
|
requestBody = this.createTokenRequestBody(request);
|
|
5888
6237
|
headers = this.createTokenRequestHeaders({
|
|
@@ -5938,7 +6287,6 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
|
|
|
5938
6287
|
function isOpenIdConfigResponse(response) {
|
|
5939
6288
|
return (response.hasOwnProperty("authorization_endpoint") &&
|
|
5940
6289
|
response.hasOwnProperty("token_endpoint") &&
|
|
5941
|
-
response.hasOwnProperty("end_session_endpoint") &&
|
|
5942
6290
|
response.hasOwnProperty("issuer"));
|
|
5943
6291
|
}
|
|
5944
6292
|
|
|
@@ -6020,7 +6368,6 @@ var AuthorityMetadataEntity = /** @class */ (function () {
|
|
|
6020
6368
|
entity.hasOwnProperty("canonical_authority") &&
|
|
6021
6369
|
entity.hasOwnProperty("authorization_endpoint") &&
|
|
6022
6370
|
entity.hasOwnProperty("token_endpoint") &&
|
|
6023
|
-
entity.hasOwnProperty("end_session_endpoint") &&
|
|
6024
6371
|
entity.hasOwnProperty("issuer") &&
|
|
6025
6372
|
entity.hasOwnProperty("aliasesFromNetwork") &&
|
|
6026
6373
|
entity.hasOwnProperty("endpointsFromNetwork") &&
|
|
@@ -6302,6 +6649,10 @@ var Authority = /** @class */ (function () {
|
|
|
6302
6649
|
*/
|
|
6303
6650
|
get: function () {
|
|
6304
6651
|
if (this.discoveryComplete()) {
|
|
6652
|
+
// ROPC policies may not have end_session_endpoint set
|
|
6653
|
+
if (!this.metadata.end_session_endpoint) {
|
|
6654
|
+
throw ClientAuthError.createLogoutNotSupportedError();
|
|
6655
|
+
}
|
|
6305
6656
|
var endpoint = this.replacePath(this.metadata.end_session_endpoint);
|
|
6306
6657
|
return this.replaceTenant(endpoint);
|
|
6307
6658
|
}
|
|
@@ -6702,7 +7053,9 @@ var Authority = /** @class */ (function () {
|
|
|
6702
7053
|
metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
|
|
6703
7054
|
// TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
|
|
6704
7055
|
metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
|
|
6705
|
-
|
|
7056
|
+
if (metadata.end_session_endpoint) {
|
|
7057
|
+
metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
|
|
7058
|
+
}
|
|
6706
7059
|
return metadata;
|
|
6707
7060
|
};
|
|
6708
7061
|
return Authority;
|
|
@@ -6837,6 +7190,63 @@ var StubbedNetworkModule = {
|
|
|
6837
7190
|
}
|
|
6838
7191
|
};
|
|
6839
7192
|
|
|
7193
|
+
/*
|
|
7194
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7195
|
+
* Licensed under the MIT License.
|
|
7196
|
+
*/
|
|
7197
|
+
/**
|
|
7198
|
+
* This is a helper class that parses supported HTTP response authentication headers to extract and return
|
|
7199
|
+
* header challenge values that can be used outside the basic authorization flows.
|
|
7200
|
+
*/
|
|
7201
|
+
var AuthenticationHeaderParser = /** @class */ (function () {
|
|
7202
|
+
function AuthenticationHeaderParser(headers) {
|
|
7203
|
+
this.headers = headers;
|
|
7204
|
+
}
|
|
7205
|
+
/**
|
|
7206
|
+
* This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.
|
|
7207
|
+
* @returns
|
|
7208
|
+
*/
|
|
7209
|
+
AuthenticationHeaderParser.prototype.getShrNonce = function () {
|
|
7210
|
+
// Attempt to parse nonce from Authentiacation-Info
|
|
7211
|
+
var authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];
|
|
7212
|
+
if (authenticationInfo) {
|
|
7213
|
+
var authenticationInfoChallenges = this.parseChallenges(authenticationInfo);
|
|
7214
|
+
if (authenticationInfoChallenges.nextnonce) {
|
|
7215
|
+
return authenticationInfoChallenges.nextnonce;
|
|
7216
|
+
}
|
|
7217
|
+
throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.AuthenticationInfo, "nextnonce challenge is missing.");
|
|
7218
|
+
}
|
|
7219
|
+
// Attempt to parse nonce from WWW-Authenticate
|
|
7220
|
+
var wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];
|
|
7221
|
+
if (wwwAuthenticate) {
|
|
7222
|
+
var wwwAuthenticateChallenges = this.parseChallenges(wwwAuthenticate);
|
|
7223
|
+
if (wwwAuthenticateChallenges.nonce) {
|
|
7224
|
+
return wwwAuthenticateChallenges.nonce;
|
|
7225
|
+
}
|
|
7226
|
+
throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.WWWAuthenticate, "nonce challenge is missing.");
|
|
7227
|
+
}
|
|
7228
|
+
// If neither header is present, throw missing headers error
|
|
7229
|
+
throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();
|
|
7230
|
+
};
|
|
7231
|
+
/**
|
|
7232
|
+
* Parses an HTTP header's challenge set into a key/value map.
|
|
7233
|
+
* @param header
|
|
7234
|
+
* @returns
|
|
7235
|
+
*/
|
|
7236
|
+
AuthenticationHeaderParser.prototype.parseChallenges = function (header) {
|
|
7237
|
+
var schemeSeparator = header.indexOf(" ");
|
|
7238
|
+
var challenges = header.substr(schemeSeparator + 1).split(",");
|
|
7239
|
+
var challengeMap = {};
|
|
7240
|
+
challenges.forEach(function (challenge) {
|
|
7241
|
+
var _a = challenge.split("="), key = _a[0], value = _a[1];
|
|
7242
|
+
// Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
|
|
7243
|
+
challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
|
|
7244
|
+
});
|
|
7245
|
+
return challengeMap;
|
|
7246
|
+
};
|
|
7247
|
+
return AuthenticationHeaderParser;
|
|
7248
|
+
}());
|
|
7249
|
+
|
|
6840
7250
|
/*
|
|
6841
7251
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6842
7252
|
* Licensed under the MIT License.
|
|
@@ -7003,6 +7413,7 @@ exports.AppMetadataEntity = AppMetadataEntity;
|
|
|
7003
7413
|
exports.AuthError = AuthError;
|
|
7004
7414
|
exports.AuthErrorMessage = AuthErrorMessage;
|
|
7005
7415
|
exports.AuthToken = AuthToken;
|
|
7416
|
+
exports.AuthenticationHeaderParser = AuthenticationHeaderParser;
|
|
7006
7417
|
exports.Authority = Authority;
|
|
7007
7418
|
exports.AuthorityFactory = AuthorityFactory;
|
|
7008
7419
|
exports.AuthorityMetadataEntity = AuthorityMetadataEntity;
|
|
@@ -7022,14 +7433,17 @@ exports.DeviceCodeClient = DeviceCodeClient;
|
|
|
7022
7433
|
exports.IdToken = AuthToken;
|
|
7023
7434
|
exports.IdTokenEntity = IdTokenEntity;
|
|
7024
7435
|
exports.InteractionRequiredAuthError = InteractionRequiredAuthError;
|
|
7436
|
+
exports.InteractionRequiredAuthErrorMessage = InteractionRequiredAuthErrorMessage;
|
|
7025
7437
|
exports.Logger = Logger;
|
|
7026
7438
|
exports.NetworkManager = NetworkManager;
|
|
7027
7439
|
exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
|
|
7028
7440
|
exports.OnBehalfOfClient = OnBehalfOfClient;
|
|
7441
|
+
exports.PopTokenGenerator = PopTokenGenerator;
|
|
7029
7442
|
exports.PromptValue = PromptValue;
|
|
7030
7443
|
exports.ProtocolUtils = ProtocolUtils;
|
|
7031
7444
|
exports.RefreshTokenClient = RefreshTokenClient;
|
|
7032
7445
|
exports.RefreshTokenEntity = RefreshTokenEntity;
|
|
7446
|
+
exports.ScopeSet = ScopeSet;
|
|
7033
7447
|
exports.ServerError = ServerError;
|
|
7034
7448
|
exports.ServerTelemetryEntity = ServerTelemetryEntity;
|
|
7035
7449
|
exports.ServerTelemetryManager = ServerTelemetryManager;
|
|
@@ -7042,4 +7456,5 @@ exports.TimeUtils = TimeUtils;
|
|
|
7042
7456
|
exports.TokenCacheContext = TokenCacheContext;
|
|
7043
7457
|
exports.UrlString = UrlString;
|
|
7044
7458
|
exports.UsernamePasswordClient = UsernamePasswordClient;
|
|
7459
|
+
exports.version = version;
|
|
7045
7460
|
//# sourceMappingURL=index.cjs.js.map
|