@azure/msal-common 16.0.0-alpha.0 → 16.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/AccountInfo.d.ts +3 -0
- package/dist/account/AccountInfo.d.ts.map +1 -1
- package/dist/account/AccountInfo.mjs +1 -1
- package/dist/account/AccountInfo.mjs.map +1 -1
- package/dist/account/AuthToken.d.ts +6 -0
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.mjs +21 -2
- 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 +5 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +1 -1
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/account/TokenClaims.d.ts +4 -0
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/account/TokenClaims.mjs +1 -1
- package/dist/account/TokenClaims.mjs.map +1 -1
- package/dist/authority/Authority.mjs +1 -1
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +1 -1
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +27 -24
- 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/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +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 +5 -5
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +8 -8
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts +2 -1
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/interface/ICacheManager.d.ts +5 -5
- package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
- package/dist/cache/utils/AccountEntityUtils.d.ts +0 -7
- package/dist/cache/utils/AccountEntityUtils.d.ts.map +1 -1
- package/dist/cache/utils/AccountEntityUtils.mjs +9 -29
- package/dist/cache/utils/AccountEntityUtils.mjs.map +1 -1
- package/dist/cache/utils/CacheHelpers.mjs +1 -1
- package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts +22 -3
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +51 -19
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts +16 -3
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +41 -18
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +16 -3
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +21 -4
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.mjs +1 -1
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/constants/AADServerParamKeys.mjs +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/JoseHeader.mjs +1 -1
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +1 -1
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/error/AuthError.d.ts +5 -0
- package/dist/error/AuthError.d.ts.map +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthError.mjs.map +1 -1
- package/dist/error/AuthErrorCodes.mjs +1 -1
- package/dist/error/CacheError.mjs +1 -1
- package/dist/error/CacheError.mjs.map +1 -1
- package/dist/error/CacheErrorCodes.mjs +1 -1
- package/dist/error/ClientAuthError.mjs +1 -1
- 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 +4 -3
- package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationError.mjs.map +1 -1
- package/dist/error/ClientConfigurationErrorCodes.d.ts +1 -0
- package/dist/error/ClientConfigurationErrorCodes.d.ts.map +1 -1
- package/dist/error/ClientConfigurationErrorCodes.mjs +4 -3
- package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs.map +1 -1
- package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
- package/dist/error/NetworkError.mjs +1 -1
- package/dist/error/NetworkError.mjs.map +1 -1
- package/dist/error/PlatformBrokerError.d.ts +16 -0
- package/dist/error/PlatformBrokerError.d.ts.map +1 -0
- package/dist/error/PlatformBrokerError.mjs +49 -0
- package/dist/error/PlatformBrokerError.mjs.map +1 -0
- package/dist/error/ServerError.mjs +1 -1
- package/dist/error/ServerError.mjs.map +1 -1
- package/dist/exports-common.d.ts +4 -2
- package/dist/exports-common.d.ts.map +1 -1
- package/dist/exports-node-only.d.ts +1 -0
- package/dist/exports-node-only.d.ts.map +1 -1
- package/dist/index-node.mjs +7 -4
- package/dist/index-node.mjs.map +1 -1
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts +24 -0
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.mjs +92 -4
- 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/RequestThumbprint.mjs +2 -2
- package/dist/network/RequestThumbprint.mjs.map +1 -1
- package/dist/network/ThrottlingUtils.mjs +1 -1
- package/dist/network/ThrottlingUtils.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.mjs +1 -1
- package/dist/protocol/Authorize.mjs.map +1 -1
- package/dist/protocol/Token.d.ts +40 -0
- package/dist/protocol/Token.d.ts.map +1 -0
- package/dist/protocol/Token.mjs +129 -0
- package/dist/protocol/Token.mjs.map +1 -0
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/BaseAuthRequest.d.ts +67 -22
- package/dist/request/BaseAuthRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +18 -12
- package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +48 -29
- package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/CommonEndSessionRequest.d.ts +21 -7
- package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
- package/dist/request/CommonRefreshTokenRequest.d.ts +12 -9
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/CommonSilentFlowRequest.d.ts +12 -13
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts +3 -3
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +6 -6
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/ScopeSet.mjs +1 -1
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/response/ResponseHandler.d.ts +1 -1
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +6 -5
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +2 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +4 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +30 -16
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +6 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvents.d.ts +1 -0
- package/dist/telemetry/performance/PerformanceEvents.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvents.mjs +3 -2
- package/dist/telemetry/performance/PerformanceEvents.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/url/UrlString.mjs +1 -1
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/ClientAssertionUtils.mjs +1 -1
- package/dist/utils/ClientAssertionUtils.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +5 -0
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +6 -2
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.mjs +1 -1
- package/dist/utils/FunctionWrappers.mjs.map +1 -1
- package/dist/utils/ProtocolUtils.d.ts +14 -35
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +56 -60
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StateTypes.d.ts +15 -0
- package/dist/utils/StateTypes.d.ts.map +1 -0
- package/dist/utils/StringUtils.mjs +1 -1
- package/dist/utils/StringUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/dist/utils/UrlUtils.mjs +1 -1
- package/dist/utils/UrlUtils.mjs.map +1 -1
- package/lib/index-browser.cjs +31 -17
- package/lib/index-browser.cjs.map +1 -1
- package/lib/{index-node-FrCFfFuh.js → index-node-Dwr2_mSO.js} +2437 -2242
- package/lib/index-node-Dwr2_mSO.js.map +1 -0
- package/lib/index-node.cjs +5 -3
- package/lib/index-node.cjs.map +1 -1
- package/lib/index.cjs +5 -3
- package/lib/index.cjs.map +1 -1
- package/lib/types/account/AccountInfo.d.ts +3 -0
- package/lib/types/account/AccountInfo.d.ts.map +1 -1
- package/lib/types/account/AuthToken.d.ts +6 -0
- package/lib/types/account/AuthToken.d.ts.map +1 -1
- package/lib/types/account/ClientInfo.d.ts +5 -1
- package/lib/types/account/ClientInfo.d.ts.map +1 -1
- package/lib/types/account/TokenClaims.d.ts +4 -0
- package/lib/types/account/TokenClaims.d.ts.map +1 -1
- package/lib/types/authority/AuthorityMetadata.d.ts.map +1 -1
- package/lib/types/cache/CacheManager.d.ts +5 -5
- package/lib/types/cache/CacheManager.d.ts.map +1 -1
- package/lib/types/cache/entities/AccountEntity.d.ts +2 -1
- package/lib/types/cache/entities/AccountEntity.d.ts.map +1 -1
- package/lib/types/cache/interface/ICacheManager.d.ts +5 -5
- package/lib/types/cache/interface/ICacheManager.d.ts.map +1 -1
- package/lib/types/cache/utils/AccountEntityUtils.d.ts +0 -7
- package/lib/types/cache/utils/AccountEntityUtils.d.ts.map +1 -1
- package/lib/types/client/AuthorizationCodeClient.d.ts +22 -3
- package/lib/types/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/lib/types/client/RefreshTokenClient.d.ts +16 -3
- package/lib/types/client/RefreshTokenClient.d.ts.map +1 -1
- package/lib/types/client/SilentFlowClient.d.ts +16 -3
- package/lib/types/client/SilentFlowClient.d.ts.map +1 -1
- package/lib/types/error/AuthError.d.ts +5 -0
- package/lib/types/error/AuthError.d.ts.map +1 -1
- package/lib/types/error/ClientAuthErrorCodes.d.ts +1 -0
- package/lib/types/error/ClientAuthErrorCodes.d.ts.map +1 -1
- package/lib/types/error/ClientConfigurationErrorCodes.d.ts +1 -0
- package/lib/types/error/ClientConfigurationErrorCodes.d.ts.map +1 -1
- package/lib/types/error/PlatformBrokerError.d.ts +16 -0
- package/lib/types/error/PlatformBrokerError.d.ts.map +1 -0
- package/lib/types/exports-common.d.ts +4 -2
- package/lib/types/exports-common.d.ts.map +1 -1
- package/lib/types/exports-node-only.d.ts +1 -0
- package/lib/types/exports-node-only.d.ts.map +1 -1
- package/lib/types/logger/Logger.d.ts +24 -0
- package/lib/types/logger/Logger.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/lib/types/packageMetadata.d.ts.map +1 -1
- package/lib/types/protocol/Token.d.ts +40 -0
- package/lib/types/protocol/Token.d.ts.map +1 -0
- package/lib/types/request/BaseAuthRequest.d.ts +67 -22
- package/lib/types/request/BaseAuthRequest.d.ts.map +1 -1
- package/lib/types/request/CommonAuthorizationCodeRequest.d.ts +18 -12
- package/lib/types/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
- package/lib/types/request/CommonAuthorizationUrlRequest.d.ts +48 -29
- package/lib/types/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
- package/lib/types/request/CommonEndSessionRequest.d.ts +21 -7
- package/lib/types/request/CommonEndSessionRequest.d.ts.map +1 -1
- package/lib/types/request/CommonRefreshTokenRequest.d.ts +12 -9
- package/lib/types/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/lib/types/request/CommonSilentFlowRequest.d.ts +12 -13
- package/lib/types/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/lib/types/request/RequestParameterBuilder.d.ts +3 -3
- package/lib/types/request/RequestParameterBuilder.d.ts.map +1 -1
- package/lib/types/response/ResponseHandler.d.ts +1 -1
- package/lib/types/response/ResponseHandler.d.ts.map +1 -1
- package/lib/types/telemetry/performance/IPerformanceClient.d.ts +2 -1
- package/lib/types/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/lib/types/telemetry/performance/PerformanceClient.d.ts +4 -1
- package/lib/types/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/lib/types/telemetry/performance/PerformanceEvent.d.ts +6 -1
- package/lib/types/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/lib/types/telemetry/performance/PerformanceEvents.d.ts +1 -0
- package/lib/types/telemetry/performance/PerformanceEvents.d.ts.map +1 -1
- package/lib/types/utils/Constants.d.ts +5 -0
- package/lib/types/utils/Constants.d.ts.map +1 -1
- package/lib/types/utils/ProtocolUtils.d.ts +14 -35
- package/lib/types/utils/ProtocolUtils.d.ts.map +1 -1
- package/lib/types/utils/StateTypes.d.ts +15 -0
- package/lib/types/utils/StateTypes.d.ts.map +1 -0
- package/package.json +123 -120
- package/src/account/AccountInfo.ts +5 -0
- package/src/account/AuthToken.ts +22 -0
- package/src/account/ClientInfo.ts +5 -1
- package/src/account/TokenClaims.ts +4 -0
- package/src/authority/AuthorityMetadata.ts +33 -35
- package/src/cache/CacheManager.ts +19 -10
- package/src/cache/entities/AccountEntity.ts +2 -1
- package/src/cache/interface/ICacheManager.ts +12 -4
- package/src/cache/utils/AccountEntityUtils.ts +8 -37
- package/src/client/AuthorizationCodeClient.ts +128 -19
- package/src/client/RefreshTokenClient.ts +101 -29
- package/src/client/SilentFlowClient.ts +63 -5
- package/src/error/AuthError.ts +6 -0
- package/src/error/ClientAuthErrorCodes.ts +1 -0
- package/src/error/ClientConfigurationErrorCodes.ts +1 -0
- package/src/error/PlatformBrokerError.ts +67 -0
- package/src/exports-common.ts +5 -6
- package/src/exports-node-only.ts +4 -0
- package/src/logger/Logger.ts +150 -2
- package/src/network/RequestThumbprint.ts +1 -1
- package/src/packageMetadata.ts +1 -1
- package/src/protocol/Token.ts +230 -0
- package/src/request/BaseAuthRequest.ts +67 -22
- package/src/request/CommonAuthorizationCodeRequest.ts +18 -12
- package/src/request/CommonAuthorizationUrlRequest.ts +48 -29
- package/src/request/CommonEndSessionRequest.ts +21 -7
- package/src/request/CommonRefreshTokenRequest.ts +12 -9
- package/src/request/CommonSilentFlowRequest.ts +12 -13
- package/src/request/RequestParameterBuilder.ts +5 -5
- package/src/response/ResponseHandler.ts +14 -3
- package/src/telemetry/performance/IPerformanceClient.ts +3 -1
- package/src/telemetry/performance/PerformanceClient.ts +39 -45
- package/src/telemetry/performance/PerformanceEvent.ts +10 -1
- package/src/telemetry/performance/PerformanceEvents.ts +1 -0
- package/src/utils/Constants.ts +6 -0
- package/src/utils/ProtocolUtils.ts +66 -92
- package/src/utils/StateTypes.ts +20 -0
- package/dist/client/BaseClient.d.ts +0 -59
- package/dist/client/BaseClient.d.ts.map +0 -1
- package/dist/client/BaseClient.mjs +0 -162
- package/dist/client/BaseClient.mjs.map +0 -1
- package/dist/index-browser.mjs +0 -75
- package/dist/index-browser.mjs.map +0 -1
- package/lib/index-node-FrCFfFuh.js.map +0 -1
- package/lib/types/client/BaseClient.d.ts +0 -59
- package/lib/types/client/BaseClient.d.ts.map +0 -1
- package/src/client/BaseClient.ts +0 -308
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
+
buildClientConfiguration,
|
|
7
8
|
ClientConfiguration,
|
|
9
|
+
CommonClientConfiguration,
|
|
8
10
|
isOidcProtocolMode,
|
|
9
11
|
} from "../config/ClientConfiguration.js";
|
|
10
|
-
import { BaseClient } from "./BaseClient.js";
|
|
11
12
|
import { CommonRefreshTokenRequest } from "../request/CommonRefreshTokenRequest.js";
|
|
12
13
|
import { Authority } from "../authority/Authority.js";
|
|
13
14
|
import { ServerAuthorizationTokenResponse } from "../response/ServerAuthorizationTokenResponse.js";
|
|
@@ -45,6 +46,17 @@ import { invoke, invokeAsync } from "../utils/FunctionWrappers.js";
|
|
|
45
46
|
import { ClientAssertion } from "../account/ClientCredentials.js";
|
|
46
47
|
import { getClientAssertion } from "../utils/ClientAssertionUtils.js";
|
|
47
48
|
import { getRequestThumbprint } from "../network/RequestThumbprint.js";
|
|
49
|
+
import {
|
|
50
|
+
createTokenQueryParameters,
|
|
51
|
+
createTokenRequestHeaders,
|
|
52
|
+
executePostToTokenEndpoint,
|
|
53
|
+
} from "../protocol/Token.js";
|
|
54
|
+
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager.js";
|
|
55
|
+
import { INetworkModule } from "../network/INetworkModule.js";
|
|
56
|
+
import { CacheManager } from "../cache/CacheManager.js";
|
|
57
|
+
import { ICrypto } from "../crypto/ICrypto.js";
|
|
58
|
+
import { Logger } from "../logger/Logger.js";
|
|
59
|
+
import { version, name } from "../packageMetadata.js";
|
|
48
60
|
|
|
49
61
|
const DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS = 300; // 5 Minutes
|
|
50
62
|
|
|
@@ -52,12 +64,58 @@ const DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS = 300; // 5 Minutes
|
|
|
52
64
|
* OAuth2.0 refresh token client
|
|
53
65
|
* @internal
|
|
54
66
|
*/
|
|
55
|
-
export class RefreshTokenClient
|
|
67
|
+
export class RefreshTokenClient {
|
|
68
|
+
// Logger object
|
|
69
|
+
public logger: Logger;
|
|
70
|
+
|
|
71
|
+
// Application config
|
|
72
|
+
protected config: CommonClientConfiguration;
|
|
73
|
+
|
|
74
|
+
// Crypto Interface
|
|
75
|
+
protected cryptoUtils: ICrypto;
|
|
76
|
+
|
|
77
|
+
// Storage Interface
|
|
78
|
+
protected cacheManager: CacheManager;
|
|
79
|
+
|
|
80
|
+
// Network Interface
|
|
81
|
+
protected networkClient: INetworkModule;
|
|
82
|
+
|
|
83
|
+
// Server Telemetry Manager
|
|
84
|
+
protected serverTelemetryManager: ServerTelemetryManager | null;
|
|
85
|
+
|
|
86
|
+
// Default authority object
|
|
87
|
+
public authority: Authority;
|
|
88
|
+
|
|
89
|
+
// Performance telemetry client
|
|
90
|
+
protected performanceClient: IPerformanceClient;
|
|
91
|
+
|
|
56
92
|
constructor(
|
|
57
93
|
configuration: ClientConfiguration,
|
|
58
94
|
performanceClient: IPerformanceClient
|
|
59
95
|
) {
|
|
60
|
-
|
|
96
|
+
// Set the configuration
|
|
97
|
+
this.config = buildClientConfiguration(configuration);
|
|
98
|
+
|
|
99
|
+
// Initialize the logger
|
|
100
|
+
this.logger = new Logger(this.config.loggerOptions, name, version);
|
|
101
|
+
|
|
102
|
+
// Initialize crypto
|
|
103
|
+
this.cryptoUtils = this.config.cryptoInterface;
|
|
104
|
+
|
|
105
|
+
// Initialize storage interface
|
|
106
|
+
this.cacheManager = this.config.storageInterface;
|
|
107
|
+
|
|
108
|
+
// Set the network interface
|
|
109
|
+
this.networkClient = this.config.networkInterface;
|
|
110
|
+
|
|
111
|
+
// Set TelemetryManager
|
|
112
|
+
this.serverTelemetryManager = this.config.serverTelemetryManager;
|
|
113
|
+
|
|
114
|
+
// set Authority
|
|
115
|
+
this.authority = this.config.authOptions.authority;
|
|
116
|
+
|
|
117
|
+
// set performance telemetry client
|
|
118
|
+
this.performanceClient = performanceClient;
|
|
61
119
|
}
|
|
62
120
|
public async acquireToken(
|
|
63
121
|
request: CommonRefreshTokenRequest
|
|
@@ -201,21 +259,23 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
201
259
|
);
|
|
202
260
|
}
|
|
203
261
|
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
TimeUtils.isTokenExpired(
|
|
207
|
-
refreshToken.expiresOn,
|
|
262
|
+
if (refreshToken.expiresOn) {
|
|
263
|
+
const offset =
|
|
208
264
|
request.refreshTokenExpirationOffsetSeconds ||
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
) {
|
|
265
|
+
DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS;
|
|
212
266
|
this.performanceClient?.addFields(
|
|
213
|
-
{
|
|
267
|
+
{
|
|
268
|
+
cacheRtExpiresOnSeconds: Number(refreshToken.expiresOn),
|
|
269
|
+
rtOffsetSeconds: offset,
|
|
270
|
+
},
|
|
214
271
|
request.correlationId
|
|
215
272
|
);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
273
|
+
|
|
274
|
+
if (TimeUtils.isTokenExpired(refreshToken.expiresOn, offset)) {
|
|
275
|
+
throw createInteractionRequiredAuthError(
|
|
276
|
+
InteractionRequiredAuthErrorCodes.refreshTokenExpired
|
|
277
|
+
);
|
|
278
|
+
}
|
|
219
279
|
}
|
|
220
280
|
// attach cached RT size to the current measurement
|
|
221
281
|
|
|
@@ -241,11 +301,6 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
241
301
|
)(refreshTokenRequest);
|
|
242
302
|
} catch (e) {
|
|
243
303
|
if (e instanceof InteractionRequiredAuthError) {
|
|
244
|
-
this.performanceClient?.addFields(
|
|
245
|
-
{ rtExpiresOnMs: Number(refreshToken.expiresOn) },
|
|
246
|
-
request.correlationId
|
|
247
|
-
);
|
|
248
|
-
|
|
249
304
|
if (e.subError === InteractionRequiredAuthErrorCodes.badToken) {
|
|
250
305
|
// Remove bad refresh token from cache
|
|
251
306
|
this.logger.verbose(
|
|
@@ -274,7 +329,12 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
274
329
|
request: CommonRefreshTokenRequest,
|
|
275
330
|
authority: Authority
|
|
276
331
|
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
|
277
|
-
const queryParametersString =
|
|
332
|
+
const queryParametersString = createTokenQueryParameters(
|
|
333
|
+
request,
|
|
334
|
+
this.config.authOptions.clientId,
|
|
335
|
+
this.config.authOptions.redirectUri,
|
|
336
|
+
this.performanceClient
|
|
337
|
+
);
|
|
278
338
|
const endpoint = UrlString.appendQueryString(
|
|
279
339
|
authority.tokenEndpoint,
|
|
280
340
|
queryParametersString
|
|
@@ -287,7 +347,9 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
287
347
|
this.performanceClient,
|
|
288
348
|
request.correlationId
|
|
289
349
|
)(request);
|
|
290
|
-
const headers: Record<string, string> =
|
|
350
|
+
const headers: Record<string, string> = createTokenRequestHeaders(
|
|
351
|
+
this.logger,
|
|
352
|
+
this.config.systemOptions.preventCorsPreflight,
|
|
291
353
|
request.ccsCredential
|
|
292
354
|
);
|
|
293
355
|
|
|
@@ -297,12 +359,23 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
297
359
|
);
|
|
298
360
|
|
|
299
361
|
return invokeAsync(
|
|
300
|
-
|
|
362
|
+
executePostToTokenEndpoint,
|
|
301
363
|
PerformanceEvents.RefreshTokenClientExecutePostToTokenEndpoint,
|
|
302
364
|
this.logger,
|
|
303
365
|
this.performanceClient,
|
|
304
366
|
request.correlationId
|
|
305
|
-
)(
|
|
367
|
+
)(
|
|
368
|
+
endpoint,
|
|
369
|
+
requestBody,
|
|
370
|
+
headers,
|
|
371
|
+
thumbprint,
|
|
372
|
+
request.correlationId,
|
|
373
|
+
this.cacheManager,
|
|
374
|
+
this.networkClient,
|
|
375
|
+
this.logger,
|
|
376
|
+
this.performanceClient,
|
|
377
|
+
this.serverTelemetryManager
|
|
378
|
+
);
|
|
306
379
|
}
|
|
307
380
|
|
|
308
381
|
/**
|
|
@@ -317,7 +390,7 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
317
390
|
RequestParameterBuilder.addClientId(
|
|
318
391
|
parameters,
|
|
319
392
|
request.embeddedClientId ||
|
|
320
|
-
request.
|
|
393
|
+
request.extraParameters?.[AADServerParamKeys.CLIENT_ID] ||
|
|
321
394
|
this.config.authOptions.clientId
|
|
322
395
|
);
|
|
323
396
|
|
|
@@ -476,11 +549,10 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
476
549
|
);
|
|
477
550
|
}
|
|
478
551
|
|
|
479
|
-
if (request.
|
|
480
|
-
RequestParameterBuilder.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
);
|
|
552
|
+
if (request.extraParameters) {
|
|
553
|
+
RequestParameterBuilder.addExtraParameters(parameters, {
|
|
554
|
+
...request.extraParameters,
|
|
555
|
+
});
|
|
484
556
|
}
|
|
485
557
|
|
|
486
558
|
RequestParameterBuilder.instrumentBrokerParams(
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
buildClientConfiguration,
|
|
8
|
+
ClientConfiguration,
|
|
9
|
+
CommonClientConfiguration,
|
|
10
|
+
} from "../config/ClientConfiguration.js";
|
|
8
11
|
import { CommonSilentFlowRequest } from "../request/CommonSilentFlowRequest.js";
|
|
9
12
|
import { AuthenticationResult } from "../response/AuthenticationResult.js";
|
|
10
13
|
import * as TimeUtils from "../utils/TimeUtils.js";
|
|
@@ -21,15 +24,70 @@ import { checkMaxAge, extractTokenClaims } from "../account/AuthToken.js";
|
|
|
21
24
|
import { TokenClaims } from "../account/TokenClaims.js";
|
|
22
25
|
import * as PerformanceEvents from "../telemetry/performance/PerformanceEvents.js";
|
|
23
26
|
import { invokeAsync } from "../utils/FunctionWrappers.js";
|
|
24
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
Authority,
|
|
29
|
+
getTenantFromAuthorityString,
|
|
30
|
+
} from "../authority/Authority.js";
|
|
31
|
+
import { Logger } from "../logger/Logger.js";
|
|
32
|
+
import { ICrypto } from "../crypto/ICrypto.js";
|
|
33
|
+
import { CacheManager } from "../cache/CacheManager.js";
|
|
34
|
+
import { INetworkModule } from "../network/INetworkModule.js";
|
|
35
|
+
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager.js";
|
|
36
|
+
import { version, name } from "../packageMetadata.js";
|
|
25
37
|
|
|
26
38
|
/** @internal */
|
|
27
|
-
export class SilentFlowClient
|
|
39
|
+
export class SilentFlowClient {
|
|
40
|
+
// Logger object
|
|
41
|
+
public logger: Logger;
|
|
42
|
+
|
|
43
|
+
// Application config
|
|
44
|
+
protected config: CommonClientConfiguration;
|
|
45
|
+
|
|
46
|
+
// Crypto Interface
|
|
47
|
+
protected cryptoUtils: ICrypto;
|
|
48
|
+
|
|
49
|
+
// Storage Interface
|
|
50
|
+
protected cacheManager: CacheManager;
|
|
51
|
+
|
|
52
|
+
// Network Interface
|
|
53
|
+
protected networkClient: INetworkModule;
|
|
54
|
+
|
|
55
|
+
// Server Telemetry Manager
|
|
56
|
+
protected serverTelemetryManager: ServerTelemetryManager | null;
|
|
57
|
+
|
|
58
|
+
// Default authority object
|
|
59
|
+
public authority: Authority;
|
|
60
|
+
|
|
61
|
+
// Performance telemetry client
|
|
62
|
+
protected performanceClient: IPerformanceClient;
|
|
63
|
+
|
|
28
64
|
constructor(
|
|
29
65
|
configuration: ClientConfiguration,
|
|
30
66
|
performanceClient: IPerformanceClient
|
|
31
67
|
) {
|
|
32
|
-
|
|
68
|
+
// Set the configuration
|
|
69
|
+
this.config = buildClientConfiguration(configuration);
|
|
70
|
+
|
|
71
|
+
// Initialize the logger
|
|
72
|
+
this.logger = new Logger(this.config.loggerOptions, name, version);
|
|
73
|
+
|
|
74
|
+
// Initialize crypto
|
|
75
|
+
this.cryptoUtils = this.config.cryptoInterface;
|
|
76
|
+
|
|
77
|
+
// Initialize storage interface
|
|
78
|
+
this.cacheManager = this.config.storageInterface;
|
|
79
|
+
|
|
80
|
+
// Set the network interface
|
|
81
|
+
this.networkClient = this.config.networkInterface;
|
|
82
|
+
|
|
83
|
+
// Set TelemetryManager
|
|
84
|
+
this.serverTelemetryManager = this.config.serverTelemetryManager;
|
|
85
|
+
|
|
86
|
+
// set Authority
|
|
87
|
+
this.authority = this.config.authOptions.authority;
|
|
88
|
+
|
|
89
|
+
// set performance telemetry client
|
|
90
|
+
this.performanceClient = performanceClient;
|
|
33
91
|
}
|
|
34
92
|
|
|
35
93
|
/**
|
package/src/error/AuthError.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as AuthErrorCodes from "./AuthErrorCodes.js";
|
|
7
|
+
import type { PlatformBrokerError } from "./PlatformBrokerError.js";
|
|
7
8
|
export { AuthErrorCodes };
|
|
8
9
|
|
|
9
10
|
export function getDefaultErrorMessage(code: string): string {
|
|
@@ -34,6 +35,11 @@ export class AuthError extends Error {
|
|
|
34
35
|
*/
|
|
35
36
|
correlationId: string;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Default PlatformBrokerError from MsalNodeRuntime when broker is enabled
|
|
40
|
+
*/
|
|
41
|
+
platformBrokerError?: PlatformBrokerError;
|
|
42
|
+
|
|
37
43
|
constructor(errorCode?: string, errorMessage?: string, suberror?: string) {
|
|
38
44
|
const message =
|
|
39
45
|
errorMessage ||
|
|
@@ -42,3 +42,4 @@ export const noNetworkConnectivity = "no_network_connectivity";
|
|
|
42
42
|
export const userCanceled = "user_canceled";
|
|
43
43
|
export const methodNotImplemented = "method_not_implemented";
|
|
44
44
|
export const nestedAppAuthBridgeDisabled = "nested_app_auth_bridge_disabled";
|
|
45
|
+
export const platformBrokerError = "platform_broker_error";
|
|
@@ -25,3 +25,4 @@ export const invalidAuthenticationHeader = "invalid_authentication_header";
|
|
|
25
25
|
export const cannotSetOIDCOptions = "cannot_set_OIDCOptions";
|
|
26
26
|
export const cannotAllowPlatformBroker = "cannot_allow_platform_broker";
|
|
27
27
|
export const authorityMismatch = "authority_mismatch";
|
|
28
|
+
export const invalidRequestMethodForEAR = "invalid_request_method_for_EAR";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthError } from "./AuthError.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a numeric tag from MSAL Runtime to a 5-character string representation.
|
|
10
|
+
* Tags are encoded as 30-bit values (6 bits per character) using a custom symbol space.
|
|
11
|
+
* @param tag - The numeric tag to convert
|
|
12
|
+
* @returns The string representation of the tag
|
|
13
|
+
*/
|
|
14
|
+
function tagToString(tag: number): string {
|
|
15
|
+
if (tag === 0) {
|
|
16
|
+
return "UNTAG";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const tagSymbolSpace =
|
|
20
|
+
"abcdefghijklmnopqrstuvwxyz0123456789****************************";
|
|
21
|
+
let tagBuffer = "*****";
|
|
22
|
+
|
|
23
|
+
const chars = [
|
|
24
|
+
tagSymbolSpace[(tag >> 24) & 0x3f],
|
|
25
|
+
tagSymbolSpace[(tag >> 18) & 0x3f],
|
|
26
|
+
tagSymbolSpace[(tag >> 12) & 0x3f],
|
|
27
|
+
tagSymbolSpace[(tag >> 6) & 0x3f],
|
|
28
|
+
tagSymbolSpace[(tag >> 0) & 0x3f],
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
tagBuffer = chars.join("");
|
|
32
|
+
|
|
33
|
+
return tagBuffer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Error class for MSAL Runtime errors that preserves detailed broker information
|
|
38
|
+
*/
|
|
39
|
+
export class PlatformBrokerError extends AuthError {
|
|
40
|
+
/**
|
|
41
|
+
* Numeric error code from MSAL Runtime
|
|
42
|
+
*/
|
|
43
|
+
public statusCode: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Error tag from MSAL Runtime
|
|
47
|
+
*/
|
|
48
|
+
public tag: string;
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
errorStatus: string,
|
|
52
|
+
errorContext: string,
|
|
53
|
+
errorCode: number,
|
|
54
|
+
errorTag: number
|
|
55
|
+
) {
|
|
56
|
+
const tagString = tagToString(errorTag);
|
|
57
|
+
const enhancedErrorContext = errorContext
|
|
58
|
+
? `${errorContext} (Error Code: ${errorCode}, Tag: ${tagString})`
|
|
59
|
+
: `(Error Code: ${errorCode}, Tag: ${tagString})`;
|
|
60
|
+
|
|
61
|
+
super(errorStatus, enhancedErrorContext);
|
|
62
|
+
this.name = "PlatformBrokerError";
|
|
63
|
+
this.statusCode = errorCode;
|
|
64
|
+
this.tag = tagString;
|
|
65
|
+
Object.setPrototypeOf(this, PlatformBrokerError.prototype);
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/exports-common.ts
CHANGED
|
@@ -22,7 +22,6 @@ export { AccountEntityUtils };
|
|
|
22
22
|
export { AuthorizationCodeClient } from "./client/AuthorizationCodeClient.js";
|
|
23
23
|
export { RefreshTokenClient } from "./client/RefreshTokenClient.js";
|
|
24
24
|
export { SilentFlowClient } from "./client/SilentFlowClient.js";
|
|
25
|
-
export { BaseClient } from "./client/BaseClient.js";
|
|
26
25
|
export {
|
|
27
26
|
AuthOptions,
|
|
28
27
|
SystemOptions,
|
|
@@ -108,6 +107,8 @@ export {
|
|
|
108
107
|
} from "./crypto/ICrypto.js";
|
|
109
108
|
|
|
110
109
|
export * as AuthorizeProtocol from "./protocol/Authorize.js";
|
|
110
|
+
export * as TokenProtocol from "./protocol/Token.js";
|
|
111
|
+
|
|
111
112
|
export { BaseAuthRequest } from "./request/BaseAuthRequest.js";
|
|
112
113
|
export { CommonAuthorizationUrlRequest } from "./request/CommonAuthorizationUrlRequest.js";
|
|
113
114
|
export { CommonAuthorizationCodeRequest } from "./request/CommonAuthorizationCodeRequest.js";
|
|
@@ -139,6 +140,7 @@ export {
|
|
|
139
140
|
AuthErrorCodes,
|
|
140
141
|
createAuthError,
|
|
141
142
|
} from "./error/AuthError.js";
|
|
143
|
+
export { PlatformBrokerError } from "./error/PlatformBrokerError.js";
|
|
142
144
|
export { ServerError } from "./error/ServerError.js";
|
|
143
145
|
export { NetworkError, createNetworkError } from "./error/NetworkError.js";
|
|
144
146
|
export {
|
|
@@ -160,11 +162,8 @@ export * as Constants from "./utils/Constants.js";
|
|
|
160
162
|
|
|
161
163
|
export { StringUtils } from "./utils/StringUtils.js";
|
|
162
164
|
export { StringDict } from "./utils/MsalTypes.js";
|
|
163
|
-
export {
|
|
164
|
-
|
|
165
|
-
RequestStateObject,
|
|
166
|
-
LibraryStateObject,
|
|
167
|
-
} from "./utils/ProtocolUtils.js";
|
|
165
|
+
export { RequestStateObject, LibraryStateObject } from "./utils/StateTypes.js";
|
|
166
|
+
export * as ProtocolUtils from "./utils/ProtocolUtils.js";
|
|
168
167
|
export * from "./utils/FunctionWrappers.js";
|
|
169
168
|
export { ServerTelemetryManager } from "./telemetry/server/ServerTelemetryManager.js";
|
|
170
169
|
export { ServerTelemetryRequest } from "./telemetry/server/ServerTelemetryRequest.js";
|
package/src/exports-node-only.ts
CHANGED
|
@@ -30,3 +30,7 @@ export {
|
|
|
30
30
|
export { getClientAssertion } from "./utils/ClientAssertionUtils.js";
|
|
31
31
|
export { IGuidGenerator } from "./crypto/IGuidGenerator.js";
|
|
32
32
|
export { StubPerformanceClient } from "./telemetry/performance/StubPerformanceClient.js";
|
|
33
|
+
export {
|
|
34
|
+
buildClientConfiguration,
|
|
35
|
+
CommonClientConfiguration,
|
|
36
|
+
} from "./config/ClientConfiguration.js";
|
package/src/logger/Logger.ts
CHANGED
|
@@ -33,6 +33,141 @@ export interface ILoggerCallback {
|
|
|
33
33
|
(level: LogLevel, message: string, containsPii: boolean): void;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Represents a single logged message with metadata
|
|
38
|
+
*/
|
|
39
|
+
export interface LoggedMessage {
|
|
40
|
+
hash: string;
|
|
41
|
+
level: LogLevel;
|
|
42
|
+
containsPii: boolean;
|
|
43
|
+
milliseconds: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* LRU cache node for correlation ID management
|
|
48
|
+
*/
|
|
49
|
+
interface CorrelationLogData {
|
|
50
|
+
logs: LoggedMessage[];
|
|
51
|
+
firstEventTime: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Shared cache state for better minification - using Map's insertion order for LRU
|
|
55
|
+
const CACHE_CAPACITY = 50;
|
|
56
|
+
const MAX_LOGS_PER_CORRELATION = 500;
|
|
57
|
+
const correlationCache = new Map<string, CorrelationLogData>();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Mark correlation ID as recently used by moving it to end of Map
|
|
61
|
+
* @param correlationId
|
|
62
|
+
* @param {CorrelationLogData} data
|
|
63
|
+
*/
|
|
64
|
+
function markAsRecentlyUsed(
|
|
65
|
+
correlationId: string,
|
|
66
|
+
data: CorrelationLogData
|
|
67
|
+
): void {
|
|
68
|
+
correlationCache.delete(correlationId);
|
|
69
|
+
correlationCache.set(correlationId, data);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Add log message to cache for specific correlation ID
|
|
74
|
+
* @param correlationId
|
|
75
|
+
* @param {LoggedMessage} loggedMessage
|
|
76
|
+
*/
|
|
77
|
+
function addLogToCache(
|
|
78
|
+
correlationId: string,
|
|
79
|
+
loggedMessage: LoggedMessage
|
|
80
|
+
): void {
|
|
81
|
+
const currentTime = Date.now();
|
|
82
|
+
|
|
83
|
+
let data = correlationCache.get(correlationId);
|
|
84
|
+
|
|
85
|
+
if (data) {
|
|
86
|
+
// Mark as recently used
|
|
87
|
+
markAsRecentlyUsed(correlationId, data);
|
|
88
|
+
} else {
|
|
89
|
+
// Create new entry
|
|
90
|
+
data = { logs: [], firstEventTime: currentTime };
|
|
91
|
+
correlationCache.set(correlationId, data);
|
|
92
|
+
|
|
93
|
+
// Remove LRU (first entry) if capacity exceeded
|
|
94
|
+
if (correlationCache.size > CACHE_CAPACITY) {
|
|
95
|
+
const firstKey = correlationCache.keys().next().value;
|
|
96
|
+
if (firstKey) {
|
|
97
|
+
correlationCache.delete(firstKey);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Add log to the data, maintaining max logs per correlation
|
|
103
|
+
data.logs.push({
|
|
104
|
+
...loggedMessage,
|
|
105
|
+
milliseconds: currentTime - data.firstEventTime,
|
|
106
|
+
});
|
|
107
|
+
if (data.logs.length > MAX_LOGS_PER_CORRELATION) {
|
|
108
|
+
data.logs.shift(); // Remove oldest log
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get all logs for specific correlation ID
|
|
114
|
+
* @param correlationId
|
|
115
|
+
*/
|
|
116
|
+
export function getLogsFromCache(correlationId: string): LoggedMessage[] {
|
|
117
|
+
const data = correlationCache.get(correlationId);
|
|
118
|
+
if (data) {
|
|
119
|
+
markAsRecentlyUsed(correlationId, data);
|
|
120
|
+
return [...data.logs]; // Return copy
|
|
121
|
+
}
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get logs for correlation ID and flush them from cache
|
|
127
|
+
* Attaches logs with empty correlation id to the requested correlation logs
|
|
128
|
+
* @param correlationId
|
|
129
|
+
*/
|
|
130
|
+
export function getAndFlushLogsFromCache(
|
|
131
|
+
correlationId: string
|
|
132
|
+
): LoggedMessage[] {
|
|
133
|
+
const res: LoggedMessage[] = [];
|
|
134
|
+
for (const id of ["", correlationId]) {
|
|
135
|
+
const data = correlationCache.get(id);
|
|
136
|
+
res.push(...(data?.logs ?? []));
|
|
137
|
+
correlationCache.delete(id); // Remove the correlation ID completely from cache
|
|
138
|
+
}
|
|
139
|
+
return res;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get all correlation IDs that have logs
|
|
144
|
+
*/
|
|
145
|
+
export function getCachedCorrelationIds(): string[] {
|
|
146
|
+
return Array.from(correlationCache.keys());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a string is already a hashed logging string (6 alphanumeric characters)
|
|
151
|
+
*/
|
|
152
|
+
function isHashedString(str: string): boolean {
|
|
153
|
+
if (str.length !== 6) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < str.length; i++) {
|
|
158
|
+
const char = str[i];
|
|
159
|
+
const isAlphaNumeric =
|
|
160
|
+
(char >= "a" && char <= "z") ||
|
|
161
|
+
(char >= "A" && char <= "Z") ||
|
|
162
|
+
(char >= "0" && char <= "9");
|
|
163
|
+
if (!isAlphaNumeric) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
|
|
36
171
|
/**
|
|
37
172
|
* Class which facilitates logging of messages to a specific place.
|
|
38
173
|
*/
|
|
@@ -105,6 +240,19 @@ export class Logger {
|
|
|
105
240
|
logMessage: string,
|
|
106
241
|
options: LoggerMessageOptions
|
|
107
242
|
): void {
|
|
243
|
+
const correlationId = options.correlationId;
|
|
244
|
+
const isHashedInput = isHashedString(logMessage);
|
|
245
|
+
|
|
246
|
+
if (isHashedInput) {
|
|
247
|
+
const loggedMessage: LoggedMessage = {
|
|
248
|
+
hash: logMessage,
|
|
249
|
+
level: options.logLevel,
|
|
250
|
+
containsPii: options.containsPii || false,
|
|
251
|
+
milliseconds: 0, // Will be calculated in addLogToCache
|
|
252
|
+
};
|
|
253
|
+
addLogToCache(correlationId, loggedMessage);
|
|
254
|
+
}
|
|
255
|
+
|
|
108
256
|
if (
|
|
109
257
|
options.logLevel > this.level ||
|
|
110
258
|
(!this.piiLoggingEnabled && options.containsPii)
|
|
@@ -114,12 +262,12 @@ export class Logger {
|
|
|
114
262
|
const timestamp = new Date().toUTCString();
|
|
115
263
|
|
|
116
264
|
// Add correlationId to logs if set, correlationId provided on log messages take precedence
|
|
117
|
-
const logHeader = `[${timestamp}] : [${
|
|
265
|
+
const logHeader = `[${timestamp}] : [${correlationId}]`;
|
|
118
266
|
|
|
119
267
|
const log = `${logHeader} : ${this.packageName}@${
|
|
120
268
|
this.packageVersion
|
|
121
269
|
} : ${LogLevel[options.logLevel]} - ${logMessage}`;
|
|
122
|
-
|
|
270
|
+
|
|
123
271
|
this.executeCallback(
|
|
124
272
|
options.logLevel,
|
|
125
273
|
log,
|
|
@@ -42,6 +42,6 @@ export function getRequestThumbprint(
|
|
|
42
42
|
shrClaims: request.shrClaims,
|
|
43
43
|
sshKid: request.sshKid,
|
|
44
44
|
embeddedClientId:
|
|
45
|
-
request.embeddedClientId || request.
|
|
45
|
+
request.embeddedClientId || request.extraParameters?.clientId,
|
|
46
46
|
};
|
|
47
47
|
}
|
package/src/packageMetadata.ts
CHANGED