@azure/msal-common 14.0.1 → 14.0.3
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.d.ts +14 -17
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.mjs +48 -39
- package/dist/account/AuthToken.mjs.map +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/CcsCredential.mjs.map +1 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +3 -4
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/authority/Authority.d.ts +1 -0
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +4 -2
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts +1 -0
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +3 -3
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +1 -1
- package/dist/authority/AuthorityMetadata.mjs.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/AuthorityType.mjs.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs.map +1 -1
- package/dist/authority/RegionDiscovery.mjs +1 -1
- package/dist/authority/RegionDiscovery.mjs.map +1 -1
- package/dist/cache/CacheManager.d.ts +2 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +7 -5
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.mjs +4 -7
- package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts +1 -0
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +3 -4
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +2 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/CacheRecord.d.ts +1 -0
- package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
- package/dist/cache/entities/CacheRecord.mjs +2 -1
- package/dist/cache/entities/CacheRecord.mjs.map +1 -1
- package/dist/cache/entities/CredentialEntity.mjs +1 -1
- package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
- package/dist/cache/entities/IdTokenEntity.mjs +1 -1
- package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +7 -0
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts +1 -0
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +11 -39
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +2 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +9 -2
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts +1 -0
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +3 -11
- 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 +8 -7
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.d.ts +2 -0
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +1 -1
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/JoseHeader.d.ts +1 -0
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.mjs +2 -1
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +1 -0
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +2 -1
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthError.mjs.map +1 -1
- package/dist/error/ClientAuthError.mjs +1 -1
- package/dist/error/ClientAuthError.mjs.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs.map +1 -1
- package/dist/error/ServerError.mjs +1 -1
- package/dist/error/ServerError.mjs.map +1 -1
- package/dist/index.cjs +1926 -1826
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.mjs +2 -12
- package/dist/logger/Logger.mjs.map +1 -1
- package/dist/network/INetworkModule.mjs +1 -1
- package/dist/network/INetworkModule.mjs.map +1 -1
- package/dist/network/NetworkManager.d.ts +1 -0
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.mjs +2 -1
- package/dist/network/NetworkManager.mjs.map +1 -1
- package/dist/network/ThrottlingUtils.d.ts +1 -0
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.mjs +2 -1
- package/dist/network/ThrottlingUtils.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts +1 -0
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +7 -7
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.mjs +4 -6
- package/dist/request/RequestValidator.mjs.map +1 -1
- package/dist/request/ScopeSet.mjs +4 -4
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/response/AuthenticationResult.d.ts +3 -1
- package/dist/response/AuthenticationResult.d.ts.map +1 -1
- package/dist/response/ResponseHandler.d.ts +5 -3
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +58 -39
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +4 -4
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +2 -2
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +3 -3
- package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +23 -3
- package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +1 -0
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +4 -4
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.mjs +10 -12
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +10 -0
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +11 -2
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts +28 -0
- package/dist/utils/FunctionWrappers.d.ts.map +1 -0
- package/dist/utils/FunctionWrappers.mjs +90 -0
- package/dist/utils/FunctionWrappers.mjs.map +1 -0
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +4 -7
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StringUtils.d.ts +0 -13
- package/dist/utils/StringUtils.d.ts.map +1 -1
- package/dist/utils/StringUtils.mjs +3 -34
- package/dist/utils/StringUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/package.json +6 -4
- package/src/account/AccountInfo.ts +44 -0
- package/src/account/AuthToken.ts +70 -0
- package/src/account/CcsCredential.ts +16 -0
- package/src/account/ClientCredentials.ts +20 -0
- package/src/account/ClientInfo.ts +64 -0
- package/src/account/TokenClaims.ts +70 -0
- package/src/authority/Authority.ts +1225 -0
- package/src/authority/AuthorityFactory.ts +106 -0
- package/src/authority/AuthorityMetadata.ts +953 -0
- package/src/authority/AuthorityOptions.ts +40 -0
- package/src/authority/AuthorityType.ts +15 -0
- package/src/authority/AzureRegion.ts +7 -0
- package/src/authority/AzureRegionConfiguration.ts +16 -0
- package/src/authority/CloudDiscoveryMetadata.ts +10 -0
- package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
- package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
- package/src/authority/ImdsOptions.ts +10 -0
- package/src/authority/OIDCOptions.ts +14 -0
- package/src/authority/OpenIdConfigResponse.ts +24 -0
- package/src/authority/ProtocolMode.ts +13 -0
- package/src/authority/RegionDiscovery.ts +193 -0
- package/src/authority/RegionDiscoveryMetadata.ts +15 -0
- package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
- package/src/cache/CacheManager.ts +1619 -0
- package/src/cache/entities/AccessTokenEntity.ts +162 -0
- package/src/cache/entities/AccountEntity.ts +309 -0
- package/src/cache/entities/AppMetadataEntity.ts +91 -0
- package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
- package/src/cache/entities/CacheRecord.ts +33 -0
- package/src/cache/entities/CredentialEntity.ts +215 -0
- package/src/cache/entities/IdTokenEntity.ts +74 -0
- package/src/cache/entities/RefreshTokenEntity.ts +78 -0
- package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
- package/src/cache/entities/ThrottlingEntity.ts +36 -0
- package/src/cache/interface/ICacheManager.ts +218 -0
- package/src/cache/interface/ICachePlugin.ts +11 -0
- package/src/cache/interface/ISerializableTokenCache.ts +9 -0
- package/src/cache/persistence/TokenCacheContext.ts +39 -0
- package/src/cache/utils/CacheTypes.ts +93 -0
- package/src/client/AuthorizationCodeClient.ts +714 -0
- package/src/client/BaseClient.ts +205 -0
- package/src/client/RefreshTokenClient.ts +442 -0
- package/src/client/SilentFlowClient.ts +186 -0
- package/src/config/AppTokenProvider.ts +47 -0
- package/src/config/ClientConfiguration.ts +287 -0
- package/src/crypto/ICrypto.ts +127 -0
- package/src/crypto/IGuidGenerator.ts +9 -0
- package/src/crypto/JoseHeader.ts +55 -0
- package/src/crypto/PopTokenGenerator.ts +155 -0
- package/src/crypto/SignedHttpRequest.ts +16 -0
- package/src/error/AuthError.ts +85 -0
- package/src/error/ClientAuthError.ts +738 -0
- package/src/error/ClientConfigurationError.ts +396 -0
- package/src/error/InteractionRequiredAuthError.ts +134 -0
- package/src/error/JoseHeaderError.ts +52 -0
- package/src/error/ServerError.ts +18 -0
- package/src/index.ts +215 -0
- package/src/logger/Logger.ts +272 -0
- package/src/network/INetworkModule.ts +57 -0
- package/src/network/NetworkManager.ts +76 -0
- package/src/network/RequestThumbprint.ts +22 -0
- package/src/network/ThrottlingUtils.ts +156 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthenticationHeaderParser.ts +89 -0
- package/src/request/BaseAuthRequest.ts +46 -0
- package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
- package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
- package/src/request/CommonClientCredentialRequest.ts +23 -0
- package/src/request/CommonDeviceCodeRequest.ts +31 -0
- package/src/request/CommonEndSessionRequest.ts +27 -0
- package/src/request/CommonOnBehalfOfRequest.ts +19 -0
- package/src/request/CommonRefreshTokenRequest.ts +25 -0
- package/src/request/CommonSilentFlowRequest.ts +24 -0
- package/src/request/CommonUsernamePasswordRequest.ts +23 -0
- package/src/request/NativeRequest.ts +25 -0
- package/src/request/NativeSignOutRequest.ts +10 -0
- package/src/request/RequestParameterBuilder.ts +606 -0
- package/src/request/RequestValidator.ts +103 -0
- package/src/request/ScopeSet.ts +230 -0
- package/src/request/StoreInCache.ts +16 -0
- package/src/response/AuthenticationResult.ts +47 -0
- package/src/response/AuthorizationCodePayload.ts +18 -0
- package/src/response/DeviceCodeResponse.ts +31 -0
- package/src/response/ExternalTokenResponse.ts +24 -0
- package/src/response/IMDSBadResponse.ts +9 -0
- package/src/response/ResponseHandler.ts +614 -0
- package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
- package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
- package/src/telemetry/performance/IPerformanceClient.ts +71 -0
- package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
- package/src/telemetry/performance/PerformanceClient.ts +635 -0
- package/src/telemetry/performance/PerformanceEvent.ts +542 -0
- package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
- package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
- package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
- package/src/url/IUri.ts +17 -0
- package/src/url/UrlString.ts +363 -0
- package/src/utils/Constants.ts +436 -0
- package/src/utils/FunctionWrappers.ts +105 -0
- package/src/utils/MsalTypes.ts +9 -0
- package/src/utils/ProtocolUtils.ts +124 -0
- package/src/utils/StringUtils.ts +106 -0
- package/src/utils/TimeUtils.ts +51 -0
- package/dist/account/DecodedAuthToken.d.ts +0 -9
- package/dist/account/DecodedAuthToken.d.ts.map +0 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ServerAuthorizationTokenResponse } from "./ServerAuthorizationTokenResponse";
|
|
7
|
+
import { buildClientInfo } from "../account/ClientInfo";
|
|
8
|
+
import { ICrypto } from "../crypto/ICrypto";
|
|
9
|
+
import { ClientAuthError } from "../error/ClientAuthError";
|
|
10
|
+
import { ServerAuthorizationCodeResponse } from "./ServerAuthorizationCodeResponse";
|
|
11
|
+
import { Logger } from "../logger/Logger";
|
|
12
|
+
import { ServerError } from "../error/ServerError";
|
|
13
|
+
import { ScopeSet } from "../request/ScopeSet";
|
|
14
|
+
import { AuthenticationResult } from "./AuthenticationResult";
|
|
15
|
+
import { AccountEntity } from "../cache/entities/AccountEntity";
|
|
16
|
+
import { Authority } from "../authority/Authority";
|
|
17
|
+
import { IdTokenEntity } from "../cache/entities/IdTokenEntity";
|
|
18
|
+
import { AccessTokenEntity } from "../cache/entities/AccessTokenEntity";
|
|
19
|
+
import { RefreshTokenEntity } from "../cache/entities/RefreshTokenEntity";
|
|
20
|
+
import { InteractionRequiredAuthError } from "../error/InteractionRequiredAuthError";
|
|
21
|
+
import { CacheRecord } from "../cache/entities/CacheRecord";
|
|
22
|
+
import { CacheManager } from "../cache/CacheManager";
|
|
23
|
+
import { ProtocolUtils, RequestStateObject } from "../utils/ProtocolUtils";
|
|
24
|
+
import {
|
|
25
|
+
AuthenticationScheme,
|
|
26
|
+
Constants,
|
|
27
|
+
THE_FAMILY_ID,
|
|
28
|
+
HttpStatus,
|
|
29
|
+
} from "../utils/Constants";
|
|
30
|
+
import { PopTokenGenerator } from "../crypto/PopTokenGenerator";
|
|
31
|
+
import { AppMetadataEntity } from "../cache/entities/AppMetadataEntity";
|
|
32
|
+
import { ICachePlugin } from "../cache/interface/ICachePlugin";
|
|
33
|
+
import { TokenCacheContext } from "../cache/persistence/TokenCacheContext";
|
|
34
|
+
import { ISerializableTokenCache } from "../cache/interface/ISerializableTokenCache";
|
|
35
|
+
import { AuthorizationCodePayload } from "./AuthorizationCodePayload";
|
|
36
|
+
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
37
|
+
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
38
|
+
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
39
|
+
import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
40
|
+
import { TokenClaims } from "../account/TokenClaims";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Class that handles response parsing.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export class ResponseHandler {
|
|
47
|
+
private clientId: string;
|
|
48
|
+
private cacheStorage: CacheManager;
|
|
49
|
+
private cryptoObj: ICrypto;
|
|
50
|
+
private logger: Logger;
|
|
51
|
+
private homeAccountIdentifier: string;
|
|
52
|
+
private serializableCache: ISerializableTokenCache | null;
|
|
53
|
+
private persistencePlugin: ICachePlugin | null;
|
|
54
|
+
private performanceClient?: IPerformanceClient;
|
|
55
|
+
|
|
56
|
+
constructor(
|
|
57
|
+
clientId: string,
|
|
58
|
+
cacheStorage: CacheManager,
|
|
59
|
+
cryptoObj: ICrypto,
|
|
60
|
+
logger: Logger,
|
|
61
|
+
serializableCache: ISerializableTokenCache | null,
|
|
62
|
+
persistencePlugin: ICachePlugin | null,
|
|
63
|
+
performanceClient?: IPerformanceClient
|
|
64
|
+
) {
|
|
65
|
+
this.clientId = clientId;
|
|
66
|
+
this.cacheStorage = cacheStorage;
|
|
67
|
+
this.cryptoObj = cryptoObj;
|
|
68
|
+
this.logger = logger;
|
|
69
|
+
this.serializableCache = serializableCache;
|
|
70
|
+
this.persistencePlugin = persistencePlugin;
|
|
71
|
+
this.performanceClient = performanceClient;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Function which validates server authorization code response.
|
|
76
|
+
* @param serverResponseHash
|
|
77
|
+
* @param cachedState
|
|
78
|
+
* @param cryptoObj
|
|
79
|
+
*/
|
|
80
|
+
validateServerAuthorizationCodeResponse(
|
|
81
|
+
serverResponseHash: ServerAuthorizationCodeResponse,
|
|
82
|
+
cachedState: string,
|
|
83
|
+
cryptoObj: ICrypto
|
|
84
|
+
): void {
|
|
85
|
+
if (!serverResponseHash.state || !cachedState) {
|
|
86
|
+
throw serverResponseHash.state
|
|
87
|
+
? ClientAuthError.createStateNotFoundError("Cached State")
|
|
88
|
+
: ClientAuthError.createStateNotFoundError("Server State");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let decodedServerResponseHash: string;
|
|
92
|
+
let decodedCachedState: string;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
decodedServerResponseHash = decodeURIComponent(
|
|
96
|
+
serverResponseHash.state
|
|
97
|
+
);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw ClientAuthError.createInvalidStateError(
|
|
100
|
+
serverResponseHash.state,
|
|
101
|
+
`Server response hash URI could not be decoded`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
decodedCachedState = decodeURIComponent(cachedState);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
throw ClientAuthError.createInvalidStateError(
|
|
109
|
+
serverResponseHash.state,
|
|
110
|
+
`Cached state URI could not be decoded`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (decodedServerResponseHash !== decodedCachedState) {
|
|
115
|
+
throw ClientAuthError.createStateMismatchError();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Check for error
|
|
119
|
+
if (
|
|
120
|
+
serverResponseHash.error ||
|
|
121
|
+
serverResponseHash.error_description ||
|
|
122
|
+
serverResponseHash.suberror
|
|
123
|
+
) {
|
|
124
|
+
if (
|
|
125
|
+
InteractionRequiredAuthError.isInteractionRequiredError(
|
|
126
|
+
serverResponseHash.error,
|
|
127
|
+
serverResponseHash.error_description,
|
|
128
|
+
serverResponseHash.suberror
|
|
129
|
+
)
|
|
130
|
+
) {
|
|
131
|
+
throw new InteractionRequiredAuthError(
|
|
132
|
+
serverResponseHash.error || Constants.EMPTY_STRING,
|
|
133
|
+
serverResponseHash.error_description,
|
|
134
|
+
serverResponseHash.suberror,
|
|
135
|
+
serverResponseHash.timestamp || Constants.EMPTY_STRING,
|
|
136
|
+
serverResponseHash.trace_id || Constants.EMPTY_STRING,
|
|
137
|
+
serverResponseHash.correlation_id || Constants.EMPTY_STRING,
|
|
138
|
+
serverResponseHash.claims || Constants.EMPTY_STRING
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
throw new ServerError(
|
|
143
|
+
serverResponseHash.error || Constants.EMPTY_STRING,
|
|
144
|
+
serverResponseHash.error_description,
|
|
145
|
+
serverResponseHash.suberror
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (serverResponseHash.client_info) {
|
|
150
|
+
buildClientInfo(serverResponseHash.client_info, cryptoObj);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Function which validates server authorization token response.
|
|
156
|
+
* @param serverResponse
|
|
157
|
+
* @param refreshAccessToken
|
|
158
|
+
*/
|
|
159
|
+
validateTokenResponse(
|
|
160
|
+
serverResponse: ServerAuthorizationTokenResponse,
|
|
161
|
+
refreshAccessToken?: boolean
|
|
162
|
+
): void {
|
|
163
|
+
// Check for error
|
|
164
|
+
if (
|
|
165
|
+
serverResponse.error ||
|
|
166
|
+
serverResponse.error_description ||
|
|
167
|
+
serverResponse.suberror
|
|
168
|
+
) {
|
|
169
|
+
const errString = `${serverResponse.error_codes} - [${serverResponse.timestamp}]: ${serverResponse.error_description} - Correlation ID: ${serverResponse.correlation_id} - Trace ID: ${serverResponse.trace_id}`;
|
|
170
|
+
const serverError = new ServerError(
|
|
171
|
+
serverResponse.error,
|
|
172
|
+
errString,
|
|
173
|
+
serverResponse.suberror
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// check if 500 error
|
|
177
|
+
if (
|
|
178
|
+
refreshAccessToken &&
|
|
179
|
+
serverResponse.status &&
|
|
180
|
+
serverResponse.status >= HttpStatus.SERVER_ERROR_RANGE_START &&
|
|
181
|
+
serverResponse.status <= HttpStatus.SERVER_ERROR_RANGE_END
|
|
182
|
+
) {
|
|
183
|
+
this.logger.warning(
|
|
184
|
+
`executeTokenRequest:validateTokenResponse - AAD is currently unavailable and the access token is unable to be refreshed.\n${serverError}`
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// don't throw an exception, but alert the user via a log that the token was unable to be refreshed
|
|
188
|
+
return;
|
|
189
|
+
// check if 400 error
|
|
190
|
+
} else if (
|
|
191
|
+
refreshAccessToken &&
|
|
192
|
+
serverResponse.status &&
|
|
193
|
+
serverResponse.status >= HttpStatus.CLIENT_ERROR_RANGE_START &&
|
|
194
|
+
serverResponse.status <= HttpStatus.CLIENT_ERROR_RANGE_END
|
|
195
|
+
) {
|
|
196
|
+
this.logger.warning(
|
|
197
|
+
`executeTokenRequest:validateTokenResponse - AAD is currently available but is unable to refresh the access token.\n${serverError}`
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// don't throw an exception, but alert the user via a log that the token was unable to be refreshed
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (
|
|
205
|
+
InteractionRequiredAuthError.isInteractionRequiredError(
|
|
206
|
+
serverResponse.error,
|
|
207
|
+
serverResponse.error_description,
|
|
208
|
+
serverResponse.suberror
|
|
209
|
+
)
|
|
210
|
+
) {
|
|
211
|
+
throw new InteractionRequiredAuthError(
|
|
212
|
+
serverResponse.error,
|
|
213
|
+
serverResponse.error_description,
|
|
214
|
+
serverResponse.suberror,
|
|
215
|
+
serverResponse.timestamp || Constants.EMPTY_STRING,
|
|
216
|
+
serverResponse.trace_id || Constants.EMPTY_STRING,
|
|
217
|
+
serverResponse.correlation_id || Constants.EMPTY_STRING,
|
|
218
|
+
serverResponse.claims || Constants.EMPTY_STRING
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
throw serverError;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Returns a constructed token response based on given string. Also manages the cache updates and cleanups.
|
|
228
|
+
* @param serverTokenResponse
|
|
229
|
+
* @param authority
|
|
230
|
+
*/
|
|
231
|
+
async handleServerTokenResponse(
|
|
232
|
+
serverTokenResponse: ServerAuthorizationTokenResponse,
|
|
233
|
+
authority: Authority,
|
|
234
|
+
reqTimestamp: number,
|
|
235
|
+
request: BaseAuthRequest,
|
|
236
|
+
authCodePayload?: AuthorizationCodePayload,
|
|
237
|
+
userAssertionHash?: string,
|
|
238
|
+
handlingRefreshTokenResponse?: boolean,
|
|
239
|
+
forceCacheRefreshTokenResponse?: boolean,
|
|
240
|
+
serverRequestId?: string
|
|
241
|
+
): Promise<AuthenticationResult> {
|
|
242
|
+
this.performanceClient?.addQueueMeasurement(
|
|
243
|
+
PerformanceEvents.HandleServerTokenResponse,
|
|
244
|
+
serverTokenResponse.correlation_id
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// create an idToken object (not entity)
|
|
248
|
+
let idTokenClaims: TokenClaims | undefined;
|
|
249
|
+
if (serverTokenResponse.id_token) {
|
|
250
|
+
idTokenClaims = extractTokenClaims(
|
|
251
|
+
serverTokenResponse.id_token || Constants.EMPTY_STRING,
|
|
252
|
+
this.cryptoObj.base64Decode
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// token nonce check (TODO: Add a warning if no nonce is given?)
|
|
256
|
+
if (authCodePayload && authCodePayload.nonce) {
|
|
257
|
+
if (idTokenClaims.nonce !== authCodePayload.nonce) {
|
|
258
|
+
throw ClientAuthError.createNonceMismatchError();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// token max_age check
|
|
263
|
+
if (request.maxAge || request.maxAge === 0) {
|
|
264
|
+
const authTime = idTokenClaims.auth_time;
|
|
265
|
+
if (!authTime) {
|
|
266
|
+
throw ClientAuthError.createAuthTimeNotFoundError();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
checkMaxAge(authTime, request.maxAge);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// generate homeAccountId
|
|
274
|
+
this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(
|
|
275
|
+
serverTokenResponse.client_info || Constants.EMPTY_STRING,
|
|
276
|
+
authority.authorityType,
|
|
277
|
+
this.logger,
|
|
278
|
+
this.cryptoObj,
|
|
279
|
+
idTokenClaims
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
// save the response tokens
|
|
283
|
+
let requestStateObj: RequestStateObject | undefined;
|
|
284
|
+
if (!!authCodePayload && !!authCodePayload.state) {
|
|
285
|
+
requestStateObj = ProtocolUtils.parseRequestState(
|
|
286
|
+
this.cryptoObj,
|
|
287
|
+
authCodePayload.state
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Add keyId from request to serverTokenResponse if defined
|
|
292
|
+
serverTokenResponse.key_id =
|
|
293
|
+
serverTokenResponse.key_id || request.sshKid || undefined;
|
|
294
|
+
|
|
295
|
+
const cacheRecord = this.generateCacheRecord(
|
|
296
|
+
serverTokenResponse,
|
|
297
|
+
authority,
|
|
298
|
+
reqTimestamp,
|
|
299
|
+
request,
|
|
300
|
+
idTokenClaims,
|
|
301
|
+
userAssertionHash,
|
|
302
|
+
authCodePayload
|
|
303
|
+
);
|
|
304
|
+
let cacheContext;
|
|
305
|
+
try {
|
|
306
|
+
if (this.persistencePlugin && this.serializableCache) {
|
|
307
|
+
this.logger.verbose(
|
|
308
|
+
"Persistence enabled, calling beforeCacheAccess"
|
|
309
|
+
);
|
|
310
|
+
cacheContext = new TokenCacheContext(
|
|
311
|
+
this.serializableCache,
|
|
312
|
+
true
|
|
313
|
+
);
|
|
314
|
+
await this.persistencePlugin.beforeCacheAccess(cacheContext);
|
|
315
|
+
}
|
|
316
|
+
/*
|
|
317
|
+
* When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.
|
|
318
|
+
* If not present, we should return null, as it's the case that another application called removeAccount in between
|
|
319
|
+
* the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal, unless explicitly flagged by
|
|
320
|
+
* the developer, as in the case of refresh token flow used in ADAL Node to MSAL Node migration.
|
|
321
|
+
*/
|
|
322
|
+
if (
|
|
323
|
+
handlingRefreshTokenResponse &&
|
|
324
|
+
!forceCacheRefreshTokenResponse &&
|
|
325
|
+
cacheRecord.account
|
|
326
|
+
) {
|
|
327
|
+
const key = cacheRecord.account.generateAccountKey();
|
|
328
|
+
const account = this.cacheStorage.getAccount(key);
|
|
329
|
+
if (!account) {
|
|
330
|
+
this.logger.warning(
|
|
331
|
+
"Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache"
|
|
332
|
+
);
|
|
333
|
+
return ResponseHandler.generateAuthenticationResult(
|
|
334
|
+
this.cryptoObj,
|
|
335
|
+
authority,
|
|
336
|
+
cacheRecord,
|
|
337
|
+
false,
|
|
338
|
+
request,
|
|
339
|
+
idTokenClaims,
|
|
340
|
+
requestStateObj,
|
|
341
|
+
undefined,
|
|
342
|
+
serverRequestId
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
await this.cacheStorage.saveCacheRecord(
|
|
347
|
+
cacheRecord,
|
|
348
|
+
request.storeInCache
|
|
349
|
+
);
|
|
350
|
+
} finally {
|
|
351
|
+
if (
|
|
352
|
+
this.persistencePlugin &&
|
|
353
|
+
this.serializableCache &&
|
|
354
|
+
cacheContext
|
|
355
|
+
) {
|
|
356
|
+
this.logger.verbose(
|
|
357
|
+
"Persistence enabled, calling afterCacheAccess"
|
|
358
|
+
);
|
|
359
|
+
await this.persistencePlugin.afterCacheAccess(cacheContext);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return ResponseHandler.generateAuthenticationResult(
|
|
363
|
+
this.cryptoObj,
|
|
364
|
+
authority,
|
|
365
|
+
cacheRecord,
|
|
366
|
+
false,
|
|
367
|
+
request,
|
|
368
|
+
idTokenClaims,
|
|
369
|
+
requestStateObj,
|
|
370
|
+
serverTokenResponse,
|
|
371
|
+
serverRequestId
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Generates CacheRecord
|
|
377
|
+
* @param serverTokenResponse
|
|
378
|
+
* @param idTokenObj
|
|
379
|
+
* @param authority
|
|
380
|
+
*/
|
|
381
|
+
private generateCacheRecord(
|
|
382
|
+
serverTokenResponse: ServerAuthorizationTokenResponse,
|
|
383
|
+
authority: Authority,
|
|
384
|
+
reqTimestamp: number,
|
|
385
|
+
request: BaseAuthRequest,
|
|
386
|
+
idTokenClaims?: TokenClaims,
|
|
387
|
+
userAssertionHash?: string,
|
|
388
|
+
authCodePayload?: AuthorizationCodePayload
|
|
389
|
+
): CacheRecord {
|
|
390
|
+
const env = authority.getPreferredCache();
|
|
391
|
+
if (!env) {
|
|
392
|
+
throw ClientAuthError.createInvalidCacheEnvironmentError();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// IdToken: non AAD scenarios can have empty realm
|
|
396
|
+
let cachedIdToken: IdTokenEntity | undefined;
|
|
397
|
+
let cachedAccount: AccountEntity | undefined;
|
|
398
|
+
if (serverTokenResponse.id_token && !!idTokenClaims) {
|
|
399
|
+
cachedIdToken = IdTokenEntity.createIdTokenEntity(
|
|
400
|
+
this.homeAccountIdentifier,
|
|
401
|
+
env,
|
|
402
|
+
serverTokenResponse.id_token,
|
|
403
|
+
this.clientId,
|
|
404
|
+
idTokenClaims.tid || ""
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
cachedAccount = AccountEntity.createAccount(
|
|
408
|
+
{
|
|
409
|
+
homeAccountId: this.homeAccountIdentifier,
|
|
410
|
+
idTokenClaims: idTokenClaims,
|
|
411
|
+
clientInfo: serverTokenResponse.client_info,
|
|
412
|
+
cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
|
|
413
|
+
msGraphHost: authCodePayload?.msgraph_host,
|
|
414
|
+
},
|
|
415
|
+
authority
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// AccessToken
|
|
420
|
+
let cachedAccessToken: AccessTokenEntity | null = null;
|
|
421
|
+
if (serverTokenResponse.access_token) {
|
|
422
|
+
// If scopes not returned in server response, use request scopes
|
|
423
|
+
const responseScopes = serverTokenResponse.scope
|
|
424
|
+
? ScopeSet.fromString(serverTokenResponse.scope)
|
|
425
|
+
: new ScopeSet(request.scopes || []);
|
|
426
|
+
|
|
427
|
+
/*
|
|
428
|
+
* Use timestamp calculated before request
|
|
429
|
+
* Server may return timestamps as strings, parse to numbers if so.
|
|
430
|
+
*/
|
|
431
|
+
const expiresIn: number =
|
|
432
|
+
(typeof serverTokenResponse.expires_in === "string"
|
|
433
|
+
? parseInt(serverTokenResponse.expires_in, 10)
|
|
434
|
+
: serverTokenResponse.expires_in) || 0;
|
|
435
|
+
const extExpiresIn: number =
|
|
436
|
+
(typeof serverTokenResponse.ext_expires_in === "string"
|
|
437
|
+
? parseInt(serverTokenResponse.ext_expires_in, 10)
|
|
438
|
+
: serverTokenResponse.ext_expires_in) || 0;
|
|
439
|
+
const refreshIn: number | undefined =
|
|
440
|
+
(typeof serverTokenResponse.refresh_in === "string"
|
|
441
|
+
? parseInt(serverTokenResponse.refresh_in, 10)
|
|
442
|
+
: serverTokenResponse.refresh_in) || undefined;
|
|
443
|
+
const tokenExpirationSeconds = reqTimestamp + expiresIn;
|
|
444
|
+
const extendedTokenExpirationSeconds =
|
|
445
|
+
tokenExpirationSeconds + extExpiresIn;
|
|
446
|
+
const refreshOnSeconds =
|
|
447
|
+
refreshIn && refreshIn > 0
|
|
448
|
+
? reqTimestamp + refreshIn
|
|
449
|
+
: undefined;
|
|
450
|
+
|
|
451
|
+
// non AAD scenarios can have empty realm
|
|
452
|
+
cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(
|
|
453
|
+
this.homeAccountIdentifier,
|
|
454
|
+
env,
|
|
455
|
+
serverTokenResponse.access_token || Constants.EMPTY_STRING,
|
|
456
|
+
this.clientId,
|
|
457
|
+
idTokenClaims?.tid || authority.tenant,
|
|
458
|
+
responseScopes.printScopes(),
|
|
459
|
+
tokenExpirationSeconds,
|
|
460
|
+
extendedTokenExpirationSeconds,
|
|
461
|
+
this.cryptoObj,
|
|
462
|
+
refreshOnSeconds,
|
|
463
|
+
serverTokenResponse.token_type,
|
|
464
|
+
userAssertionHash,
|
|
465
|
+
serverTokenResponse.key_id,
|
|
466
|
+
request.claims,
|
|
467
|
+
request.requestedClaimsHash
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// refreshToken
|
|
472
|
+
let cachedRefreshToken: RefreshTokenEntity | null = null;
|
|
473
|
+
if (serverTokenResponse.refresh_token) {
|
|
474
|
+
cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(
|
|
475
|
+
this.homeAccountIdentifier,
|
|
476
|
+
env,
|
|
477
|
+
serverTokenResponse.refresh_token || Constants.EMPTY_STRING,
|
|
478
|
+
this.clientId,
|
|
479
|
+
serverTokenResponse.foci,
|
|
480
|
+
userAssertionHash
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// appMetadata
|
|
485
|
+
let cachedAppMetadata: AppMetadataEntity | null = null;
|
|
486
|
+
if (serverTokenResponse.foci) {
|
|
487
|
+
cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(
|
|
488
|
+
this.clientId,
|
|
489
|
+
env,
|
|
490
|
+
serverTokenResponse.foci
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return new CacheRecord(
|
|
495
|
+
cachedAccount,
|
|
496
|
+
cachedIdToken,
|
|
497
|
+
cachedAccessToken,
|
|
498
|
+
cachedRefreshToken,
|
|
499
|
+
cachedAppMetadata
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
|
|
505
|
+
*
|
|
506
|
+
* Optionally takes a state string that is set as-is in the response.
|
|
507
|
+
*
|
|
508
|
+
* @param cacheRecord
|
|
509
|
+
* @param idTokenObj
|
|
510
|
+
* @param fromTokenCache
|
|
511
|
+
* @param stateString
|
|
512
|
+
*/
|
|
513
|
+
static async generateAuthenticationResult(
|
|
514
|
+
cryptoObj: ICrypto,
|
|
515
|
+
authority: Authority,
|
|
516
|
+
cacheRecord: CacheRecord,
|
|
517
|
+
fromTokenCache: boolean,
|
|
518
|
+
request: BaseAuthRequest,
|
|
519
|
+
idTokenClaims?: TokenClaims,
|
|
520
|
+
requestState?: RequestStateObject,
|
|
521
|
+
serverTokenResponse?: ServerAuthorizationTokenResponse,
|
|
522
|
+
requestId?: string
|
|
523
|
+
): Promise<AuthenticationResult> {
|
|
524
|
+
let accessToken: string = Constants.EMPTY_STRING;
|
|
525
|
+
let responseScopes: Array<string> = [];
|
|
526
|
+
let expiresOn: Date | null = null;
|
|
527
|
+
let extExpiresOn: Date | undefined;
|
|
528
|
+
let refreshOn: Date | undefined;
|
|
529
|
+
let familyId: string = Constants.EMPTY_STRING;
|
|
530
|
+
|
|
531
|
+
if (cacheRecord.accessToken) {
|
|
532
|
+
if (
|
|
533
|
+
cacheRecord.accessToken.tokenType === AuthenticationScheme.POP
|
|
534
|
+
) {
|
|
535
|
+
const popTokenGenerator: PopTokenGenerator =
|
|
536
|
+
new PopTokenGenerator(cryptoObj);
|
|
537
|
+
const { secret, keyId } = cacheRecord.accessToken;
|
|
538
|
+
|
|
539
|
+
if (!keyId) {
|
|
540
|
+
throw ClientAuthError.createKeyIdMissingError();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
accessToken = await popTokenGenerator.signPopToken(
|
|
544
|
+
secret,
|
|
545
|
+
keyId,
|
|
546
|
+
request
|
|
547
|
+
);
|
|
548
|
+
} else {
|
|
549
|
+
accessToken = cacheRecord.accessToken.secret;
|
|
550
|
+
}
|
|
551
|
+
responseScopes = ScopeSet.fromString(
|
|
552
|
+
cacheRecord.accessToken.target
|
|
553
|
+
).asArray();
|
|
554
|
+
expiresOn = new Date(
|
|
555
|
+
Number(cacheRecord.accessToken.expiresOn) * 1000
|
|
556
|
+
);
|
|
557
|
+
extExpiresOn = new Date(
|
|
558
|
+
Number(cacheRecord.accessToken.extendedExpiresOn) * 1000
|
|
559
|
+
);
|
|
560
|
+
if (cacheRecord.accessToken.refreshOn) {
|
|
561
|
+
refreshOn = new Date(
|
|
562
|
+
Number(cacheRecord.accessToken.refreshOn) * 1000
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (cacheRecord.appMetadata) {
|
|
568
|
+
familyId =
|
|
569
|
+
cacheRecord.appMetadata.familyId === THE_FAMILY_ID
|
|
570
|
+
? THE_FAMILY_ID
|
|
571
|
+
: "";
|
|
572
|
+
}
|
|
573
|
+
const uid = idTokenClaims?.oid || idTokenClaims?.sub || "";
|
|
574
|
+
const tid = idTokenClaims?.tid || "";
|
|
575
|
+
|
|
576
|
+
// for hybrid + native bridge enablement, send back the native account Id
|
|
577
|
+
if (serverTokenResponse?.spa_accountid && !!cacheRecord.account) {
|
|
578
|
+
cacheRecord.account.nativeAccountId =
|
|
579
|
+
serverTokenResponse?.spa_accountid;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
return {
|
|
583
|
+
authority: authority.canonicalAuthority,
|
|
584
|
+
uniqueId: uid,
|
|
585
|
+
tenantId: tid,
|
|
586
|
+
scopes: responseScopes,
|
|
587
|
+
account: cacheRecord.account
|
|
588
|
+
? cacheRecord.account.getAccountInfo()
|
|
589
|
+
: null,
|
|
590
|
+
idToken: cacheRecord?.idToken?.secret || "",
|
|
591
|
+
idTokenClaims: idTokenClaims || {},
|
|
592
|
+
accessToken: accessToken,
|
|
593
|
+
fromCache: fromTokenCache,
|
|
594
|
+
expiresOn: expiresOn,
|
|
595
|
+
extExpiresOn: extExpiresOn,
|
|
596
|
+
refreshOn: refreshOn,
|
|
597
|
+
correlationId: request.correlationId,
|
|
598
|
+
requestId: requestId || Constants.EMPTY_STRING,
|
|
599
|
+
familyId: familyId,
|
|
600
|
+
tokenType:
|
|
601
|
+
cacheRecord.accessToken?.tokenType || Constants.EMPTY_STRING,
|
|
602
|
+
state: requestState
|
|
603
|
+
? requestState.userRequestState
|
|
604
|
+
: Constants.EMPTY_STRING,
|
|
605
|
+
cloudGraphHostName:
|
|
606
|
+
cacheRecord.account?.cloudGraphHostName ||
|
|
607
|
+
Constants.EMPTY_STRING,
|
|
608
|
+
msGraphHost:
|
|
609
|
+
cacheRecord.account?.msGraphHost || Constants.EMPTY_STRING,
|
|
610
|
+
code: serverTokenResponse?.spa_code,
|
|
611
|
+
fromNativeBroker: false,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Deserialized response object from server authorization code request.
|
|
8
|
+
* - code: authorization code from server
|
|
9
|
+
* - client_info: client info object
|
|
10
|
+
* - state: OAuth2 request state
|
|
11
|
+
* - error: error sent back in hash
|
|
12
|
+
* - error: description
|
|
13
|
+
*/
|
|
14
|
+
export type ServerAuthorizationCodeResponse = {
|
|
15
|
+
// Success case
|
|
16
|
+
code?: string;
|
|
17
|
+
client_info?: string;
|
|
18
|
+
state?: string;
|
|
19
|
+
cloud_instance_name?: string;
|
|
20
|
+
cloud_instance_host_name?: string;
|
|
21
|
+
cloud_graph_host_name?: string;
|
|
22
|
+
msgraph_host?: string;
|
|
23
|
+
// Error case
|
|
24
|
+
error?: string;
|
|
25
|
+
error_description?: string;
|
|
26
|
+
suberror?: string;
|
|
27
|
+
timestamp?: string;
|
|
28
|
+
trace_id?: string;
|
|
29
|
+
correlation_id?: string;
|
|
30
|
+
claims?: string;
|
|
31
|
+
// Native Account ID
|
|
32
|
+
accountId?: string;
|
|
33
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthenticationScheme } from "../utils/Constants";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Deserialized response object from server authorization code request.
|
|
10
|
+
* - token_type: Indicates the token type value. Can be either Bearer or pop.
|
|
11
|
+
* - scope: The scopes that the access_token is valid for.
|
|
12
|
+
* - expires_in: How long the access token is valid (in seconds).
|
|
13
|
+
* - refresh_in: Duration afer which a token should be renewed, regardless of expiration.
|
|
14
|
+
* - ext_expires_in: How long the access token is valid (in seconds) if the server isn't responding.
|
|
15
|
+
* - access_token: The requested access token. The app can use this token to authenticate to the secured resource, such as a web API.
|
|
16
|
+
* - refresh_token: An OAuth 2.0 refresh token. The app can use this token acquire additional access tokens after the current access token expires.
|
|
17
|
+
* - id_token: A JSON Web Token (JWT). The app can decode the segments of this token to request information about the user who signed in.
|
|
18
|
+
* - key_id: A string that uniquely identifies a public key that the request is bound to.
|
|
19
|
+
*
|
|
20
|
+
* In case of error:
|
|
21
|
+
* - error: An error code string that can be used to classify types of errors that occur, and can be used to react to errors.
|
|
22
|
+
* - error_description: A specific error message that can help a developer identify the root cause of an authentication error.
|
|
23
|
+
* - error_codes: A list of STS-specific error codes that can help in diagnostics.
|
|
24
|
+
* - timestamp: The time at which the error occurred.
|
|
25
|
+
* - trace_id: A unique identifier for the request that can help in diagnostics.
|
|
26
|
+
* - correlation_id: A unique identifier for the request that can help in diagnostics across components.
|
|
27
|
+
* - status: the network request's response status
|
|
28
|
+
*/
|
|
29
|
+
export type ServerAuthorizationTokenResponse = {
|
|
30
|
+
status?: number;
|
|
31
|
+
// Success
|
|
32
|
+
token_type?: AuthenticationScheme;
|
|
33
|
+
scope?: string;
|
|
34
|
+
expires_in?: number;
|
|
35
|
+
refresh_in?: number;
|
|
36
|
+
ext_expires_in?: number;
|
|
37
|
+
access_token?: string;
|
|
38
|
+
refresh_token?: string;
|
|
39
|
+
id_token?: string;
|
|
40
|
+
client_info?: string;
|
|
41
|
+
foci?: string;
|
|
42
|
+
spa_code?: string;
|
|
43
|
+
spa_accountid?: string;
|
|
44
|
+
key_id?: string;
|
|
45
|
+
// Error
|
|
46
|
+
error?: string;
|
|
47
|
+
error_description?: string;
|
|
48
|
+
error_codes?: Array<string>;
|
|
49
|
+
suberror?: string;
|
|
50
|
+
timestamp?: string;
|
|
51
|
+
trace_id?: string;
|
|
52
|
+
correlation_id?: string;
|
|
53
|
+
claims?: string;
|
|
54
|
+
};
|