@azure/msal-common 4.2.1 → 4.5.1
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 +212 -1
- package/LICENSE +21 -21
- package/README.md +61 -58
- package/changelog.md +402 -344
- package/dist/_virtual/_tslib.js +90 -0
- package/dist/_virtual/_tslib.js.map +1 -0
- package/dist/account/AuthToken.js +43 -0
- package/dist/account/AuthToken.js.map +1 -0
- package/dist/account/CcsCredential.d.ts +9 -0
- package/dist/account/CcsCredential.d.ts.map +1 -0
- package/dist/account/CcsCredential.js +14 -0
- package/dist/account/CcsCredential.js.map +1 -0
- package/dist/account/ClientInfo.d.ts +6 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.js +44 -0
- package/dist/account/ClientInfo.js.map +1 -0
- package/dist/account/TokenClaims.d.ts +1 -0
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/authority/Authority.d.ts +25 -0
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.js +574 -0
- package/dist/authority/Authority.js.map +1 -0
- package/dist/authority/AuthorityFactory.js +69 -0
- package/dist/authority/AuthorityFactory.js.map +1 -0
- package/dist/authority/AuthorityOptions.d.ts +2 -0
- package/dist/authority/AuthorityOptions.d.ts.map +1 -1
- package/dist/authority/AuthorityType.js +17 -0
- package/dist/authority/AuthorityType.js.map +1 -0
- package/dist/authority/AzureRegion.d.ts +2 -0
- package/dist/authority/AzureRegion.d.ts.map +1 -0
- package/dist/authority/AzureRegionConfiguration.d.ts +6 -0
- package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.js +13 -0
- package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -0
- package/dist/authority/OpenIdConfigResponse.js +15 -0
- package/dist/authority/OpenIdConfigResponse.js.map +1 -0
- package/dist/authority/ProtocolMode.js +17 -0
- package/dist/authority/ProtocolMode.js.map +1 -0
- package/dist/authority/RegionDiscovery.d.ts +31 -0
- package/dist/authority/RegionDiscovery.d.ts.map +1 -0
- package/dist/authority/RegionDiscovery.js +119 -0
- package/dist/authority/RegionDiscovery.js.map +1 -0
- package/dist/authority/RegionDiscoveryMetadata.d.ts +7 -0
- package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -0
- package/dist/cache/CacheManager.js +713 -0
- package/dist/cache/CacheManager.js.map +1 -0
- package/dist/cache/entities/AccessTokenEntity.js +111 -0
- package/dist/cache/entities/AccessTokenEntity.js.map +1 -0
- package/dist/cache/entities/AccountEntity.d.ts +5 -5
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.js +242 -0
- package/dist/cache/entities/AccountEntity.js.map +1 -0
- package/dist/cache/entities/AppMetadataEntity.js +74 -0
- package/dist/cache/entities/AppMetadataEntity.js.map +1 -0
- package/dist/cache/entities/AuthorityMetadataEntity.js +81 -0
- package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -0
- package/dist/cache/entities/CacheRecord.js +19 -0
- package/dist/cache/entities/CacheRecord.js.map +1 -0
- package/dist/cache/entities/CredentialEntity.js +142 -0
- package/dist/cache/entities/CredentialEntity.js.map +1 -0
- package/dist/cache/entities/IdTokenEntity.js +71 -0
- package/dist/cache/entities/IdTokenEntity.js.map +1 -0
- package/dist/cache/entities/RefreshTokenEntity.js +73 -0
- package/dist/cache/entities/RefreshTokenEntity.js.map +1 -0
- package/dist/cache/entities/ServerTelemetryEntity.js +35 -0
- package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -0
- package/dist/cache/entities/ThrottlingEntity.js +32 -0
- package/dist/cache/entities/ThrottlingEntity.js.map +1 -0
- package/dist/cache/persistence/TokenCacheContext.js +39 -0
- package/dist/cache/persistence/TokenCacheContext.js.map +1 -0
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.js +388 -0
- package/dist/client/AuthorizationCodeClient.js.map +1 -0
- package/dist/client/BaseClient.d.ts +2 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.js +101 -0
- package/dist/client/BaseClient.js.map +1 -0
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.js +169 -0
- package/dist/client/ClientCredentialClient.js.map +1 -0
- package/dist/client/DeviceCodeClient.d.ts +6 -0
- package/dist/client/DeviceCodeClient.d.ts.map +1 -1
- package/dist/client/DeviceCodeClient.js +212 -0
- package/dist/client/DeviceCodeClient.js.map +1 -0
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.js +209 -0
- package/dist/client/OnBehalfOfClient.js.map +1 -0
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.js +212 -0
- package/dist/client/RefreshTokenClient.js.map +1 -0
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.js +132 -0
- package/dist/client/SilentFlowClient.js.map +1 -0
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.js +112 -0
- package/dist/client/UsernamePasswordClient.js.map +1 -0
- package/dist/config/ClientConfiguration.d.ts +3 -0
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.js +91 -0
- package/dist/config/ClientConfiguration.js.map +1 -0
- package/dist/crypto/ICrypto.js +53 -0
- package/dist/crypto/ICrypto.js.map +1 -0
- package/dist/crypto/PopTokenGenerator.js +72 -0
- package/dist/crypto/PopTokenGenerator.js.map +1 -0
- package/dist/error/AuthError.js +46 -0
- package/dist/error/AuthError.js.map +1 -0
- package/dist/error/ClientAuthError.d.ts +13 -6
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.js +456 -0
- package/dist/error/ClientAuthError.js.map +1 -0
- package/dist/error/ClientConfigurationError.d.ts +1 -6
- package/dist/error/ClientConfigurationError.d.ts.map +1 -1
- package/dist/error/ClientConfigurationError.js +210 -0
- package/dist/error/ClientConfigurationError.js.map +1 -0
- package/dist/error/InteractionRequiredAuthError.js +48 -0
- package/dist/error/InteractionRequiredAuthError.js.map +1 -0
- package/dist/error/ServerError.js +25 -0
- package/dist/error/ServerError.js.map +1 -0
- package/dist/index.cjs.js +7045 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -6479
- package/dist/index.js.map +1 -0
- package/dist/logger/Logger.d.ts +12 -3
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +183 -0
- package/dist/logger/Logger.js.map +1 -0
- package/dist/network/INetworkModule.d.ts +1 -1
- package/dist/network/INetworkModule.d.ts.map +1 -1
- package/dist/network/INetworkModule.js +21 -0
- package/dist/network/INetworkModule.js.map +1 -0
- package/dist/network/NetworkManager.js +56 -0
- package/dist/network/NetworkManager.js.map +1 -0
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.js +95 -0
- package/dist/network/ThrottlingUtils.js.map +1 -0
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +8 -0
- package/dist/packageMetadata.js.map +1 -0
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +3 -0
- package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +1 -0
- package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/CommonClientCredentialRequest.d.ts +7 -4
- package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/CommonRefreshTokenRequest.d.ts +2 -0
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts +11 -0
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.js +340 -0
- package/dist/request/RequestParameterBuilder.js.map +1 -0
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.js +92 -0
- package/dist/request/RequestValidator.js.map +1 -0
- package/dist/request/ScopeSet.js +192 -0
- package/dist/request/ScopeSet.js.map +1 -0
- package/dist/response/AuthenticationResult.d.ts +1 -1
- package/dist/response/AuthenticationResult.d.ts.map +1 -1
- package/dist/response/AuthorizationCodePayload.d.ts +1 -0
- package/dist/response/AuthorizationCodePayload.d.ts.map +1 -1
- package/dist/response/IMDSBadResponse.d.ts +5 -0
- package/dist/response/IMDSBadResponse.d.ts.map +1 -0
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.js +281 -0
- package/dist/response/ResponseHandler.js.map +1 -0
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +23 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.js +168 -0
- package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -0
- package/dist/url/UrlString.d.ts +10 -0
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.js +223 -0
- package/dist/url/UrlString.js.map +1 -0
- package/dist/utils/Constants.d.ts +47 -4
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +362 -0
- package/dist/utils/Constants.js.map +1 -0
- package/dist/utils/ProtocolUtils.js +77 -0
- package/dist/utils/ProtocolUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +5 -0
- package/dist/utils/StringUtils.d.ts.map +1 -1
- package/dist/utils/StringUtils.js +128 -0
- package/dist/utils/StringUtils.js.map +1 -0
- package/dist/utils/TimeUtils.d.ts +13 -0
- package/dist/utils/TimeUtils.d.ts.map +1 -1
- package/dist/utils/TimeUtils.js +53 -0
- package/dist/utils/TimeUtils.js.map +1 -0
- package/package.json +10 -19
- package/dist/index.es.js +0 -6472
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*! @azure/msal-common v4.5.1 2021-08-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
|
|
4
|
+
import { BaseClient } from './BaseClient.js';
|
|
5
|
+
import { RequestParameterBuilder } from '../request/RequestParameterBuilder.js';
|
|
6
|
+
import { ScopeSet } from '../request/ScopeSet.js';
|
|
7
|
+
import { CredentialType, GrantType, AADServerParamKeys, CacheOutcome, Constants } from '../utils/Constants.js';
|
|
8
|
+
import { ResponseHandler } from '../response/ResponseHandler.js';
|
|
9
|
+
import { TimeUtils } from '../utils/TimeUtils.js';
|
|
10
|
+
import { AuthToken } from '../account/AuthToken.js';
|
|
11
|
+
import { ClientAuthError } from '../error/ClientAuthError.js';
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
|
+
* Licensed under the MIT License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* On-Behalf-Of client
|
|
19
|
+
*/
|
|
20
|
+
var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
21
|
+
__extends(OnBehalfOfClient, _super);
|
|
22
|
+
function OnBehalfOfClient(configuration) {
|
|
23
|
+
return _super.call(this, configuration) || this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Public API to acquire tokens with on behalf of flow
|
|
27
|
+
* @param request
|
|
28
|
+
*/
|
|
29
|
+
OnBehalfOfClient.prototype.acquireToken = function (request) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
31
|
+
var cachedAuthenticationResult;
|
|
32
|
+
return __generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
|
+
case 0:
|
|
35
|
+
this.scopeSet = new ScopeSet(request.scopes || []);
|
|
36
|
+
if (!request.skipCache) return [3 /*break*/, 2];
|
|
37
|
+
return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
|
|
38
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
39
|
+
case 2: return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
|
|
40
|
+
case 3:
|
|
41
|
+
cachedAuthenticationResult = _a.sent();
|
|
42
|
+
if (!cachedAuthenticationResult) return [3 /*break*/, 4];
|
|
43
|
+
return [2 /*return*/, cachedAuthenticationResult];
|
|
44
|
+
case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
|
|
45
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* look up cache for tokens
|
|
52
|
+
* @param request
|
|
53
|
+
*/
|
|
54
|
+
OnBehalfOfClient.prototype.getCachedAuthenticationResult = function (request) {
|
|
55
|
+
var _a;
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var cachedAccessToken, cachedIdToken, idTokenObject, cachedAccount, localAccountId, accountInfo;
|
|
58
|
+
return __generator(this, function (_b) {
|
|
59
|
+
switch (_b.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
cachedAccessToken = this.readAccessTokenFromCache();
|
|
62
|
+
if (!cachedAccessToken ||
|
|
63
|
+
TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
64
|
+
// Update the server telemetry outcome
|
|
65
|
+
(_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
66
|
+
return [2 /*return*/, null];
|
|
67
|
+
}
|
|
68
|
+
cachedIdToken = this.readIdTokenFromCache(request);
|
|
69
|
+
cachedAccount = null;
|
|
70
|
+
if (cachedIdToken) {
|
|
71
|
+
idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
|
|
72
|
+
localAccountId = idTokenObject.claims.oid ? idTokenObject.claims.oid : idTokenObject.claims.sub;
|
|
73
|
+
accountInfo = {
|
|
74
|
+
homeAccountId: cachedIdToken.homeAccountId,
|
|
75
|
+
environment: cachedIdToken.environment,
|
|
76
|
+
tenantId: cachedIdToken.realm,
|
|
77
|
+
username: Constants.EMPTY_STRING,
|
|
78
|
+
localAccountId: localAccountId || ""
|
|
79
|
+
};
|
|
80
|
+
cachedAccount = this.readAccountFromCache(accountInfo);
|
|
81
|
+
}
|
|
82
|
+
return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
|
|
83
|
+
account: cachedAccount,
|
|
84
|
+
accessToken: cachedAccessToken,
|
|
85
|
+
idToken: cachedIdToken,
|
|
86
|
+
refreshToken: null,
|
|
87
|
+
appMetadata: null
|
|
88
|
+
}, true, request, idTokenObject)];
|
|
89
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* read access token from cache TODO: CacheManager API should be used here
|
|
96
|
+
* @param request
|
|
97
|
+
*/
|
|
98
|
+
OnBehalfOfClient.prototype.readAccessTokenFromCache = function () {
|
|
99
|
+
var accessTokenFilter = {
|
|
100
|
+
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
101
|
+
credentialType: CredentialType.ACCESS_TOKEN,
|
|
102
|
+
clientId: this.config.authOptions.clientId,
|
|
103
|
+
realm: this.authority.tenant,
|
|
104
|
+
target: this.scopeSet.printScopesLowerCase(),
|
|
105
|
+
};
|
|
106
|
+
var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
|
|
107
|
+
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
108
|
+
var numAccessTokens = accessTokens.length;
|
|
109
|
+
if (numAccessTokens < 1) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
else if (numAccessTokens > 1) {
|
|
113
|
+
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
114
|
+
}
|
|
115
|
+
return accessTokens[0];
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* read idtoken from cache TODO: CacheManager API should be used here instead
|
|
119
|
+
* @param request
|
|
120
|
+
*/
|
|
121
|
+
OnBehalfOfClient.prototype.readIdTokenFromCache = function (request) {
|
|
122
|
+
var idTokenFilter = {
|
|
123
|
+
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
124
|
+
credentialType: CredentialType.ID_TOKEN,
|
|
125
|
+
clientId: this.config.authOptions.clientId,
|
|
126
|
+
realm: this.authority.tenant,
|
|
127
|
+
oboAssertion: request.oboAssertion
|
|
128
|
+
};
|
|
129
|
+
var credentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);
|
|
130
|
+
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
131
|
+
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
132
|
+
if (idTokens.length < 1) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return idTokens[0];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* read account from cache, TODO: CacheManager API should be used here instead
|
|
139
|
+
* @param account
|
|
140
|
+
*/
|
|
141
|
+
OnBehalfOfClient.prototype.readAccountFromCache = function (account) {
|
|
142
|
+
return this.cacheManager.readAccountFromCache(account);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Make a network call to the server requesting credentials
|
|
146
|
+
* @param request
|
|
147
|
+
* @param authority
|
|
148
|
+
*/
|
|
149
|
+
OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
|
|
152
|
+
return __generator(this, function (_a) {
|
|
153
|
+
switch (_a.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
requestBody = this.createTokenRequestBody(request);
|
|
156
|
+
headers = this.createTokenRequestHeaders();
|
|
157
|
+
thumbprint = {
|
|
158
|
+
clientId: this.config.authOptions.clientId,
|
|
159
|
+
authority: request.authority,
|
|
160
|
+
scopes: request.scopes
|
|
161
|
+
};
|
|
162
|
+
reqTimestamp = TimeUtils.nowSeconds();
|
|
163
|
+
return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
|
|
164
|
+
case 1:
|
|
165
|
+
response = _a.sent();
|
|
166
|
+
responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
167
|
+
responseHandler.validateTokenResponse(response.body);
|
|
168
|
+
return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
|
|
169
|
+
case 2:
|
|
170
|
+
tokenResponse = _a.sent();
|
|
171
|
+
return [2 /*return*/, tokenResponse];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* generate a server request in accepable format
|
|
178
|
+
* @param request
|
|
179
|
+
*/
|
|
180
|
+
OnBehalfOfClient.prototype.createTokenRequestBody = function (request) {
|
|
181
|
+
var parameterBuilder = new RequestParameterBuilder();
|
|
182
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
183
|
+
parameterBuilder.addScopes(request.scopes);
|
|
184
|
+
parameterBuilder.addGrantType(GrantType.JWT_BEARER);
|
|
185
|
+
parameterBuilder.addClientInfo();
|
|
186
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
187
|
+
parameterBuilder.addThrottling();
|
|
188
|
+
if (this.serverTelemetryManager) {
|
|
189
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
190
|
+
}
|
|
191
|
+
var correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
|
|
192
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
193
|
+
parameterBuilder.addRequestTokenUse(AADServerParamKeys.ON_BEHALF_OF);
|
|
194
|
+
parameterBuilder.addOboAssertion(request.oboAssertion);
|
|
195
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
196
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
197
|
+
}
|
|
198
|
+
if (this.config.clientCredentials.clientAssertion) {
|
|
199
|
+
var clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
200
|
+
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
201
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
202
|
+
}
|
|
203
|
+
return parameterBuilder.createQueryString();
|
|
204
|
+
};
|
|
205
|
+
return OnBehalfOfClient;
|
|
206
|
+
}(BaseClient));
|
|
207
|
+
|
|
208
|
+
export { OnBehalfOfClient };
|
|
209
|
+
//# sourceMappingURL=OnBehalfOfClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnBehalfOfClient.js","sources":["../../src/client/OnBehalfOfClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType, AADServerParamKeys , CredentialType, Constants, CacheOutcome } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonOnBehalfOfRequest } from \"../request/CommonOnBehalfOfRequest\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { AccountInfo } from \"../account/AccountInfo\";\n\n/**\n * On-Behalf-Of client\n */\nexport class OnBehalfOfClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Public API to acquire tokens with on behalf of flow\n * @param request\n */\n public async acquireToken(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority);\n }\n\n const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);\n if (cachedAuthenticationResult) {\n return cachedAuthenticationResult;\n } else {\n return await this.executeTokenRequest(request, this.authority);\n }\n }\n\n /**\n * look up cache for tokens\n * @param request\n */\n private async getCachedAuthenticationResult(request: CommonOnBehalfOfRequest): Promise<AuthenticationResult | null> {\n const cachedAccessToken = this.readAccessTokenFromCache();\n if (!cachedAccessToken ||\n TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n\n // Update the server telemetry outcome\n this.serverTelemetryManager?.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n\n return null;\n }\n\n const cachedIdToken = this.readIdTokenFromCache(request);\n let idTokenObject: AuthToken | undefined;\n let cachedAccount: AccountEntity | null = null;\n if (cachedIdToken) {\n idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);\n const localAccountId = idTokenObject.claims.oid ? idTokenObject.claims.oid : idTokenObject.claims.sub;\n const accountInfo: AccountInfo = {\n homeAccountId: cachedIdToken.homeAccountId,\n environment: cachedIdToken.environment,\n tenantId: cachedIdToken.realm,\n username: Constants.EMPTY_STRING,\n localAccountId: localAccountId || \"\"\n };\n\n cachedAccount = this.readAccountFromCache(accountInfo);\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: cachedAccount,\n accessToken: cachedAccessToken,\n idToken: cachedIdToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request,\n idTokenObject);\n }\n\n /**\n * read access token from cache TODO: CacheManager API should be used here\n * @param request\n */\n private readAccessTokenFromCache(): AccessTokenEntity | null {\n const accessTokenFilter: CredentialFilter = {\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ACCESS_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant,\n target: this.scopeSet.printScopesLowerCase(),\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n const accessTokens = Object.keys(credentialCache.accessTokens).map(key => credentialCache.accessTokens[key]);\n\n const numAccessTokens = accessTokens.length;\n if (numAccessTokens < 1) {\n return null;\n } else if (numAccessTokens > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * read idtoken from cache TODO: CacheManager API should be used here instead\n * @param request\n */\n private readIdTokenFromCache(request: CommonOnBehalfOfRequest): IdTokenEntity | null {\n const idTokenFilter: CredentialFilter = {\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ID_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant,\n oboAssertion: request.oboAssertion\n };\n\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);\n const idTokens = Object.keys(credentialCache.idTokens).map(key => credentialCache.idTokens[key]);\n // When acquiring a token on behalf of an application, there might not be an id token in the cache\n if (idTokens.length < 1) {\n return null;\n }\n return idTokens[0] as IdTokenEntity;\n }\n\n /**\n * read account from cache, TODO: CacheManager API should be used here instead\n * @param account\n */\n private readAccountFromCache(account: AccountInfo): AccountEntity | null {\n return this.cacheManager.readAccountFromCache(account);\n }\n\n /**\n * Make a network call to the server requesting credentials\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonOnBehalfOfRequest, authority: Authority)\n : Promise<AuthenticationResult | null> {\n\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes\n };\n\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(response.body);\n const tokenResponse = await responseHandler.handleServerTokenResponse(\n response.body,\n this.authority,\n reqTimestamp,\n request\n );\n\n return tokenResponse;\n }\n\n /**\n * generate a server request in accepable format\n * @param request\n */\n private createTokenRequestBody(request: CommonOnBehalfOfRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes);\n\n parameterBuilder.addGrantType(GrantType.JWT_BEARER);\n\n parameterBuilder.addClientInfo();\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n\n parameterBuilder.addThrottling();\n \n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n parameterBuilder.addRequestTokenUse(AADServerParamKeys.ON_BEHALF_OF);\n\n parameterBuilder.addOboAssertion(request.oboAssertion);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n if (this.config.clientCredentials.clientAssertion) {\n const clientAssertion = this.config.clientCredentials.clientAssertion;\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAwBA;;;;IAGsC,oCAAU;IAI5C,0BAAY,aAAkC;eAC1C,kBAAM,aAAa,CAAC;KACvB;;;;;IAMY,uCAAY,GAAzB,UAA0B,OAAgC;;;;;;wBACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;6BAE/C,OAAO,CAAC,SAAS,EAAjB,wBAAiB;wBACV,qBAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAA;4BAA9D,sBAAO,SAAuD,EAAC;4BAGhC,qBAAM,IAAI,CAAC,6BAA6B,CAAC,OAAO,CAAC,EAAA;;wBAA9E,0BAA0B,GAAG,SAAiD;6BAChF,0BAA0B,EAA1B,wBAA0B;wBAC1B,sBAAO,0BAA0B,EAAC;4BAE3B,qBAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAA;4BAA9D,sBAAO,SAAuD,EAAC;;;;KAEtE;;;;;IAMa,wDAA6B,GAA3C,UAA4C,OAAgC;;;;;;;wBAClE,iBAAiB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;wBAC1D,IAAI,CAAC,iBAAiB;4BAClB,SAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,yBAAyB,CAAC,EAAE;;4BAG5G,MAAA,IAAI,CAAC,sBAAsB,0CAAE,eAAe,CAAC,CAAC,iBAAiB,GAAG,YA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C,kBAAkB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAC/D,gBAAgB,CAAC,sBAAsB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;SAC1E;QAED,OAAO,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;KAC/C;IACL,uBAAC;AAAD,CAlNA,CAAsC,UAAU;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshTokenClient.d.ts","sourceRoot":"","sources":["../../src/client/RefreshTokenClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"RefreshTokenClient.d.ts","sourceRoot":"","sources":["../../src/client/RefreshTokenClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAS7E;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;gBAElC,aAAa,EAAE,mBAAmB;IAIjC,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAyB5F;;;OAGG;IACU,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCxG;;;OAGG;YACW,kCAAkC;IAsBhD;;;;OAIG;YACW,mBAAmB;IAgBjC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAUlC;;;OAGG;YACW,sBAAsB;CA8DvC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/*! @azure/msal-common v4.5.1 2021-08-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
|
|
4
|
+
import { BaseClient } from './BaseClient.js';
|
|
5
|
+
import { RequestParameterBuilder } from '../request/RequestParameterBuilder.js';
|
|
6
|
+
import { AuthenticationScheme, GrantType, Errors } from '../utils/Constants.js';
|
|
7
|
+
import { ResponseHandler } from '../response/ResponseHandler.js';
|
|
8
|
+
import { PopTokenGenerator } from '../crypto/PopTokenGenerator.js';
|
|
9
|
+
import { StringUtils } from '../utils/StringUtils.js';
|
|
10
|
+
import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
|
|
11
|
+
import { ClientAuthError, ClientAuthErrorMessage } from '../error/ClientAuthError.js';
|
|
12
|
+
import { ServerError } from '../error/ServerError.js';
|
|
13
|
+
import { TimeUtils } from '../utils/TimeUtils.js';
|
|
14
|
+
import { UrlString } from '../url/UrlString.js';
|
|
15
|
+
import { CcsCredentialType } from '../account/CcsCredential.js';
|
|
16
|
+
import { buildClientInfoFromHomeAccountId } from '../account/ClientInfo.js';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
20
|
+
* Licensed under the MIT License.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* OAuth2.0 refresh token client
|
|
24
|
+
*/
|
|
25
|
+
var RefreshTokenClient = /** @class */ (function (_super) {
|
|
26
|
+
__extends(RefreshTokenClient, _super);
|
|
27
|
+
function RefreshTokenClient(configuration) {
|
|
28
|
+
return _super.call(this, configuration) || this;
|
|
29
|
+
}
|
|
30
|
+
RefreshTokenClient.prototype.acquireToken = function (request) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
32
|
+
var reqTimestamp, response, responseHandler;
|
|
33
|
+
return __generator(this, function (_a) {
|
|
34
|
+
switch (_a.label) {
|
|
35
|
+
case 0:
|
|
36
|
+
reqTimestamp = TimeUtils.nowSeconds();
|
|
37
|
+
return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
|
|
38
|
+
case 1:
|
|
39
|
+
response = _a.sent();
|
|
40
|
+
responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
41
|
+
responseHandler.validateTokenResponse(response.body);
|
|
42
|
+
return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true)];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Gets cached refresh token and attaches to request, then calls acquireToken API
|
|
49
|
+
* @param request
|
|
50
|
+
*/
|
|
51
|
+
RefreshTokenClient.prototype.acquireTokenByRefreshToken = function (request) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var isFOCI, noFamilyRTInCache, clientMismatchErrorWithFamilyRT;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
// Cannot renew token if no request object is given.
|
|
56
|
+
if (!request) {
|
|
57
|
+
throw ClientConfigurationError.createEmptyTokenRequestError();
|
|
58
|
+
}
|
|
59
|
+
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
60
|
+
if (!request.account) {
|
|
61
|
+
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
62
|
+
}
|
|
63
|
+
isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment, this.config.authOptions.clientId);
|
|
64
|
+
// if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
|
|
65
|
+
if (isFOCI) {
|
|
66
|
+
try {
|
|
67
|
+
return [2 /*return*/, this.acquireTokenWithCachedRefreshToken(request, true)];
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
noFamilyRTInCache = e instanceof ClientAuthError && e.errorCode === ClientAuthErrorMessage.noTokensFoundError.code;
|
|
71
|
+
clientMismatchErrorWithFamilyRT = e instanceof ServerError && e.errorCode === Errors.INVALID_GRANT_ERROR && e.subError === Errors.CLIENT_MISMATCH_ERROR;
|
|
72
|
+
// if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)
|
|
73
|
+
if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {
|
|
74
|
+
return [2 /*return*/, this.acquireTokenWithCachedRefreshToken(request, false)];
|
|
75
|
+
// throw in all other cases
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// fall back to application refresh token acquisition
|
|
83
|
+
return [2 /*return*/, this.acquireTokenWithCachedRefreshToken(request, false)];
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* makes a network call to acquire tokens by exchanging RefreshToken available in userCache; throws if refresh token is not cached
|
|
89
|
+
* @param request
|
|
90
|
+
*/
|
|
91
|
+
RefreshTokenClient.prototype.acquireTokenWithCachedRefreshToken = function (request, foci) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var refreshToken, refreshTokenRequest;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
refreshToken = this.cacheManager.readRefreshTokenFromCache(this.config.authOptions.clientId, request.account, foci);
|
|
96
|
+
// no refresh Token
|
|
97
|
+
if (!refreshToken) {
|
|
98
|
+
throw ClientAuthError.createNoTokensFoundError();
|
|
99
|
+
}
|
|
100
|
+
refreshTokenRequest = __assign(__assign({}, request), { refreshToken: refreshToken.secret, authenticationScheme: request.authenticationScheme || AuthenticationScheme.BEARER, ccsCredential: {
|
|
101
|
+
credential: request.account.homeAccountId,
|
|
102
|
+
type: CcsCredentialType.HOME_ACCOUNT_ID
|
|
103
|
+
} });
|
|
104
|
+
return [2 /*return*/, this.acquireToken(refreshTokenRequest)];
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Constructs the network message and makes a NW call to the underlying secure token service
|
|
110
|
+
* @param request
|
|
111
|
+
* @param authority
|
|
112
|
+
*/
|
|
113
|
+
RefreshTokenClient.prototype.executeTokenRequest = function (request, authority) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var requestBody, queryParameters, headers, thumbprint, endpoint;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0: return [4 /*yield*/, this.createTokenRequestBody(request)];
|
|
119
|
+
case 1:
|
|
120
|
+
requestBody = _a.sent();
|
|
121
|
+
queryParameters = this.createTokenQueryParameters(request);
|
|
122
|
+
headers = this.createTokenRequestHeaders(request.ccsCredential);
|
|
123
|
+
thumbprint = {
|
|
124
|
+
clientId: this.config.authOptions.clientId,
|
|
125
|
+
authority: authority.canonicalAuthority,
|
|
126
|
+
scopes: request.scopes
|
|
127
|
+
};
|
|
128
|
+
endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
|
|
129
|
+
return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Creates query string for the /token request
|
|
136
|
+
* @param request
|
|
137
|
+
*/
|
|
138
|
+
RefreshTokenClient.prototype.createTokenQueryParameters = function (request) {
|
|
139
|
+
var parameterBuilder = new RequestParameterBuilder();
|
|
140
|
+
if (request.tokenQueryParameters) {
|
|
141
|
+
parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);
|
|
142
|
+
}
|
|
143
|
+
return parameterBuilder.createQueryString();
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Helper function to create the token request body
|
|
147
|
+
* @param request
|
|
148
|
+
*/
|
|
149
|
+
RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, _a, _b, clientInfo;
|
|
152
|
+
return __generator(this, function (_c) {
|
|
153
|
+
switch (_c.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
parameterBuilder = new RequestParameterBuilder();
|
|
156
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
157
|
+
parameterBuilder.addScopes(request.scopes);
|
|
158
|
+
parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
|
|
159
|
+
parameterBuilder.addClientInfo();
|
|
160
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
161
|
+
parameterBuilder.addThrottling();
|
|
162
|
+
if (this.serverTelemetryManager) {
|
|
163
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
164
|
+
}
|
|
165
|
+
correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
|
|
166
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
167
|
+
parameterBuilder.addRefreshToken(request.refreshToken);
|
|
168
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
169
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
170
|
+
}
|
|
171
|
+
if (this.config.clientCredentials.clientAssertion) {
|
|
172
|
+
clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
173
|
+
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
174
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
175
|
+
}
|
|
176
|
+
if (!(request.authenticationScheme === AuthenticationScheme.POP)) return [3 /*break*/, 2];
|
|
177
|
+
popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
|
|
178
|
+
_b = (_a = parameterBuilder).addPopToken;
|
|
179
|
+
return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
|
|
180
|
+
case 1:
|
|
181
|
+
_b.apply(_a, [_c.sent()]);
|
|
182
|
+
_c.label = 2;
|
|
183
|
+
case 2:
|
|
184
|
+
if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
|
|
185
|
+
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
186
|
+
}
|
|
187
|
+
if (this.config.systemOptions.preventCorsPreflight && request.ccsCredential) {
|
|
188
|
+
switch (request.ccsCredential.type) {
|
|
189
|
+
case CcsCredentialType.HOME_ACCOUNT_ID:
|
|
190
|
+
try {
|
|
191
|
+
clientInfo = buildClientInfoFromHomeAccountId(request.ccsCredential.credential);
|
|
192
|
+
parameterBuilder.addCcsOid(clientInfo);
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case CcsCredentialType.UPN:
|
|
199
|
+
parameterBuilder.addCcsUpn(request.ccsCredential.credential);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return [2 /*return*/, parameterBuilder.createQueryString()];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
return RefreshTokenClient;
|
|
209
|
+
}(BaseClient));
|
|
210
|
+
|
|
211
|
+
export { RefreshTokenClient };
|
|
212
|
+
//# sourceMappingURL=RefreshTokenClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefreshTokenClient.js","sources":["../../src/client/RefreshTokenClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { CommonRefreshTokenRequest } from \"../request/CommonRefreshTokenRequest\";\nimport { Authority } from \"../authority/Authority\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { GrantType, AuthenticationScheme, Errors } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { NetworkResponse } from \"../network/NetworkManager\";\nimport { CommonSilentFlowRequest } from \"../request/CommonSilentFlowRequest\";\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\nimport { ClientAuthError, ClientAuthErrorMessage } from \"../error/ClientAuthError\";\nimport { ServerError } from \"../error/ServerError\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { UrlString } from \"../url/UrlString\";\nimport { CcsCredentialType } from \"../account/CcsCredential\";\nimport { buildClientInfoFromHomeAccountId } from \"../account/ClientInfo\";\n\n/**\n * OAuth2.0 refresh token client\n */\nexport class RefreshTokenClient extends BaseClient {\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n public async acquireToken(request: CommonRefreshTokenRequest): Promise<AuthenticationResult>{\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executeTokenRequest(request, this.authority);\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(response.body);\n return responseHandler.handleServerTokenResponse(\n response.body,\n this.authority,\n reqTimestamp,\n request,\n undefined,\n undefined,\n true\n );\n }\n\n /**\n * Gets cached refresh token and attaches to request, then calls acquireToken API\n * @param request\n */\n public async acquireTokenByRefreshToken(request: CommonSilentFlowRequest): Promise<AuthenticationResult> {\n // Cannot renew token if no request object is given.\n if (!request) {\n throw ClientConfigurationError.createEmptyTokenRequestError();\n }\n\n // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases\n if (!request.account) {\n throw ClientAuthError.createNoAccountInSilentRequestError();\n }\n\n // try checking if FOCI is enabled for the given application\n const isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment, this.config.authOptions.clientId);\n\n // if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest\n if (isFOCI) {\n try {\n return this.acquireTokenWithCachedRefreshToken(request, true);\n } catch (e) {\n const noFamilyRTInCache = e instanceof ClientAuthError && e.errorCode === ClientAuthErrorMessage.noTokensFoundError.code;\n const clientMismatchErrorWithFamilyRT = e instanceof ServerError && e.errorCode === Errors.INVALID_GRANT_ERROR && e.subError === Errors.CLIENT_MISMATCH_ERROR;\n\n // if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)\n if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {\n return this.acquireTokenWithCachedRefreshToken(request, false);\n // throw in all other cases\n } else {\n throw e;\n }\n }\n }\n\n // fall back to application refresh token acquisition\n return this.acquireTokenWithCachedRefreshToken(request, false);\n }\n\n /**\n * makes a network call to acquire tokens by exchanging RefreshToken available in userCache; throws if refresh token is not cached\n * @param request\n */\n private async acquireTokenWithCachedRefreshToken(request: CommonSilentFlowRequest, foci: boolean) {\n // fetches family RT or application RT based on FOCI value\n const refreshToken = this.cacheManager.readRefreshTokenFromCache(this.config.authOptions.clientId, request.account, foci);\n\n // no refresh Token\n if (!refreshToken) {\n throw ClientAuthError.createNoTokensFoundError();\n }\n\n const refreshTokenRequest: CommonRefreshTokenRequest = {\n ...request,\n refreshToken: refreshToken.secret,\n authenticationScheme: request.authenticationScheme || AuthenticationScheme.BEARER,\n ccsCredential: {\n credential: request.account.homeAccountId,\n type: CcsCredentialType.HOME_ACCOUNT_ID\n }\n };\n\n return this.acquireToken(refreshTokenRequest);\n }\n\n /**\n * Constructs the network message and makes a NW call to the underlying secure token service\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonRefreshTokenRequest, authority: Authority)\n : Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {\n\n const requestBody = await this.createTokenRequestBody(request);\n const queryParameters = this.createTokenQueryParameters(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders(request.ccsCredential);\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: authority.canonicalAuthority,\n scopes: request.scopes\n };\n\n const endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);\n return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);\n }\n\n /**\n * Creates query string for the /token request\n * @param request \n */\n private createTokenQueryParameters(request: CommonRefreshTokenRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n if (request.tokenQueryParameters) {\n parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * Helper function to create the token request body\n * @param request\n */\n private async createTokenRequestBody(request: CommonRefreshTokenRequest): Promise<string> {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes);\n\n parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);\n\n parameterBuilder.addClientInfo();\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n\n parameterBuilder.addThrottling();\n \n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n parameterBuilder.addRefreshToken(request.refreshToken);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n if (this.config.clientCredentials.clientAssertion) {\n const clientAssertion = this.config.clientCredentials.clientAssertion;\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n if (request.authenticationScheme === AuthenticationScheme.POP) {\n const popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);\n\n parameterBuilder.addPopToken(await popTokenGenerator.generateCnf(request));\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n if (this.config.systemOptions.preventCorsPreflight && request.ccsCredential) {\n switch (request.ccsCredential.type) {\n case CcsCredentialType.HOME_ACCOUNT_ID:\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(request.ccsCredential.credential);\n parameterBuilder.addCcsOid(clientInfo);\n } catch (e) {\n this.logger.verbose(\"Could not parse home account ID for CCS Header: \" + e);\n }\n break;\n case CcsCredentialType.UPN:\n parameterBuilder.addCcsUpn(request.ccsCredential.credential);\n break;\n }\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;AA2BA;;;;IAGwC,sCAAU;IAE9C,4BAAY,aAAkC;eAC1C,kBAAM,aAAa,CAAC;KACvB;IAEY,yCAAY,GAAzB,UAA0B,OAAkC;;;;;;wBAClD,YAAY,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;wBAC3B,qBAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAA;;wBAAlE,QAAQ,GAAG,SAAuD;wBAElE,eAAe,GAAG,IAAI,eAAe,CACvC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAChC,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,CAAC,i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gCAAgC,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;wCACtF,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;qCAC1C;oCAAC,OAAO,CAAC,EAAE;wCACR,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,kDAAkD,GAAG,CAAC,CAAC,CAAC;qCAC/E;oCACD,MAAM;gCACV,KAAK,iBAAiB,CAAC,GAAG;oCACtB,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;oCAC7D,MAAM;6BACb;yBACJ;wBAED,sBAAO,gBAAgB,CAAC,iBAAiB,EAAE,EAAC;;;;KAC/C;IACL,yBAAC;AAAD,CAtMA,CAAwC,UAAU;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SilentFlowClient.d.ts","sourceRoot":"","sources":["../../src/client/SilentFlowClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"SilentFlowClient.d.ts","sourceRoot":"","sources":["../../src/client/SilentFlowClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAYxE,qBAAa,gBAAiB,SAAQ,UAAU;gBAEhC,aAAa,EAAE,mBAAmB;IAI9C;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAanF;;;OAGG;IACG,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA8CzF;;;OAGG;YACW,6BAA6B;CAc9C"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*! @azure/msal-common v4.5.1 2021-08-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
|
|
4
|
+
import { BaseClient } from './BaseClient.js';
|
|
5
|
+
import { ScopeSet } from '../request/ScopeSet.js';
|
|
6
|
+
import { AuthToken } from '../account/AuthToken.js';
|
|
7
|
+
import { TimeUtils } from '../utils/TimeUtils.js';
|
|
8
|
+
import { RefreshTokenClient } from './RefreshTokenClient.js';
|
|
9
|
+
import { ClientAuthError, ClientAuthErrorMessage } from '../error/ClientAuthError.js';
|
|
10
|
+
import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
|
|
11
|
+
import { ResponseHandler } from '../response/ResponseHandler.js';
|
|
12
|
+
import { CacheOutcome, AuthenticationScheme } from '../utils/Constants.js';
|
|
13
|
+
import { StringUtils } from '../utils/StringUtils.js';
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
17
|
+
* Licensed under the MIT License.
|
|
18
|
+
*/
|
|
19
|
+
var SilentFlowClient = /** @class */ (function (_super) {
|
|
20
|
+
__extends(SilentFlowClient, _super);
|
|
21
|
+
function SilentFlowClient(configuration) {
|
|
22
|
+
return _super.call(this, configuration) || this;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
|
|
26
|
+
* the given token and returns the renewed token
|
|
27
|
+
* @param request
|
|
28
|
+
*/
|
|
29
|
+
SilentFlowClient.prototype.acquireToken = function (request) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
31
|
+
var e_1, refreshTokenClient;
|
|
32
|
+
return __generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
|
+
case 0:
|
|
35
|
+
_a.trys.push([0, 2, , 3]);
|
|
36
|
+
return [4 /*yield*/, this.acquireCachedToken(request)];
|
|
37
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
38
|
+
case 2:
|
|
39
|
+
e_1 = _a.sent();
|
|
40
|
+
if (e_1 instanceof ClientAuthError && e_1.errorCode === ClientAuthErrorMessage.tokenRefreshRequired.code) {
|
|
41
|
+
refreshTokenClient = new RefreshTokenClient(this.config);
|
|
42
|
+
return [2 /*return*/, refreshTokenClient.acquireTokenByRefreshToken(request)];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw e_1;
|
|
46
|
+
}
|
|
47
|
+
case 3: return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves token from cache or throws an error if it must be refreshed.
|
|
54
|
+
* @param request
|
|
55
|
+
*/
|
|
56
|
+
SilentFlowClient.prototype.acquireCachedToken = function (request) {
|
|
57
|
+
var _a, _b, _c, _d;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var requestScopes, environment, authScheme, cacheRecord;
|
|
60
|
+
return __generator(this, function (_e) {
|
|
61
|
+
switch (_e.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
// Cannot renew token if no request object is given.
|
|
64
|
+
if (!request) {
|
|
65
|
+
throw ClientConfigurationError.createEmptyTokenRequestError();
|
|
66
|
+
}
|
|
67
|
+
// We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
|
|
68
|
+
if (!request.account) {
|
|
69
|
+
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
70
|
+
}
|
|
71
|
+
requestScopes = new ScopeSet(request.scopes || []);
|
|
72
|
+
environment = request.authority || this.authority.getPreferredCache();
|
|
73
|
+
authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
|
|
74
|
+
cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme);
|
|
75
|
+
if (request.forceRefresh) {
|
|
76
|
+
// Must refresh due to present force_refresh flag.
|
|
77
|
+
(_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
|
|
78
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
79
|
+
}
|
|
80
|
+
else if (!cacheRecord.accessToken) {
|
|
81
|
+
// Must refresh due to non-existent access_token.
|
|
82
|
+
(_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
83
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
84
|
+
}
|
|
85
|
+
else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
|
|
86
|
+
TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
|
|
87
|
+
// Must refresh due to expired access_token.
|
|
88
|
+
(_c = this.serverTelemetryManager) === null || _c === void 0 ? void 0 : _c.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
|
|
89
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
90
|
+
}
|
|
91
|
+
else if (cacheRecord.accessToken.refreshOn && TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
|
|
92
|
+
// Must refresh due to the refresh_in value.
|
|
93
|
+
(_d = this.serverTelemetryManager) === null || _d === void 0 ? void 0 : _d.setCacheOutcome(CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
|
|
94
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
95
|
+
}
|
|
96
|
+
else if (!StringUtils.isEmptyObj(request.claims)) {
|
|
97
|
+
// Must refresh due to request parameters.
|
|
98
|
+
throw ClientAuthError.createRefreshRequiredError();
|
|
99
|
+
}
|
|
100
|
+
if (this.config.serverTelemetryManager) {
|
|
101
|
+
this.config.serverTelemetryManager.incrementCacheHits();
|
|
102
|
+
}
|
|
103
|
+
return [4 /*yield*/, this.generateResultFromCacheRecord(cacheRecord, request)];
|
|
104
|
+
case 1: return [2 /*return*/, _e.sent()];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Helper function to build response object from the CacheRecord
|
|
111
|
+
* @param cacheRecord
|
|
112
|
+
*/
|
|
113
|
+
SilentFlowClient.prototype.generateResultFromCacheRecord = function (cacheRecord, request) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var idTokenObj;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
if (cacheRecord.idToken) {
|
|
120
|
+
idTokenObj = new AuthToken(cacheRecord.idToken.secret, this.config.cryptoInterface);
|
|
121
|
+
}
|
|
122
|
+
return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, cacheRecord, true, request, idTokenObj)];
|
|
123
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return SilentFlowClient;
|
|
129
|
+
}(BaseClient));
|
|
130
|
+
|
|
131
|
+
export { SilentFlowClient };
|
|
132
|
+
//# sourceMappingURL=SilentFlowClient.js.map
|