@azure/msal-common 14.1.0 → 14.3.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/AuthToken.mjs +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/ClientInfo.mjs +1 -1
- package/dist/authority/Authority.d.ts +25 -11
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +122 -71
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +3 -3
- package/dist/authority/AuthorityMetadata.d.ts +42 -162
- package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +106 -384
- package/dist/authority/AuthorityMetadata.mjs.map +1 -1
- package/dist/authority/AuthorityOptions.d.ts +6 -0
- package/dist/authority/AuthorityOptions.d.ts.map +1 -1
- package/dist/authority/AuthorityOptions.mjs +1 -1
- package/dist/authority/AuthorityOptions.mjs.map +1 -1
- package/dist/authority/AuthorityType.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/RegionDiscovery.mjs +1 -1
- package/dist/cache/CacheManager.d.ts +17 -1
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +79 -37
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +12 -43
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +1 -3
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
- package/dist/cache/entities/CacheRecord.mjs +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts +15 -73
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/IdTokenEntity.d.ts +4 -30
- package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.d.ts +2 -33
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/utils/CacheHelpers.d.ts +59 -0
- package/dist/cache/utils/CacheHelpers.d.ts.map +1 -0
- package/dist/cache/utils/CacheHelpers.mjs +226 -0
- package/dist/cache/utils/CacheHelpers.mjs.map +1 -0
- package/dist/cache/utils/CacheTypes.d.ts +1 -0
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +3 -3
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +2 -2
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +11 -10
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +4 -4
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +1 -0
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +20 -27
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.mjs +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/JoseHeader.mjs +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthErrorCodes.mjs +1 -1
- package/dist/error/ClientAuthError.d.ts +5 -0
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.mjs +7 -2
- package/dist/error/ClientAuthError.mjs.map +1 -1
- package/dist/error/ClientAuthErrorCodes.d.ts +1 -0
- package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -1
- package/dist/error/ClientAuthErrorCodes.mjs +3 -2
- package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
- package/dist/error/ServerError.mjs +1 -1
- package/dist/index.cjs +5157 -5476
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +4 -6
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.mjs +1 -1
- package/dist/network/INetworkModule.mjs +1 -1
- package/dist/network/NetworkManager.mjs +1 -1
- package/dist/network/ThrottlingUtils.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/RequestParameterBuilder.mjs +1 -1
- package/dist/request/RequestValidator.mjs +1 -1
- package/dist/request/ScopeSet.mjs +1 -1
- package/dist/response/ResponseHandler.d.ts +2 -2
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +30 -32
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +17 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +9 -2
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
- package/dist/url/UrlString.mjs +1 -1
- package/dist/utils/Constants.mjs +1 -1
- package/dist/utils/FunctionWrappers.mjs +1 -1
- package/dist/utils/ProtocolUtils.mjs +1 -1
- package/dist/utils/StringUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/package.json +1 -1
- package/src/authority/Authority.ts +205 -127
- package/src/authority/AuthorityFactory.ts +4 -4
- package/src/authority/AuthorityMetadata.ts +151 -390
- package/src/authority/AuthorityOptions.ts +9 -0
- package/src/cache/CacheManager.ts +115 -56
- package/src/cache/entities/AccessTokenEntity.ts +13 -149
- package/src/cache/entities/AccountEntity.ts +0 -3
- package/src/cache/entities/CredentialEntity.ts +16 -200
- package/src/cache/entities/IdTokenEntity.ts +4 -64
- package/src/cache/entities/RefreshTokenEntity.ts +2 -69
- package/src/cache/utils/CacheHelpers.ts +306 -0
- package/src/cache/utils/CacheTypes.ts +1 -0
- package/src/client/AuthorizationCodeClient.ts +10 -4
- package/src/client/BaseClient.ts +29 -15
- package/src/client/RefreshTokenClient.ts +17 -7
- package/src/client/SilentFlowClient.ts +49 -49
- package/src/error/ClientAuthError.ts +8 -0
- package/src/error/ClientAuthErrorCodes.ts +1 -0
- package/src/index.ts +7 -1
- package/src/packageMetadata.ts +1 -1
- package/src/response/ResponseHandler.ts +45 -44
- package/src/telemetry/performance/PerformanceEvent.ts +24 -2
- package/dist/cache/entities/AccessTokenEntity.mjs +0 -121
- package/dist/cache/entities/AccessTokenEntity.mjs.map +0 -1
- package/dist/cache/entities/CredentialEntity.mjs +0 -145
- package/dist/cache/entities/CredentialEntity.mjs.map +0 -1
- package/dist/cache/entities/IdTokenEntity.mjs +0 -64
- package/dist/cache/entities/IdTokenEntity.mjs.map +0 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs +0 -67
- package/dist/cache/entities/RefreshTokenEntity.mjs.map +0 -1
|
@@ -194,8 +194,7 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
194
194
|
// Get code response
|
|
195
195
|
responseHandler.validateServerAuthorizationCodeResponse(
|
|
196
196
|
serverParams,
|
|
197
|
-
cachedState
|
|
198
|
-
this.cryptoUtils
|
|
197
|
+
cachedState
|
|
199
198
|
);
|
|
200
199
|
|
|
201
200
|
// throw when there is no auth code in the response
|
|
@@ -297,11 +296,18 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
297
296
|
|
|
298
297
|
return invokeAsync(
|
|
299
298
|
this.executePostToTokenEndpoint.bind(this),
|
|
300
|
-
PerformanceEvents.
|
|
299
|
+
PerformanceEvents.AuthorizationCodeClientExecutePostToTokenEndpoint,
|
|
301
300
|
this.logger,
|
|
302
301
|
this.performanceClient,
|
|
303
302
|
request.correlationId
|
|
304
|
-
)(
|
|
303
|
+
)(
|
|
304
|
+
endpoint,
|
|
305
|
+
requestBody,
|
|
306
|
+
headers,
|
|
307
|
+
thumbprint,
|
|
308
|
+
request.correlationId,
|
|
309
|
+
PerformanceEvents.AuthorizationCodeClientExecutePostToTokenEndpoint
|
|
310
|
+
);
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
/**
|
package/src/client/BaseClient.ts
CHANGED
|
@@ -19,15 +19,12 @@ import { CacheManager } from "../cache/CacheManager";
|
|
|
19
19
|
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager";
|
|
20
20
|
import { RequestThumbprint } from "../network/RequestThumbprint";
|
|
21
21
|
import { version, name } from "../packageMetadata";
|
|
22
|
-
import {
|
|
23
|
-
createClientAuthError,
|
|
24
|
-
ClientAuthErrorCodes,
|
|
25
|
-
} from "../error/ClientAuthError";
|
|
26
22
|
import { CcsCredential, CcsCredentialType } from "../account/CcsCredential";
|
|
27
23
|
import { buildClientInfoFromHomeAccountId } from "../account/ClientInfo";
|
|
28
24
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
29
25
|
import { RequestParameterBuilder } from "../request/RequestParameterBuilder";
|
|
30
26
|
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
27
|
+
import { AuthorityFactory } from "../authority/AuthorityFactory";
|
|
31
28
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
32
29
|
|
|
33
30
|
/**
|
|
@@ -144,12 +141,16 @@ export abstract class BaseClient {
|
|
|
144
141
|
queryString: string,
|
|
145
142
|
headers: Record<string, string>,
|
|
146
143
|
thumbprint: RequestThumbprint,
|
|
147
|
-
correlationId: string
|
|
144
|
+
correlationId: string,
|
|
145
|
+
queuedEvent?: string
|
|
148
146
|
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
if (queuedEvent) {
|
|
148
|
+
this.performanceClient?.addQueueMeasurement(
|
|
149
|
+
queuedEvent,
|
|
150
|
+
correlationId
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
153
154
|
const response =
|
|
154
155
|
await this.networkManager.sendPostRequest<ServerAuthorizationTokenResponse>(
|
|
155
156
|
thumbprint,
|
|
@@ -181,13 +182,26 @@ export abstract class BaseClient {
|
|
|
181
182
|
* Updates the authority object of the client. Endpoint discovery must be completed.
|
|
182
183
|
* @param updatedAuthority
|
|
183
184
|
*/
|
|
184
|
-
updateAuthority(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
async updateAuthority(
|
|
186
|
+
cloudInstanceHostname: string,
|
|
187
|
+
correlationId: string
|
|
188
|
+
): Promise<void> {
|
|
189
|
+
this.performanceClient?.addQueueMeasurement(
|
|
190
|
+
PerformanceEvents.UpdateTokenEndpointAuthority,
|
|
191
|
+
correlationId
|
|
192
|
+
);
|
|
193
|
+
const cloudInstanceAuthorityUri = `https://${cloudInstanceHostname}/${this.authority.tenant}/`;
|
|
194
|
+
const cloudInstanceAuthority =
|
|
195
|
+
await AuthorityFactory.createDiscoveredInstance(
|
|
196
|
+
cloudInstanceAuthorityUri,
|
|
197
|
+
this.networkClient,
|
|
198
|
+
this.cacheManager,
|
|
199
|
+
this.authority.options,
|
|
200
|
+
this.logger,
|
|
201
|
+
this.performanceClient,
|
|
202
|
+
correlationId
|
|
188
203
|
);
|
|
189
|
-
|
|
190
|
-
this.authority = updatedAuthority;
|
|
204
|
+
this.authority = cloudInstanceAuthority;
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
/**
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
} from "../error/InteractionRequiredAuthError";
|
|
47
47
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
48
48
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
49
|
-
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
49
|
+
import { invoke, invokeAsync } from "../utils/FunctionWrappers";
|
|
50
50
|
/**
|
|
51
51
|
* OAuth2.0 refresh token client
|
|
52
52
|
* @internal
|
|
@@ -196,10 +196,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
196
196
|
);
|
|
197
197
|
|
|
198
198
|
// fetches family RT or application RT based on FOCI value
|
|
199
|
-
const refreshToken =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
const refreshToken = invoke(
|
|
200
|
+
this.cacheManager.getRefreshToken.bind(this.cacheManager),
|
|
201
|
+
PerformanceEvents.CacheManagerGetRefreshToken,
|
|
202
|
+
this.logger,
|
|
203
|
+
this.performanceClient,
|
|
204
|
+
request.correlationId
|
|
205
|
+
)(request.account, foci);
|
|
203
206
|
|
|
204
207
|
if (!refreshToken) {
|
|
205
208
|
throw createInteractionRequiredAuthError(
|
|
@@ -274,11 +277,18 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
274
277
|
|
|
275
278
|
return invokeAsync(
|
|
276
279
|
this.executePostToTokenEndpoint.bind(this),
|
|
277
|
-
PerformanceEvents.
|
|
280
|
+
PerformanceEvents.RefreshTokenClientExecutePostToTokenEndpoint,
|
|
278
281
|
this.logger,
|
|
279
282
|
this.performanceClient,
|
|
280
283
|
request.correlationId
|
|
281
|
-
)(
|
|
284
|
+
)(
|
|
285
|
+
endpoint,
|
|
286
|
+
requestBody,
|
|
287
|
+
headers,
|
|
288
|
+
thumbprint,
|
|
289
|
+
request.correlationId,
|
|
290
|
+
PerformanceEvents.RefreshTokenClientExecutePostToTokenEndpoint
|
|
291
|
+
);
|
|
282
292
|
}
|
|
283
293
|
|
|
284
294
|
/**
|
|
@@ -14,10 +14,6 @@ import {
|
|
|
14
14
|
ClientAuthErrorCodes,
|
|
15
15
|
createClientAuthError,
|
|
16
16
|
} from "../error/ClientAuthError";
|
|
17
|
-
import {
|
|
18
|
-
createClientConfigurationError,
|
|
19
|
-
ClientConfigurationErrorCodes,
|
|
20
|
-
} from "../error/ClientConfigurationError";
|
|
21
17
|
import { ResponseHandler } from "../response/ResponseHandler";
|
|
22
18
|
import { CacheRecord } from "../cache/entities/CacheRecord";
|
|
23
19
|
import { CacheOutcome } from "../utils/Constants";
|
|
@@ -25,6 +21,8 @@ import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient"
|
|
|
25
21
|
import { StringUtils } from "../utils/StringUtils";
|
|
26
22
|
import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
27
23
|
import { TokenClaims } from "../account/TokenClaims";
|
|
24
|
+
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
25
|
+
import { invokeAsync } from "../utils/FunctionWrappers";
|
|
28
26
|
|
|
29
27
|
/** @internal */
|
|
30
28
|
export class SilentFlowClient extends BaseClient {
|
|
@@ -92,35 +90,21 @@ export class SilentFlowClient extends BaseClient {
|
|
|
92
90
|
async acquireCachedToken(
|
|
93
91
|
request: CommonSilentFlowRequest
|
|
94
92
|
): Promise<[AuthenticationResult, CacheOutcome]> {
|
|
93
|
+
this.performanceClient?.addQueueMeasurement(
|
|
94
|
+
PerformanceEvents.SilentFlowClientAcquireCachedToken,
|
|
95
|
+
request.correlationId
|
|
96
|
+
);
|
|
95
97
|
let lastCacheOutcome: CacheOutcome = CacheOutcome.NOT_APPLICABLE;
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (request.forceRefresh) {
|
|
105
|
-
// Must refresh due to present force_refresh flag.
|
|
106
|
-
lastCacheOutcome = CacheOutcome.FORCE_REFRESH_OR_CLAIMS;
|
|
107
|
-
this.serverTelemetryManager?.setCacheOutcome(
|
|
108
|
-
CacheOutcome.FORCE_REFRESH_OR_CLAIMS
|
|
109
|
-
);
|
|
110
|
-
this.logger.info(
|
|
111
|
-
"SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true."
|
|
112
|
-
);
|
|
113
|
-
throw createClientAuthError(
|
|
114
|
-
ClientAuthErrorCodes.tokenRefreshRequired
|
|
115
|
-
);
|
|
116
|
-
} else if (
|
|
117
|
-
!this.config.cacheOptions.claimsBasedCachingEnabled &&
|
|
118
|
-
!StringUtils.isEmptyObj(request.claims)
|
|
99
|
+
if (
|
|
100
|
+
request.forceRefresh ||
|
|
101
|
+
(!this.config.cacheOptions.claimsBasedCachingEnabled &&
|
|
102
|
+
!StringUtils.isEmptyObj(request.claims))
|
|
119
103
|
) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
104
|
+
// Must refresh due to present force_refresh flag.
|
|
105
|
+
this.setCacheOutcome(
|
|
106
|
+
CacheOutcome.FORCE_REFRESH_OR_CLAIMS,
|
|
107
|
+
request.correlationId
|
|
124
108
|
);
|
|
125
109
|
throw createClientAuthError(
|
|
126
110
|
ClientAuthErrorCodes.tokenRefreshRequired
|
|
@@ -145,12 +129,9 @@ export class SilentFlowClient extends BaseClient {
|
|
|
145
129
|
|
|
146
130
|
if (!cacheRecord.accessToken) {
|
|
147
131
|
// must refresh due to non-existent access_token
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
this.logger.info(
|
|
153
|
-
"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties."
|
|
132
|
+
this.setCacheOutcome(
|
|
133
|
+
CacheOutcome.NO_CACHED_ACCESS_TOKEN,
|
|
134
|
+
request.correlationId
|
|
154
135
|
);
|
|
155
136
|
throw createClientAuthError(
|
|
156
137
|
ClientAuthErrorCodes.tokenRefreshRequired
|
|
@@ -163,12 +144,9 @@ export class SilentFlowClient extends BaseClient {
|
|
|
163
144
|
)
|
|
164
145
|
) {
|
|
165
146
|
// must refresh due to the expires_in value
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
);
|
|
170
|
-
this.logger.info(
|
|
171
|
-
`SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`
|
|
147
|
+
this.setCacheOutcome(
|
|
148
|
+
CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED,
|
|
149
|
+
request.correlationId
|
|
172
150
|
);
|
|
173
151
|
throw createClientAuthError(
|
|
174
152
|
ClientAuthErrorCodes.tokenRefreshRequired
|
|
@@ -179,26 +157,44 @@ export class SilentFlowClient extends BaseClient {
|
|
|
179
157
|
) {
|
|
180
158
|
// must refresh (in the background) due to the refresh_in value
|
|
181
159
|
lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
|
|
182
|
-
this.serverTelemetryManager?.setCacheOutcome(
|
|
183
|
-
CacheOutcome.PROACTIVELY_REFRESHED
|
|
184
|
-
);
|
|
185
|
-
this.logger.info(
|
|
186
|
-
"SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'."
|
|
187
|
-
);
|
|
188
160
|
|
|
189
161
|
// don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
|
|
190
162
|
}
|
|
191
163
|
|
|
164
|
+
this.setCacheOutcome(lastCacheOutcome, request.correlationId);
|
|
165
|
+
|
|
192
166
|
if (this.config.serverTelemetryManager) {
|
|
193
167
|
this.config.serverTelemetryManager.incrementCacheHits();
|
|
194
168
|
}
|
|
195
169
|
|
|
196
170
|
return [
|
|
197
|
-
await
|
|
171
|
+
await invokeAsync(
|
|
172
|
+
this.generateResultFromCacheRecord.bind(this),
|
|
173
|
+
PerformanceEvents.SilentFlowClientGenerateResultFromCacheRecord,
|
|
174
|
+
this.logger,
|
|
175
|
+
this.performanceClient,
|
|
176
|
+
request.correlationId
|
|
177
|
+
)(cacheRecord, request),
|
|
198
178
|
lastCacheOutcome,
|
|
199
179
|
];
|
|
200
180
|
}
|
|
201
181
|
|
|
182
|
+
private setCacheOutcome(
|
|
183
|
+
cacheOutcome: CacheOutcome,
|
|
184
|
+
correlationId: string
|
|
185
|
+
): void {
|
|
186
|
+
this.serverTelemetryManager?.setCacheOutcome(cacheOutcome);
|
|
187
|
+
this.performanceClient?.addFields(
|
|
188
|
+
{
|
|
189
|
+
cacheOutcome: cacheOutcome,
|
|
190
|
+
},
|
|
191
|
+
correlationId
|
|
192
|
+
);
|
|
193
|
+
this.logger.info(
|
|
194
|
+
`Token refresh is required due to cache outcome: ${cacheOutcome}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
202
198
|
/**
|
|
203
199
|
* Helper function to build response object from the CacheRecord
|
|
204
200
|
* @param cacheRecord
|
|
@@ -207,6 +203,10 @@ export class SilentFlowClient extends BaseClient {
|
|
|
207
203
|
cacheRecord: CacheRecord,
|
|
208
204
|
request: CommonSilentFlowRequest
|
|
209
205
|
): Promise<AuthenticationResult> {
|
|
206
|
+
this.performanceClient?.addQueueMeasurement(
|
|
207
|
+
PerformanceEvents.SilentFlowClientGenerateResultFromCacheRecord,
|
|
208
|
+
request.correlationId
|
|
209
|
+
);
|
|
210
210
|
let idTokenClaims: TokenClaims | undefined;
|
|
211
211
|
if (cacheRecord.idToken) {
|
|
212
212
|
idTokenClaims = extractTokenClaims(
|
|
@@ -89,6 +89,8 @@ export const ClientAuthErrorMessages = {
|
|
|
89
89
|
"A tenant id - not common, organizations, or consumers - must be specified when using the client_credentials flow.",
|
|
90
90
|
[ClientAuthErrorCodes.methodNotImplemented]:
|
|
91
91
|
"This method has not been implemented",
|
|
92
|
+
[ClientAuthErrorCodes.nestedAppAuthBridgeDisabled]:
|
|
93
|
+
"The nested app auth bridge is disabled",
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
/**
|
|
@@ -306,6 +308,12 @@ export const ClientAuthErrorMessage = {
|
|
|
306
308
|
ClientAuthErrorCodes.missingTenantIdError
|
|
307
309
|
],
|
|
308
310
|
},
|
|
311
|
+
nestedAppAuthBridgeDisabled: {
|
|
312
|
+
code: ClientAuthErrorCodes.nestedAppAuthBridgeDisabled,
|
|
313
|
+
desc: ClientAuthErrorMessages[
|
|
314
|
+
ClientAuthErrorCodes.nestedAppAuthBridgeDisabled
|
|
315
|
+
],
|
|
316
|
+
},
|
|
309
317
|
};
|
|
310
318
|
|
|
311
319
|
/**
|
|
@@ -49,3 +49,4 @@ export const noNetworkConnectivity = "no_network_connectivity";
|
|
|
49
49
|
export const userCanceled = "user_canceled";
|
|
50
50
|
export const missingTenantIdError = "missing_tenant_id_error";
|
|
51
51
|
export const methodNotImplemented = "method_not_implemented";
|
|
52
|
+
export const nestedAppAuthBridgeDisabled = "nested_app_auth_bridge_disabled";
|
package/src/index.ts
CHANGED
|
@@ -39,10 +39,15 @@ export {
|
|
|
39
39
|
buildClientInfoFromHomeAccountId,
|
|
40
40
|
} from "./account/ClientInfo";
|
|
41
41
|
// Authority
|
|
42
|
-
export {
|
|
42
|
+
export {
|
|
43
|
+
Authority,
|
|
44
|
+
formatAuthorityUri,
|
|
45
|
+
buildStaticAuthorityOptions,
|
|
46
|
+
} from "./authority/Authority";
|
|
43
47
|
export {
|
|
44
48
|
AuthorityOptions,
|
|
45
49
|
AzureCloudInstance,
|
|
50
|
+
StaticAuthorityOptions,
|
|
46
51
|
} from "./authority/AuthorityOptions";
|
|
47
52
|
export { AuthorityFactory } from "./authority/AuthorityFactory";
|
|
48
53
|
export { AuthorityType } from "./authority/AuthorityType";
|
|
@@ -66,6 +71,7 @@ export {
|
|
|
66
71
|
} from "./cache/utils/CacheTypes";
|
|
67
72
|
export { CacheRecord } from "./cache/entities/CacheRecord";
|
|
68
73
|
export { CredentialEntity } from "./cache/entities/CredentialEntity";
|
|
74
|
+
export * as CacheHelpers from "./cache/utils/CacheHelpers";
|
|
69
75
|
export { AppMetadataEntity } from "./cache/entities/AppMetadataEntity";
|
|
70
76
|
export { AccountEntity } from "./cache/entities/AccountEntity";
|
|
71
77
|
export { IdTokenEntity } from "./cache/entities/IdTokenEntity";
|
package/src/packageMetadata.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { ServerAuthorizationTokenResponse } from "./ServerAuthorizationTokenResponse";
|
|
7
|
-
import { buildClientInfo } from "../account/ClientInfo";
|
|
8
7
|
import { ICrypto } from "../crypto/ICrypto";
|
|
9
8
|
import {
|
|
10
9
|
ClientAuthErrorCodes,
|
|
@@ -44,6 +43,8 @@ import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient"
|
|
|
44
43
|
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
45
44
|
import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
46
45
|
import { TokenClaims } from "../account/TokenClaims";
|
|
46
|
+
import { AccountInfo } from "../account/AccountInfo";
|
|
47
|
+
import * as CacheHelpers from "../cache/utils/CacheHelpers";
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Class that handles response parsing.
|
|
@@ -80,16 +81,15 @@ export class ResponseHandler {
|
|
|
80
81
|
/**
|
|
81
82
|
* Function which validates server authorization code response.
|
|
82
83
|
* @param serverResponseHash
|
|
83
|
-
* @param
|
|
84
|
+
* @param requestState
|
|
84
85
|
* @param cryptoObj
|
|
85
86
|
*/
|
|
86
87
|
validateServerAuthorizationCodeResponse(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
cryptoObj: ICrypto
|
|
88
|
+
serverResponse: ServerAuthorizationCodeResponse,
|
|
89
|
+
requestState: string
|
|
90
90
|
): void {
|
|
91
|
-
if (!
|
|
92
|
-
throw
|
|
91
|
+
if (!serverResponse.state || !requestState) {
|
|
92
|
+
throw serverResponse.state
|
|
93
93
|
? createClientAuthError(
|
|
94
94
|
ClientAuthErrorCodes.stateNotFound,
|
|
95
95
|
"Cached State"
|
|
@@ -100,67 +100,63 @@ export class ResponseHandler {
|
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
let
|
|
104
|
-
let
|
|
103
|
+
let decodedServerResponseState: string;
|
|
104
|
+
let decodedRequestState: string;
|
|
105
105
|
|
|
106
106
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
decodedServerResponseState = decodeURIComponent(
|
|
108
|
+
serverResponse.state
|
|
109
109
|
);
|
|
110
110
|
} catch (e) {
|
|
111
111
|
throw createClientAuthError(
|
|
112
112
|
ClientAuthErrorCodes.invalidState,
|
|
113
|
-
|
|
113
|
+
serverResponse.state
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
try {
|
|
118
|
-
|
|
118
|
+
decodedRequestState = decodeURIComponent(requestState);
|
|
119
119
|
} catch (e) {
|
|
120
120
|
throw createClientAuthError(
|
|
121
121
|
ClientAuthErrorCodes.invalidState,
|
|
122
|
-
|
|
122
|
+
serverResponse.state
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
if (
|
|
126
|
+
if (decodedServerResponseState !== decodedRequestState) {
|
|
127
127
|
throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Check for error
|
|
131
131
|
if (
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
serverResponse.error ||
|
|
133
|
+
serverResponse.error_description ||
|
|
134
|
+
serverResponse.suberror
|
|
135
135
|
) {
|
|
136
136
|
if (
|
|
137
137
|
isInteractionRequiredError(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
serverResponse.error,
|
|
139
|
+
serverResponse.error_description,
|
|
140
|
+
serverResponse.suberror
|
|
141
141
|
)
|
|
142
142
|
) {
|
|
143
143
|
throw new InteractionRequiredAuthError(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
serverResponse.error || "",
|
|
145
|
+
serverResponse.error_description,
|
|
146
|
+
serverResponse.suberror,
|
|
147
|
+
serverResponse.timestamp || "",
|
|
148
|
+
serverResponse.trace_id || "",
|
|
149
|
+
serverResponse.correlation_id || "",
|
|
150
|
+
serverResponse.claims || ""
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
throw new ServerError(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
serverResponse.error || "",
|
|
156
|
+
serverResponse.error_description,
|
|
157
|
+
serverResponse.suberror
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
if (serverResponseHash.client_info) {
|
|
162
|
-
buildClientInfo(serverResponseHash.client_info, cryptoObj);
|
|
163
|
-
}
|
|
164
160
|
}
|
|
165
161
|
|
|
166
162
|
/**
|
|
@@ -414,7 +410,7 @@ export class ResponseHandler {
|
|
|
414
410
|
let cachedIdToken: IdTokenEntity | undefined;
|
|
415
411
|
let cachedAccount: AccountEntity | undefined;
|
|
416
412
|
if (serverTokenResponse.id_token && !!idTokenClaims) {
|
|
417
|
-
cachedIdToken =
|
|
413
|
+
cachedIdToken = CacheHelpers.createIdTokenEntity(
|
|
418
414
|
this.homeAccountIdentifier,
|
|
419
415
|
env,
|
|
420
416
|
serverTokenResponse.id_token,
|
|
@@ -467,16 +463,16 @@ export class ResponseHandler {
|
|
|
467
463
|
: undefined;
|
|
468
464
|
|
|
469
465
|
// non AAD scenarios can have empty realm
|
|
470
|
-
cachedAccessToken =
|
|
466
|
+
cachedAccessToken = CacheHelpers.createAccessTokenEntity(
|
|
471
467
|
this.homeAccountIdentifier,
|
|
472
468
|
env,
|
|
473
|
-
serverTokenResponse.access_token
|
|
469
|
+
serverTokenResponse.access_token,
|
|
474
470
|
this.clientId,
|
|
475
471
|
idTokenClaims?.tid || authority.tenant,
|
|
476
472
|
responseScopes.printScopes(),
|
|
477
473
|
tokenExpirationSeconds,
|
|
478
474
|
extendedTokenExpirationSeconds,
|
|
479
|
-
this.cryptoObj,
|
|
475
|
+
this.cryptoObj.base64Decode,
|
|
480
476
|
refreshOnSeconds,
|
|
481
477
|
serverTokenResponse.token_type,
|
|
482
478
|
userAssertionHash,
|
|
@@ -489,10 +485,10 @@ export class ResponseHandler {
|
|
|
489
485
|
// refreshToken
|
|
490
486
|
let cachedRefreshToken: RefreshTokenEntity | null = null;
|
|
491
487
|
if (serverTokenResponse.refresh_token) {
|
|
492
|
-
cachedRefreshToken =
|
|
488
|
+
cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
|
|
493
489
|
this.homeAccountIdentifier,
|
|
494
490
|
env,
|
|
495
|
-
serverTokenResponse.refresh_token
|
|
491
|
+
serverTokenResponse.refresh_token,
|
|
496
492
|
this.clientId,
|
|
497
493
|
serverTokenResponse.foci,
|
|
498
494
|
userAssertionHash
|
|
@@ -599,14 +595,19 @@ export class ResponseHandler {
|
|
|
599
595
|
serverTokenResponse?.spa_accountid;
|
|
600
596
|
}
|
|
601
597
|
|
|
598
|
+
const accountInfo: AccountInfo | null = cacheRecord.account
|
|
599
|
+
? {
|
|
600
|
+
...cacheRecord.account.getAccountInfo(),
|
|
601
|
+
idTokenClaims,
|
|
602
|
+
}
|
|
603
|
+
: null;
|
|
604
|
+
|
|
602
605
|
return {
|
|
603
606
|
authority: authority.canonicalAuthority,
|
|
604
607
|
uniqueId: uid,
|
|
605
608
|
tenantId: tid,
|
|
606
609
|
scopes: responseScopes,
|
|
607
|
-
account:
|
|
608
|
-
? cacheRecord.account.getAccountInfo()
|
|
609
|
-
: null,
|
|
610
|
+
account: accountInfo,
|
|
610
611
|
idToken: cacheRecord?.idToken?.secret || "",
|
|
611
612
|
idTokenClaims: idTokenClaims || {},
|
|
612
613
|
accessToken: accessToken,
|
|
@@ -101,8 +101,10 @@ export const PerformanceEvents = {
|
|
|
101
101
|
/**
|
|
102
102
|
* Time spent sending/waiting for the response of a request to the token endpoint
|
|
103
103
|
*/
|
|
104
|
-
|
|
105
|
-
"
|
|
104
|
+
RefreshTokenClientExecutePostToTokenEndpoint:
|
|
105
|
+
"refreshTokenClientExecutePostToTokenEndpoint",
|
|
106
|
+
AuthorizationCodeClientExecutePostToTokenEndpoint:
|
|
107
|
+
"authorizationCodeClientExecutePostToTokenEndpoint",
|
|
106
108
|
/**
|
|
107
109
|
* Used to measure the time taken for completing embedded-broker handshake (PW-Broker).
|
|
108
110
|
*/
|
|
@@ -150,6 +152,9 @@ export const PerformanceEvents = {
|
|
|
150
152
|
* Internal API for acquiring token from cache
|
|
151
153
|
*/
|
|
152
154
|
AcquireTokenFromCache: "acquireTokenFromCache",
|
|
155
|
+
SilentFlowClientAcquireCachedToken: "silentFlowClientAcquireCachedToken",
|
|
156
|
+
SilentFlowClientGenerateResultFromCacheRecord:
|
|
157
|
+
"silentFlowClientGenerateResultFromCacheRecord",
|
|
153
158
|
|
|
154
159
|
/**
|
|
155
160
|
* acquireTokenBySilentIframe (msal-browser).
|
|
@@ -180,6 +185,7 @@ export const PerformanceEvents = {
|
|
|
180
185
|
SilentHandlerInitiateAuthRequest: "silentHandlerInitiateAuthRequest",
|
|
181
186
|
SilentHandlerMonitorIframeForHash: "silentHandlerMonitorIframeForHash",
|
|
182
187
|
SilentHandlerLoadFrame: "silentHandlerLoadFrame",
|
|
188
|
+
SilentHandlerLoadFrameSync: "silentHandlerLoadFrameSync",
|
|
183
189
|
|
|
184
190
|
/**
|
|
185
191
|
* Helper functions in StandardInteractionClient class (msal-browser)
|
|
@@ -230,6 +236,8 @@ export const PerformanceEvents = {
|
|
|
230
236
|
AuthorityFactoryCreateDiscoveredInstance:
|
|
231
237
|
"authorityFactoryCreateDiscoveredInstance",
|
|
232
238
|
AuthorityResolveEndpointsAsync: "authorityResolveEndpointsAsync",
|
|
239
|
+
AuthorityResolveEndpointsFromLocalSources:
|
|
240
|
+
"authorityResolveEndpointsFromLocalSources",
|
|
233
241
|
AuthorityGetCloudDiscoveryMetadataFromNetwork:
|
|
234
242
|
"authorityGetCloudDiscoveryMetadataFromNetwork",
|
|
235
243
|
AuthorityUpdateCloudDiscoveryMetadata:
|
|
@@ -264,10 +272,13 @@ export const PerformanceEvents = {
|
|
|
264
272
|
|
|
265
273
|
NativeGenerateAuthResult: "nativeGenerateAuthResult",
|
|
266
274
|
|
|
275
|
+
RemoveHiddenIframe: "removeHiddenIframe",
|
|
276
|
+
|
|
267
277
|
/**
|
|
268
278
|
* Cache operations
|
|
269
279
|
*/
|
|
270
280
|
ClearTokensAndKeysWithClaims: "clearTokensAndKeysWithClaims",
|
|
281
|
+
CacheManagerGetRefreshToken: "cacheManagerGetRefreshToken",
|
|
271
282
|
|
|
272
283
|
/**
|
|
273
284
|
* Crypto Operations
|
|
@@ -443,6 +454,12 @@ export type PerformanceEvent = {
|
|
|
443
454
|
*/
|
|
444
455
|
cacheLookupPolicy?: number | undefined;
|
|
445
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Cache Outcome
|
|
459
|
+
* @type {?number}
|
|
460
|
+
*/
|
|
461
|
+
cacheOutcome?: number;
|
|
462
|
+
|
|
446
463
|
/**
|
|
447
464
|
* Amount of time spent in the JS queue in milliseconds.
|
|
448
465
|
*
|
|
@@ -536,6 +553,11 @@ export type PerformanceEvent = {
|
|
|
536
553
|
extensionInstalled?: boolean;
|
|
537
554
|
extensionHandshakeTimeoutMs?: number;
|
|
538
555
|
extensionHandshakeTimedOut?: boolean;
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Nested App Auth Fields
|
|
559
|
+
*/
|
|
560
|
+
nestedAppAuthRequest?: boolean;
|
|
539
561
|
};
|
|
540
562
|
|
|
541
563
|
export const IntFields: ReadonlySet<string> = new Set([
|