@azure/msal-common 14.5.0 → 14.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/AccountInfo.d.ts +58 -58
- package/dist/account/AccountInfo.mjs +59 -59
- package/dist/account/AuthToken.d.ts +17 -17
- package/dist/account/AuthToken.mjs +58 -58
- package/dist/account/CcsCredential.d.ts +9 -9
- package/dist/account/CcsCredential.mjs +8 -8
- package/dist/account/ClientCredentials.d.ts +14 -14
- package/dist/account/ClientInfo.d.ts +18 -18
- package/dist/account/ClientInfo.mjs +37 -37
- package/dist/account/TokenClaims.d.ts +83 -83
- package/dist/account/TokenClaims.mjs +20 -20
- package/dist/authority/Authority.d.ts +254 -253
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +815 -811
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts +31 -31
- package/dist/authority/AuthorityFactory.mjs +47 -47
- package/dist/authority/AuthorityMetadata.d.ts +503 -503
- package/dist/authority/AuthorityMetadata.mjs +603 -603
- package/dist/authority/AuthorityOptions.d.ts +27 -27
- package/dist/authority/AuthorityOptions.mjs +18 -18
- package/dist/authority/AuthorityType.d.ts +10 -10
- package/dist/authority/AuthorityType.mjs +13 -13
- package/dist/authority/AzureRegion.d.ts +1 -1
- package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
- package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
- package/dist/authority/ImdsOptions.d.ts +5 -5
- package/dist/authority/OIDCOptions.d.ts +8 -8
- package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
- package/dist/authority/OpenIdConfigResponse.mjs +10 -10
- package/dist/authority/ProtocolMode.d.ts +8 -8
- package/dist/authority/ProtocolMode.mjs +11 -11
- package/dist/authority/RegionDiscovery.d.ts +32 -32
- package/dist/authority/RegionDiscovery.mjs +106 -106
- package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
- package/dist/cache/CacheManager.d.ts +508 -517
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +1237 -1263
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +25 -25
- package/dist/cache/entities/AccountEntity.d.ts +106 -106
- package/dist/cache/entities/AccountEntity.mjs +244 -244
- package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
- package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
- package/dist/cache/entities/CacheRecord.d.ts +14 -14
- package/dist/cache/entities/CacheRecord.mjs +14 -14
- package/dist/cache/entities/CredentialEntity.d.ts +30 -30
- package/dist/cache/entities/IdTokenEntity.d.ts +8 -8
- package/dist/cache/entities/RefreshTokenEntity.d.ts +7 -5
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.d.ts +5 -5
- package/dist/cache/entities/ThrottlingEntity.d.ts +7 -13
- package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -1
- package/dist/cache/interface/ICacheManager.d.ts +166 -166
- package/dist/cache/interface/ICachePlugin.d.ts +5 -5
- package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
- package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
- package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
- package/dist/cache/utils/CacheHelpers.d.ts +70 -64
- package/dist/cache/utils/CacheHelpers.d.ts.map +1 -1
- package/dist/cache/utils/CacheHelpers.mjs +252 -233
- package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +69 -69
- package/dist/client/AuthorizationCodeClient.d.ts +74 -74
- package/dist/client/AuthorizationCodeClient.mjs +402 -402
- package/dist/client/BaseClient.d.ts +51 -51
- package/dist/client/BaseClient.mjs +100 -100
- package/dist/client/RefreshTokenClient.d.ts +35 -35
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +206 -187
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +27 -27
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +129 -118
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/AppTokenProvider.d.ts +38 -38
- package/dist/config/ClientConfiguration.d.ts +150 -150
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +96 -98
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/constants/AADServerParamKeys.d.ts +52 -51
- package/dist/constants/AADServerParamKeys.d.ts.map +1 -1
- package/dist/constants/AADServerParamKeys.mjs +57 -56
- package/dist/constants/AADServerParamKeys.mjs.map +1 -1
- package/dist/crypto/ICrypto.d.ts +58 -58
- package/dist/crypto/ICrypto.mjs +30 -30
- package/dist/crypto/IGuidGenerator.d.ts +4 -4
- package/dist/crypto/JoseHeader.d.ts +22 -22
- package/dist/crypto/JoseHeader.mjs +37 -37
- package/dist/crypto/PopTokenGenerator.d.ts +60 -60
- package/dist/crypto/PopTokenGenerator.mjs +82 -82
- package/dist/crypto/SignedHttpRequest.d.ts +15 -15
- package/dist/error/AuthError.d.ts +44 -44
- package/dist/error/AuthError.mjs +46 -46
- package/dist/error/AuthErrorCodes.d.ts +5 -5
- package/dist/error/AuthErrorCodes.mjs +9 -9
- package/dist/error/ClientAuthError.d.ts +237 -237
- package/dist/error/ClientAuthError.mjs +249 -249
- package/dist/error/ClientAuthErrorCodes.d.ts +44 -44
- package/dist/error/ClientAuthErrorCodes.mjs +48 -48
- package/dist/error/ClientConfigurationError.d.ts +128 -128
- package/dist/error/ClientConfigurationError.mjs +135 -135
- package/dist/error/ClientConfigurationErrorCodes.d.ts +22 -22
- package/dist/error/ClientConfigurationErrorCodes.mjs +26 -26
- package/dist/error/InteractionRequiredAuthError.d.ts +61 -57
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +85 -77
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +7 -5
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +15 -13
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -1
- package/dist/error/JoseHeaderError.d.ts +15 -15
- package/dist/error/JoseHeaderError.mjs +22 -22
- package/dist/error/JoseHeaderErrorCodes.d.ts +2 -2
- package/dist/error/JoseHeaderErrorCodes.mjs +6 -6
- package/dist/error/ServerError.d.ts +7 -7
- package/dist/error/ServerError.mjs +14 -14
- package/dist/index.cjs +8628 -8597
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +99 -99
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts +95 -95
- package/dist/logger/Logger.mjs +188 -188
- package/dist/network/INetworkModule.d.ts +29 -29
- package/dist/network/INetworkModule.mjs +12 -12
- package/dist/network/NetworkManager.d.ts +33 -33
- package/dist/network/NetworkManager.mjs +34 -34
- package/dist/network/RequestThumbprint.d.ts +18 -18
- package/dist/network/ThrottlingUtils.d.ts +42 -42
- package/dist/network/ThrottlingUtils.mjs +95 -95
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +4 -4
- package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
- package/dist/request/AuthenticationHeaderParser.mjs +55 -55
- package/dist/request/BaseAuthRequest.d.ts +43 -43
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
- package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
- package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
- package/dist/request/CommonEndSessionRequest.d.ts +21 -21
- package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
- package/dist/request/CommonRefreshTokenRequest.d.ts +22 -22
- package/dist/request/CommonSilentFlowRequest.d.ts +27 -20
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
- package/dist/request/NativeRequest.d.ts +19 -19
- package/dist/request/NativeSignOutRequest.d.ts +5 -5
- package/dist/request/RequestParameterBuilder.d.ts +217 -217
- package/dist/request/RequestParameterBuilder.mjs +381 -381
- package/dist/request/RequestValidator.d.ts +33 -33
- package/dist/request/RequestValidator.mjs +81 -81
- package/dist/request/ScopeSet.d.ts +88 -88
- package/dist/request/ScopeSet.mjs +197 -197
- package/dist/request/StoreInCache.d.ts +8 -8
- package/dist/response/AuthenticationResult.d.ts +41 -41
- package/dist/response/AuthorizationCodePayload.d.ts +13 -13
- package/dist/response/DeviceCodeResponse.d.ts +25 -25
- package/dist/response/ExternalTokenResponse.d.ts +15 -15
- package/dist/response/IMDSBadResponse.d.ts +4 -4
- package/dist/response/ResponseHandler.d.ts +69 -69
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +346 -336
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +47 -46
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +57 -51
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
- package/dist/telemetry/performance/PerformanceClient.d.ts +198 -191
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +413 -409
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +464 -464
- package/dist/telemetry/performance/PerformanceEvent.mjs +253 -253
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
- package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +76 -76
- package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
- package/dist/telemetry/server/ServerTelemetryManager.mjs +201 -201
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
- package/dist/url/IUri.d.ts +12 -12
- package/dist/url/UrlString.d.ts +48 -48
- package/dist/url/UrlString.mjs +161 -161
- package/dist/utils/Constants.d.ts +298 -296
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +313 -310
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts +27 -27
- package/dist/utils/FunctionWrappers.mjs +84 -84
- package/dist/utils/MsalTypes.d.ts +6 -6
- package/dist/utils/ProtocolUtils.d.ts +42 -42
- package/dist/utils/ProtocolUtils.mjs +69 -69
- package/dist/utils/StringUtils.d.ts +40 -40
- package/dist/utils/StringUtils.mjs +95 -95
- package/dist/utils/TimeUtils.d.ts +27 -27
- package/dist/utils/TimeUtils.mjs +45 -45
- package/dist/utils/UrlUtils.d.ts +10 -10
- package/dist/utils/UrlUtils.mjs +44 -44
- package/package.json +1 -1
- package/src/authority/Authority.ts +9 -3
- package/src/cache/CacheManager.ts +0 -54
- package/src/cache/entities/RefreshTokenEntity.ts +3 -1
- package/src/cache/entities/ThrottlingEntity.ts +2 -24
- package/src/cache/utils/CacheHelpers.ts +26 -1
- package/src/client/RefreshTokenClient.ts +40 -7
- package/src/client/SilentFlowClient.ts +30 -10
- package/src/config/ClientConfiguration.ts +4 -4
- package/src/constants/AADServerParamKeys.ts +1 -0
- package/src/error/InteractionRequiredAuthError.ts +12 -0
- package/src/error/InteractionRequiredAuthErrorCodes.ts +2 -0
- package/src/index.ts +1 -0
- package/src/packageMetadata.ts +1 -1
- package/src/request/CommonSilentFlowRequest.ts +7 -0
- package/src/response/ResponseHandler.ts +21 -5
- package/src/response/ServerAuthorizationTokenResponse.ts +1 -0
- package/src/telemetry/performance/IPerformanceClient.ts +6 -0
- package/src/telemetry/performance/PerformanceClient.ts +24 -31
- package/src/telemetry/performance/StubPerformanceClient.ts +0 -1
- package/src/utils/Constants.ts +4 -0
- package/dist/cache/entities/ThrottlingEntity.mjs +0 -30
- package/dist/cache/entities/ThrottlingEntity.mjs.map +0 -1
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
CredentialType,
|
|
15
15
|
SERVER_TELEM_CONSTANTS,
|
|
16
16
|
Separators,
|
|
17
|
+
ThrottlingConstants,
|
|
17
18
|
} from "../../utils/Constants";
|
|
18
19
|
import { TimeUtils } from "../../utils/TimeUtils";
|
|
19
20
|
import { AccessTokenEntity } from "../entities/AccessTokenEntity";
|
|
@@ -168,7 +169,8 @@ export function createRefreshTokenEntity(
|
|
|
168
169
|
refreshToken: string,
|
|
169
170
|
clientId: string,
|
|
170
171
|
familyId?: string,
|
|
171
|
-
userAssertionHash?: string
|
|
172
|
+
userAssertionHash?: string,
|
|
173
|
+
expiresOn?: number
|
|
172
174
|
): RefreshTokenEntity {
|
|
173
175
|
const rtEntity: RefreshTokenEntity = {
|
|
174
176
|
credentialType: CredentialType.REFRESH_TOKEN,
|
|
@@ -186,6 +188,10 @@ export function createRefreshTokenEntity(
|
|
|
186
188
|
rtEntity.familyId = familyId;
|
|
187
189
|
}
|
|
188
190
|
|
|
191
|
+
if (expiresOn) {
|
|
192
|
+
rtEntity.expiresOn = expiresOn.toString();
|
|
193
|
+
}
|
|
194
|
+
|
|
189
195
|
return rtEntity;
|
|
190
196
|
}
|
|
191
197
|
|
|
@@ -325,3 +331,22 @@ export function isServerTelemetryEntity(key: string, entity?: object): boolean {
|
|
|
325
331
|
|
|
326
332
|
return validateKey && validateEntity;
|
|
327
333
|
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* validates if a given cache entry is "Throttling", parses <key,value>
|
|
337
|
+
* @param key
|
|
338
|
+
* @param entity
|
|
339
|
+
*/
|
|
340
|
+
export function isThrottlingEntity(key: string, entity?: object): boolean {
|
|
341
|
+
let validateKey: boolean = false;
|
|
342
|
+
if (key) {
|
|
343
|
+
validateKey = key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
let validateEntity: boolean = true;
|
|
347
|
+
if (entity) {
|
|
348
|
+
validateEntity = entity.hasOwnProperty("throttleTime");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return validateKey && validateEntity;
|
|
352
|
+
}
|
|
@@ -47,6 +47,10 @@ import {
|
|
|
47
47
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
48
48
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
49
49
|
import { invoke, invokeAsync } from "../utils/FunctionWrappers";
|
|
50
|
+
import { generateCredentialKey } from "../cache/utils/CacheHelpers";
|
|
51
|
+
|
|
52
|
+
const DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS = 300; // 5 Minutes
|
|
53
|
+
|
|
50
54
|
/**
|
|
51
55
|
* OAuth2.0 refresh token client
|
|
52
56
|
* @internal
|
|
@@ -215,6 +219,19 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
215
219
|
InteractionRequiredAuthErrorCodes.noTokensFound
|
|
216
220
|
);
|
|
217
221
|
}
|
|
222
|
+
|
|
223
|
+
if (
|
|
224
|
+
refreshToken.expiresOn &&
|
|
225
|
+
TimeUtils.isTokenExpired(
|
|
226
|
+
refreshToken.expiresOn,
|
|
227
|
+
request.refreshTokenExpirationOffsetSeconds ||
|
|
228
|
+
DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS
|
|
229
|
+
)
|
|
230
|
+
) {
|
|
231
|
+
throw createInteractionRequiredAuthError(
|
|
232
|
+
InteractionRequiredAuthErrorCodes.refreshTokenExpired
|
|
233
|
+
);
|
|
234
|
+
}
|
|
218
235
|
// attach cached RT size to the current measurement
|
|
219
236
|
|
|
220
237
|
const refreshTokenRequest: CommonRefreshTokenRequest = {
|
|
@@ -228,13 +245,29 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
228
245
|
},
|
|
229
246
|
};
|
|
230
247
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
try {
|
|
249
|
+
return await invokeAsync(
|
|
250
|
+
this.acquireToken.bind(this),
|
|
251
|
+
PerformanceEvents.RefreshTokenClientAcquireToken,
|
|
252
|
+
this.logger,
|
|
253
|
+
this.performanceClient,
|
|
254
|
+
request.correlationId
|
|
255
|
+
)(refreshTokenRequest);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
if (
|
|
258
|
+
e instanceof InteractionRequiredAuthError &&
|
|
259
|
+
e.subError === InteractionRequiredAuthErrorCodes.badToken
|
|
260
|
+
) {
|
|
261
|
+
// Remove bad refresh token from cache
|
|
262
|
+
this.logger.verbose(
|
|
263
|
+
"acquireTokenWithRefreshToken: bad refresh token, removing from cache"
|
|
264
|
+
);
|
|
265
|
+
const badRefreshTokenKey = generateCredentialKey(refreshToken);
|
|
266
|
+
this.cacheManager.removeRefreshToken(badRefreshTokenKey);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
throw e;
|
|
270
|
+
}
|
|
238
271
|
}
|
|
239
272
|
|
|
240
273
|
/**
|
|
@@ -23,6 +23,7 @@ import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
|
23
23
|
import { TokenClaims } from "../account/TokenClaims";
|
|
24
24
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
25
25
|
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
26
|
+
import { getTenantFromAuthorityString } from "../authority/Authority";
|
|
26
27
|
|
|
27
28
|
/** @internal */
|
|
28
29
|
export class SilentFlowClient extends BaseClient {
|
|
@@ -118,18 +119,20 @@ export class SilentFlowClient extends BaseClient {
|
|
|
118
119
|
);
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
const
|
|
122
|
-
request.
|
|
123
|
-
|
|
124
|
-
const
|
|
122
|
+
const requestTenantId =
|
|
123
|
+
request.account.tenantId ||
|
|
124
|
+
getTenantFromAuthorityString(request.authority);
|
|
125
|
+
const tokenKeys = this.cacheManager.getTokenKeys();
|
|
126
|
+
const cachedAccessToken = this.cacheManager.getAccessToken(
|
|
125
127
|
request.account,
|
|
126
128
|
request,
|
|
127
|
-
|
|
129
|
+
tokenKeys,
|
|
130
|
+
requestTenantId,
|
|
128
131
|
this.performanceClient,
|
|
129
132
|
request.correlationId
|
|
130
133
|
);
|
|
131
134
|
|
|
132
|
-
if (!
|
|
135
|
+
if (!cachedAccessToken) {
|
|
133
136
|
// must refresh due to non-existent access_token
|
|
134
137
|
this.setCacheOutcome(
|
|
135
138
|
CacheOutcome.NO_CACHED_ACCESS_TOKEN,
|
|
@@ -139,9 +142,9 @@ export class SilentFlowClient extends BaseClient {
|
|
|
139
142
|
ClientAuthErrorCodes.tokenRefreshRequired
|
|
140
143
|
);
|
|
141
144
|
} else if (
|
|
142
|
-
TimeUtils.wasClockTurnedBack(
|
|
145
|
+
TimeUtils.wasClockTurnedBack(cachedAccessToken.cachedAt) ||
|
|
143
146
|
TimeUtils.isTokenExpired(
|
|
144
|
-
|
|
147
|
+
cachedAccessToken.expiresOn,
|
|
145
148
|
this.config.systemOptions.tokenRenewalOffsetSeconds
|
|
146
149
|
)
|
|
147
150
|
) {
|
|
@@ -154,8 +157,8 @@ export class SilentFlowClient extends BaseClient {
|
|
|
154
157
|
ClientAuthErrorCodes.tokenRefreshRequired
|
|
155
158
|
);
|
|
156
159
|
} else if (
|
|
157
|
-
|
|
158
|
-
TimeUtils.isTokenExpired(
|
|
160
|
+
cachedAccessToken.refreshOn &&
|
|
161
|
+
TimeUtils.isTokenExpired(cachedAccessToken.refreshOn, 0)
|
|
159
162
|
) {
|
|
160
163
|
// must refresh (in the background) due to the refresh_in value
|
|
161
164
|
lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
|
|
@@ -163,6 +166,23 @@ export class SilentFlowClient extends BaseClient {
|
|
|
163
166
|
// don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
const environment =
|
|
170
|
+
request.authority || this.authority.getPreferredCache();
|
|
171
|
+
const cacheRecord: CacheRecord = {
|
|
172
|
+
account: this.cacheManager.readAccountFromCache(request.account),
|
|
173
|
+
accessToken: cachedAccessToken,
|
|
174
|
+
idToken: this.cacheManager.getIdToken(
|
|
175
|
+
request.account,
|
|
176
|
+
tokenKeys,
|
|
177
|
+
requestTenantId,
|
|
178
|
+
this.performanceClient,
|
|
179
|
+
request.correlationId
|
|
180
|
+
),
|
|
181
|
+
refreshToken: null,
|
|
182
|
+
appMetadata:
|
|
183
|
+
this.cacheManager.readAppMetadataFromCache(environment),
|
|
184
|
+
};
|
|
185
|
+
|
|
166
186
|
this.setCacheOutcome(lastCacheOutcome, request.correlationId);
|
|
167
187
|
|
|
168
188
|
if (this.config.serverTelemetryManager) {
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
import { INetworkModule } from "../network/INetworkModule";
|
|
7
7
|
import { DEFAULT_CRYPTO_IMPLEMENTATION, ICrypto } from "../crypto/ICrypto";
|
|
8
8
|
import { ILoggerCallback, Logger, LogLevel } from "../logger/Logger";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Constants,
|
|
11
|
+
DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
|
|
12
|
+
} from "../utils/Constants";
|
|
10
13
|
import { version } from "../packageMetadata";
|
|
11
14
|
import { Authority } from "../authority/Authority";
|
|
12
15
|
import { AzureCloudInstance } from "../authority/AuthorityOptions";
|
|
@@ -21,9 +24,6 @@ import {
|
|
|
21
24
|
createClientAuthError,
|
|
22
25
|
} from "../error/ClientAuthError";
|
|
23
26
|
|
|
24
|
-
// Token renewal offset default in seconds
|
|
25
|
-
const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
|
|
26
|
-
|
|
27
27
|
/**
|
|
28
28
|
* Use the configuration object to configure MSAL Modules and initialize the base interfaces for MSAL.
|
|
29
29
|
*
|
|
@@ -16,6 +16,7 @@ export const ACCESS_TOKEN = "access_token";
|
|
|
16
16
|
export const ID_TOKEN = "id_token";
|
|
17
17
|
export const REFRESH_TOKEN = "refresh_token";
|
|
18
18
|
export const EXPIRES_IN = "expires_in";
|
|
19
|
+
export const REFRESH_TOKEN_EXPIRES_IN = "refresh_token_expires_in";
|
|
19
20
|
export const STATE = "state";
|
|
20
21
|
export const NONCE = "nonce";
|
|
21
22
|
export const PROMPT = "prompt";
|
|
@@ -15,6 +15,7 @@ export const InteractionRequiredServerErrorMessage = [
|
|
|
15
15
|
InteractionRequiredAuthErrorCodes.interactionRequired,
|
|
16
16
|
InteractionRequiredAuthErrorCodes.consentRequired,
|
|
17
17
|
InteractionRequiredAuthErrorCodes.loginRequired,
|
|
18
|
+
InteractionRequiredAuthErrorCodes.badToken,
|
|
18
19
|
];
|
|
19
20
|
|
|
20
21
|
export const InteractionRequiredAuthSubErrorMessage = [
|
|
@@ -23,6 +24,7 @@ export const InteractionRequiredAuthSubErrorMessage = [
|
|
|
23
24
|
"basic_action",
|
|
24
25
|
"user_password_expired",
|
|
25
26
|
"consent_required",
|
|
27
|
+
"bad_token",
|
|
26
28
|
];
|
|
27
29
|
|
|
28
30
|
const InteractionRequiredAuthErrorMessages = {
|
|
@@ -30,6 +32,10 @@ const InteractionRequiredAuthErrorMessages = {
|
|
|
30
32
|
"No refresh token found in the cache. Please sign-in.",
|
|
31
33
|
[InteractionRequiredAuthErrorCodes.nativeAccountUnavailable]:
|
|
32
34
|
"The requested account is not available in the native broker. It may have been deleted or logged out. Please sign-in again using an interactive API.",
|
|
35
|
+
[InteractionRequiredAuthErrorCodes.refreshTokenExpired]:
|
|
36
|
+
"Refresh token has expired.",
|
|
37
|
+
[InteractionRequiredAuthErrorCodes.badToken]:
|
|
38
|
+
"Identity provider returned bad_token due to an expired or invalid refresh token. Please invoke an interactive API to resolve.",
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
/**
|
|
@@ -49,6 +55,12 @@ export const InteractionRequiredAuthErrorMessage = {
|
|
|
49
55
|
InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
|
|
50
56
|
],
|
|
51
57
|
},
|
|
58
|
+
bad_token: {
|
|
59
|
+
code: InteractionRequiredAuthErrorCodes.badToken,
|
|
60
|
+
desc: InteractionRequiredAuthErrorMessages[
|
|
61
|
+
InteractionRequiredAuthErrorCodes.badToken
|
|
62
|
+
],
|
|
63
|
+
},
|
|
52
64
|
};
|
|
53
65
|
|
|
54
66
|
/**
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
// Codes defined by MSAL
|
|
7
7
|
export const noTokensFound = "no_tokens_found";
|
|
8
8
|
export const nativeAccountUnavailable = "native_account_unavailable";
|
|
9
|
+
export const refreshTokenExpired = "refresh_token_expired";
|
|
9
10
|
|
|
10
11
|
// Codes potentially returned by server
|
|
11
12
|
export const interactionRequired = "interaction_required";
|
|
12
13
|
export const consentRequired = "consent_required";
|
|
13
14
|
export const loginRequired = "login_required";
|
|
15
|
+
export const badToken = "bad_token";
|
package/src/index.ts
CHANGED
package/src/packageMetadata.ts
CHANGED
|
@@ -20,7 +20,14 @@ import { BaseAuthRequest } from "./BaseAuthRequest";
|
|
|
20
20
|
* - tokenQueryParameters - String to string map of custom query parameters added to the /token call
|
|
21
21
|
*/
|
|
22
22
|
export type CommonSilentFlowRequest = BaseAuthRequest & {
|
|
23
|
+
/** Account object to lookup the credentials */
|
|
23
24
|
account: AccountInfo;
|
|
25
|
+
/** Skip cache lookup and forces network call(s) to get fresh tokens */
|
|
24
26
|
forceRefresh: boolean;
|
|
27
|
+
/** RedirectUri registered on the app registration - only required in brokering scenarios */
|
|
28
|
+
redirectUri?: string;
|
|
29
|
+
/** Key value pairs to include on the POST body to the /token endpoint */
|
|
25
30
|
tokenBodyParameters?: StringDict;
|
|
31
|
+
/** If refresh token will expire within the configured value, consider it already expired. Used to pre-emptively invoke interaction when cached refresh token is close to expiry. */
|
|
32
|
+
refreshTokenExpirationOffsetSeconds?: number;
|
|
26
33
|
};
|
|
@@ -435,9 +435,10 @@ export class ResponseHandler {
|
|
|
435
435
|
idTokenClaims,
|
|
436
436
|
this.cryptoObj.base64Decode,
|
|
437
437
|
serverTokenResponse.client_info,
|
|
438
|
+
env,
|
|
438
439
|
claimsTenantId,
|
|
439
440
|
authCodePayload,
|
|
440
|
-
undefined,
|
|
441
|
+
undefined, // nativeAccountId
|
|
441
442
|
this.logger
|
|
442
443
|
);
|
|
443
444
|
}
|
|
@@ -497,13 +498,26 @@ export class ResponseHandler {
|
|
|
497
498
|
// refreshToken
|
|
498
499
|
let cachedRefreshToken: RefreshTokenEntity | null = null;
|
|
499
500
|
if (serverTokenResponse.refresh_token) {
|
|
501
|
+
let rtExpiresOn: number | undefined;
|
|
502
|
+
if (serverTokenResponse.refresh_token_expires_in) {
|
|
503
|
+
const rtExpiresIn: number =
|
|
504
|
+
typeof serverTokenResponse.refresh_token_expires_in ===
|
|
505
|
+
"string"
|
|
506
|
+
? parseInt(
|
|
507
|
+
serverTokenResponse.refresh_token_expires_in,
|
|
508
|
+
10
|
|
509
|
+
)
|
|
510
|
+
: serverTokenResponse.refresh_token_expires_in;
|
|
511
|
+
rtExpiresOn = reqTimestamp + rtExpiresIn;
|
|
512
|
+
}
|
|
500
513
|
cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
|
|
501
514
|
this.homeAccountIdentifier,
|
|
502
515
|
env,
|
|
503
516
|
serverTokenResponse.refresh_token,
|
|
504
517
|
this.clientId,
|
|
505
518
|
serverTokenResponse.foci,
|
|
506
|
-
userAssertionHash
|
|
519
|
+
userAssertionHash,
|
|
520
|
+
rtExpiresOn
|
|
507
521
|
);
|
|
508
522
|
}
|
|
509
523
|
|
|
@@ -654,6 +668,7 @@ export function buildAccountToCache(
|
|
|
654
668
|
idTokenClaims: TokenClaims,
|
|
655
669
|
base64Decode: (input: string) => string,
|
|
656
670
|
clientInfo?: string,
|
|
671
|
+
environment?: string,
|
|
657
672
|
claimsTenantId?: string | null,
|
|
658
673
|
authCodePayload?: AuthorizationCodePayload,
|
|
659
674
|
nativeAccountId?: string,
|
|
@@ -676,9 +691,10 @@ export function buildAccountToCache(
|
|
|
676
691
|
cachedAccount ||
|
|
677
692
|
AccountEntity.createAccount(
|
|
678
693
|
{
|
|
679
|
-
homeAccountId
|
|
680
|
-
idTokenClaims
|
|
681
|
-
clientInfo
|
|
694
|
+
homeAccountId,
|
|
695
|
+
idTokenClaims,
|
|
696
|
+
clientInfo,
|
|
697
|
+
environment,
|
|
682
698
|
cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
|
|
683
699
|
msGraphHost: authCodePayload?.msgraph_host,
|
|
684
700
|
nativeAccountId: nativeAccountId,
|
|
@@ -14,6 +14,9 @@ export type InProgressPerformanceEvent = {
|
|
|
14
14
|
add: (fields: { [key: string]: {} | undefined }) => void;
|
|
15
15
|
increment: (fields: { [key: string]: number | undefined }) => void;
|
|
16
16
|
event: PerformanceEvent;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated This attribute will be removed in the next major version
|
|
19
|
+
*/
|
|
17
20
|
measurement: IPerformanceMeasurement;
|
|
18
21
|
};
|
|
19
22
|
|
|
@@ -35,6 +38,9 @@ export interface IPerformanceClient {
|
|
|
35
38
|
removePerformanceCallback(callbackId: string): boolean;
|
|
36
39
|
addPerformanceCallback(callback: PerformanceCallbackFunction): string;
|
|
37
40
|
emitEvents(events: PerformanceEvent[], correlationId: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated This method will be removed in the next major version
|
|
43
|
+
*/
|
|
38
44
|
startPerformanceMeasurement(
|
|
39
45
|
measureName: string,
|
|
40
46
|
correlationId: string
|
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
PerformanceCallbackFunction,
|
|
12
12
|
QueueMeasurement,
|
|
13
13
|
} from "./IPerformanceClient";
|
|
14
|
-
import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
|
|
15
14
|
import {
|
|
16
15
|
IntFields,
|
|
17
16
|
PerformanceEvent,
|
|
18
17
|
PerformanceEvents,
|
|
19
18
|
PerformanceEventStatus,
|
|
20
19
|
} from "./PerformanceEvent";
|
|
20
|
+
import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
|
|
21
|
+
import { StubPerformanceMeasurement } from "./StubPerformanceClient";
|
|
21
22
|
|
|
22
23
|
export interface PreQueueEvent {
|
|
23
24
|
name: PerformanceEvents;
|
|
@@ -111,6 +112,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
111
112
|
* @param {string} measureName
|
|
112
113
|
* @param {string} correlationId
|
|
113
114
|
* @returns {IPerformanceMeasurement}
|
|
115
|
+
* @deprecated This method will be removed in the next major version
|
|
114
116
|
*/
|
|
115
117
|
startPerformanceMeasurement(
|
|
116
118
|
measureName: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
@@ -273,11 +275,6 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
273
275
|
`PerformanceClient: Performance measurement started for ${measureName}`,
|
|
274
276
|
eventCorrelationId
|
|
275
277
|
);
|
|
276
|
-
const performanceMeasurement = this.startPerformanceMeasurement(
|
|
277
|
-
measureName,
|
|
278
|
-
eventCorrelationId
|
|
279
|
-
);
|
|
280
|
-
performanceMeasurement.startMeasurement();
|
|
281
278
|
|
|
282
279
|
const inProgressEvent: PerformanceEvent = {
|
|
283
280
|
eventId: this.generateId(),
|
|
@@ -301,15 +298,12 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
301
298
|
end: (
|
|
302
299
|
event?: Partial<PerformanceEvent>
|
|
303
300
|
): PerformanceEvent | null => {
|
|
304
|
-
return this.endMeasurement(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
},
|
|
311
|
-
performanceMeasurement
|
|
312
|
-
);
|
|
301
|
+
return this.endMeasurement({
|
|
302
|
+
// Initial set of event properties
|
|
303
|
+
...inProgressEvent,
|
|
304
|
+
// Properties set when event ends
|
|
305
|
+
...event,
|
|
306
|
+
});
|
|
313
307
|
},
|
|
314
308
|
discard: () => {
|
|
315
309
|
return this.discardMeasurements(inProgressEvent.correlationId);
|
|
@@ -323,8 +317,8 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
323
317
|
inProgressEvent.correlationId
|
|
324
318
|
);
|
|
325
319
|
},
|
|
326
|
-
measurement: performanceMeasurement,
|
|
327
320
|
event: inProgressEvent,
|
|
321
|
+
measurement: new StubPerformanceMeasurement(),
|
|
328
322
|
};
|
|
329
323
|
}
|
|
330
324
|
|
|
@@ -338,10 +332,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
338
332
|
* @param {IPerformanceMeasurement} measurement
|
|
339
333
|
* @returns {(PerformanceEvent | null)}
|
|
340
334
|
*/
|
|
341
|
-
endMeasurement(
|
|
342
|
-
event: PerformanceEvent,
|
|
343
|
-
measurement?: IPerformanceMeasurement
|
|
344
|
-
): PerformanceEvent | null {
|
|
335
|
+
endMeasurement(event: PerformanceEvent): PerformanceEvent | null {
|
|
345
336
|
const rootEvent: PerformanceEvent | undefined =
|
|
346
337
|
this.eventsByCorrelationId.get(event.correlationId);
|
|
347
338
|
if (!rootEvent) {
|
|
@@ -365,17 +356,8 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
365
356
|
rootEvent.incompleteSubMeasurements?.delete(event.eventId);
|
|
366
357
|
}
|
|
367
358
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// null indicates no measurement was taken (e.g. needed performance APIs not present)
|
|
371
|
-
if (!durationMs) {
|
|
372
|
-
this.logger.trace(
|
|
373
|
-
"PerformanceClient: Performance measurement not taken",
|
|
374
|
-
rootEvent.correlationId
|
|
375
|
-
);
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
|
|
359
|
+
const durationMs =
|
|
360
|
+
event.durationMs || this.getDurationMs(event.startTimeMs);
|
|
379
361
|
this.logger.trace(
|
|
380
362
|
`PerformanceClient: Performance measurement ended for ${event.name}: ${durationMs} ms`,
|
|
381
363
|
event.correlationId
|
|
@@ -633,4 +615,15 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
633
615
|
}
|
|
634
616
|
});
|
|
635
617
|
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Returns event duration in milliseconds
|
|
621
|
+
* @param startTimeMs {number}
|
|
622
|
+
* @returns {number}
|
|
623
|
+
*/
|
|
624
|
+
private getDurationMs(startTimeMs: number): number {
|
|
625
|
+
const durationMs = Date.now() - startTimeMs;
|
|
626
|
+
// Handle clock skew
|
|
627
|
+
return durationMs < 0 ? durationMs : 0;
|
|
628
|
+
}
|
|
636
629
|
}
|
package/src/utils/Constants.ts
CHANGED
|
@@ -68,6 +68,7 @@ export const HttpStatus = {
|
|
|
68
68
|
SUCCESS_RANGE_END: 299,
|
|
69
69
|
REDIRECT: 302,
|
|
70
70
|
CLIENT_ERROR_RANGE_START: 400,
|
|
71
|
+
UNAUTHORIZED: 401,
|
|
71
72
|
CLIENT_ERROR_RANGE_END: 499,
|
|
72
73
|
SERVER_ERROR_RANGE_START: 500,
|
|
73
74
|
SERVER_ERROR_RANGE_END: 599,
|
|
@@ -370,3 +371,6 @@ export type JsonWebTokenTypes =
|
|
|
370
371
|
(typeof JsonWebTokenTypes)[keyof typeof JsonWebTokenTypes];
|
|
371
372
|
|
|
372
373
|
export const ONE_DAY_IN_MS = 86400000;
|
|
374
|
+
|
|
375
|
+
// Token renewal offset default in seconds
|
|
376
|
+
export const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*! @azure/msal-common v14.5.0 2023-12-01 */
|
|
2
|
-
'use strict';
|
|
3
|
-
import { ThrottlingConstants } from '../../utils/Constants.mjs';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License.
|
|
8
|
-
*/
|
|
9
|
-
class ThrottlingEntity {
|
|
10
|
-
/**
|
|
11
|
-
* validates if a given cache entry is "Throttling", parses <key,value>
|
|
12
|
-
* @param key
|
|
13
|
-
* @param entity
|
|
14
|
-
*/
|
|
15
|
-
static isThrottlingEntity(key, entity) {
|
|
16
|
-
let validateKey = false;
|
|
17
|
-
if (key) {
|
|
18
|
-
validateKey =
|
|
19
|
-
key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
|
|
20
|
-
}
|
|
21
|
-
let validateEntity = true;
|
|
22
|
-
if (entity) {
|
|
23
|
-
validateEntity = entity.hasOwnProperty("throttleTime");
|
|
24
|
-
}
|
|
25
|
-
return validateKey && validateEntity;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { ThrottlingEntity };
|
|
30
|
-
//# sourceMappingURL=ThrottlingEntity.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThrottlingEntity.mjs","sources":["../../../src/cache/entities/ThrottlingEntity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;MAIU,gBAAgB,CAAA;AASzB;;;;AAIG;AACH,IAAA,OAAO,kBAAkB,CAAC,GAAW,EAAE,MAAe,EAAA;QAClD,IAAI,WAAW,GAAY,KAAK,CAAC;AACjC,QAAA,IAAI,GAAG,EAAE;YACL,WAAW;gBACP,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAChE,SAAA;QAED,IAAI,cAAc,GAAY,IAAI,CAAC;AACnC,QAAA,IAAI,MAAM,EAAE;AACR,YAAA,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;AAC1D,SAAA;QAED,OAAO,WAAW,IAAI,cAAc,CAAC;KACxC;AACJ;;;;"}
|