@azure/msal-browser 3.1.0 → 3.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/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +20 -19
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +14 -6
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +18 -8
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.d.ts +274 -0
- package/dist/app/PublicClientNext.d.ts.map +1 -0
- package/dist/app/PublicClientNext.mjs +362 -0
- package/dist/app/PublicClientNext.mjs.map +1 -0
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +13 -13
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +4 -15
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +13 -69
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.d.ts.map +1 -1
- package/dist/cache/BrowserStorage.mjs +7 -9
- package/dist/cache/BrowserStorage.mjs.map +1 -1
- package/dist/cache/CryptoKeyStore.mjs +1 -1
- package/dist/cache/DatabaseStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/config/Configuration.d.ts +4 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +8 -7
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.d.ts +2 -1
- package/dist/controllers/ControllerFactory.d.ts.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +26 -19
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +3 -2
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts +96 -0
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
- package/dist/controllers/NestedAppAuthController.mjs +345 -0
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
- package/dist/controllers/StandardController.d.ts +11 -6
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +67 -45
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
- package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
- package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
- package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
- package/dist/crypto/BrowserCrypto.d.ts +44 -49
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +77 -77
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +1 -7
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +18 -23
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +6 -21
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +45 -46
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.mjs +18 -2
- package/dist/encode/Base64Decode.mjs.map +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.d.ts +10 -1
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +12 -3
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +1 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +3 -2
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
- package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
- package/dist/error/NativeAuthError.d.ts +17 -45
- package/dist/error/NativeAuthError.d.ts.map +1 -1
- package/dist/error/NativeAuthError.mjs +47 -78
- package/dist/error/NativeAuthError.mjs.map +1 -1
- package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
- package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/NativeAuthErrorCodes.mjs +11 -0
- package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
- package/dist/error/NestedAppAuthError.d.ts +15 -0
- package/dist/error/NestedAppAuthError.d.ts.map +1 -0
- package/dist/error/NestedAppAuthError.mjs +30 -0
- package/dist/error/NestedAppAuthError.mjs.map +1 -0
- package/dist/event/EventHandler.d.ts.map +1 -1
- package/dist/event/EventHandler.mjs +3 -2
- package/dist/event/EventHandler.mjs.map +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +10 -11
- package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +26 -13
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +5 -4
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -7
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +7 -10
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +11 -18
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +27 -13
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +8 -18
- package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +16 -37
- package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
- package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +6 -9
- package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +3 -3
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts +13 -47
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +120 -156
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/naa/AccountInfo.d.ts +13 -0
- package/dist/naa/AccountInfo.d.ts.map +1 -0
- package/dist/naa/AccountRequests.d.ts +10 -0
- package/dist/naa/AccountRequests.d.ts.map +1 -0
- package/dist/naa/AuthBridge.d.ts +6 -0
- package/dist/naa/AuthBridge.d.ts.map +1 -0
- package/dist/naa/BridgeCapabilities.d.ts +4 -0
- package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
- package/dist/naa/BridgeError.d.ts +10 -0
- package/dist/naa/BridgeError.d.ts.map +1 -0
- package/dist/naa/BridgeError.mjs +12 -0
- package/dist/naa/BridgeError.mjs.map +1 -0
- package/dist/naa/BridgeProxy.d.ts +72 -0
- package/dist/naa/BridgeProxy.d.ts.map +1 -0
- package/dist/naa/BridgeProxy.mjs +154 -0
- package/dist/naa/BridgeProxy.mjs.map +1 -0
- package/dist/naa/BridgeRequest.d.ts +7 -0
- package/dist/naa/BridgeRequest.d.ts.map +1 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.d.ts +11 -0
- package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.mjs +20 -0
- package/dist/naa/BridgeStatusCode.mjs.map +1 -0
- package/dist/naa/IBridgeProxy.d.ts +11 -0
- package/dist/naa/IBridgeProxy.d.ts.map +1 -0
- package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
- package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
- package/dist/naa/TokenRequest.d.ts +22 -0
- package/dist/naa/TokenRequest.d.ts.map +1 -0
- package/dist/naa/TokenResponse.d.ts +17 -0
- package/dist/naa/TokenResponse.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/network/FetchClient.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
- package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +3 -3
- package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
- package/dist/utils/BrowserUtils.d.ts +54 -53
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +114 -102
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +61 -18042
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +13593 -12505
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +66 -65
- package/package.json +2 -2
- package/src/app/IPublicClientApplication.ts +55 -18
- package/src/app/PublicClientApplication.ts +19 -7
- package/src/app/PublicClientNext.ts +442 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/BrowserCacheManager.ts +29 -103
- package/src/cache/BrowserStorage.ts +9 -11
- package/src/config/Configuration.ts +21 -8
- package/src/controllers/ControllerFactory.ts +36 -25
- package/src/controllers/IController.ts +4 -1
- package/src/controllers/NestedAppAuthController.ts +525 -0
- package/src/controllers/StandardController.ts +163 -98
- package/src/controllers/UnknownOperatingContextController.ts +383 -0
- package/src/crypto/BrowserCrypto.ts +119 -103
- package/src/crypto/CryptoOps.ts +18 -27
- package/src/crypto/PkceGenerator.ts +93 -54
- package/src/encode/Base64Decode.ts +21 -1
- package/src/error/BrowserAuthError.ts +13 -1
- package/src/error/BrowserAuthErrorCodes.ts +1 -0
- package/src/error/BrowserConfigurationAuthError.ts +33 -102
- package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
- package/src/error/NativeAuthError.ts +73 -101
- package/src/error/NativeAuthErrorCodes.ts +7 -0
- package/src/error/NestedAppAuthError.ts +32 -0
- package/src/event/EventHandler.ts +2 -1
- package/src/index.ts +8 -10
- package/src/interaction_client/BaseInteractionClient.ts +14 -8
- package/src/interaction_client/NativeInteractionClient.ts +48 -14
- package/src/interaction_client/PopupClient.ts +2 -1
- package/src/interaction_client/RedirectClient.ts +1 -1
- package/src/interaction_client/SilentAuthCodeClient.ts +22 -19
- package/src/interaction_client/SilentCacheClient.ts +28 -28
- package/src/interaction_client/SilentIframeClient.ts +54 -18
- package/src/interaction_client/SilentRefreshClient.ts +26 -28
- package/src/interaction_client/StandardInteractionClient.ts +37 -68
- package/src/interaction_handler/InteractionHandler.ts +20 -15
- package/src/interaction_handler/RedirectHandler.ts +6 -2
- package/src/interaction_handler/SilentHandler.ts +177 -230
- package/src/naa/AccountInfo.ts +17 -0
- package/src/naa/AccountRequests.ts +16 -0
- package/src/naa/AuthBridge.ts +16 -0
- package/src/naa/BridgeCapabilities.ts +8 -0
- package/src/naa/BridgeError.ts +18 -0
- package/src/naa/BridgeProxy.ts +230 -0
- package/src/naa/BridgeRequest.ts +12 -0
- package/src/naa/BridgeRequestEnvelope.ts +46 -0
- package/src/naa/BridgeResponseEnvelope.ts +21 -0
- package/src/naa/BridgeStatusCode.ts +15 -0
- package/src/naa/IBridgeProxy.ts +25 -0
- package/src/naa/InitializeBridgeResponse.ts +12 -0
- package/src/naa/TokenRequest.ts +26 -0
- package/src/naa/TokenResponse.ts +61 -0
- package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
- package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +1 -1
- package/src/utils/BrowserProtocolUtils.ts +3 -2
- package/src/utils/BrowserUtils.ts +133 -125
- package/dist/crypto/ISubtleCrypto.d.ts +0 -10
- package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
- package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
- package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
- package/dist/utils/BrowserStringUtils.d.ts +0 -22
- package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
- package/dist/utils/BrowserStringUtils.mjs +0 -144
- package/dist/utils/BrowserStringUtils.mjs.map +0 -1
- package/src/crypto/ISubtleCrypto.ts +0 -30
- package/src/crypto/ModernBrowserCrypto.ts +0 -69
- package/src/utils/BrowserStringUtils.ts +0 -143
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CommonAuthorizationUrlRequest,
|
|
8
|
+
CommonSilentFlowRequest,
|
|
9
|
+
PerformanceCallbackFunction,
|
|
10
|
+
AccountInfo,
|
|
11
|
+
Logger,
|
|
12
|
+
ICrypto,
|
|
13
|
+
IPerformanceClient,
|
|
14
|
+
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
15
|
+
AccountFilter,
|
|
16
|
+
} from "@azure/msal-common";
|
|
17
|
+
import { ITokenCache } from "../cache/ITokenCache";
|
|
18
|
+
import { BrowserConfiguration } from "../config/Configuration";
|
|
19
|
+
import {
|
|
20
|
+
BrowserCacheManager,
|
|
21
|
+
DEFAULT_BROWSER_CACHE_MANAGER,
|
|
22
|
+
} from "../cache/BrowserCacheManager";
|
|
23
|
+
import { INavigationClient } from "../navigation/INavigationClient";
|
|
24
|
+
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
|
|
25
|
+
import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
|
|
26
|
+
import { EndSessionRequest } from "../request/EndSessionRequest";
|
|
27
|
+
import { PopupRequest } from "../request/PopupRequest";
|
|
28
|
+
import { RedirectRequest } from "../request/RedirectRequest";
|
|
29
|
+
import { SilentRequest } from "../request/SilentRequest";
|
|
30
|
+
import { SsoSilentRequest } from "../request/SsoSilentRequest";
|
|
31
|
+
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
32
|
+
import { ApiId, WrapperSKU, InteractionType } from "../utils/BrowserConstants";
|
|
33
|
+
import { IController } from "./IController";
|
|
34
|
+
import { UnknownOperatingContext } from "../operatingcontext/UnknownOperatingContext";
|
|
35
|
+
import { CryptoOps } from "../crypto/CryptoOps";
|
|
36
|
+
import {
|
|
37
|
+
blockAPICallsBeforeInitialize,
|
|
38
|
+
blockNonBrowserEnvironment,
|
|
39
|
+
} from "../utils/BrowserUtils";
|
|
40
|
+
import { EventHandler } from "../event/EventHandler";
|
|
41
|
+
import { EventCallbackFunction } from "../event/EventMessage";
|
|
42
|
+
import { ClearCacheRequest } from "../request/ClearCacheRequest";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* UnknownOperatingContextController class
|
|
46
|
+
*
|
|
47
|
+
* - Until initialize method is called, this controller is the default
|
|
48
|
+
* - AFter initialize method is called, this controller will be swapped out for the appropriate controller
|
|
49
|
+
* if the operating context can be determined; otherwise this controller will continued be used
|
|
50
|
+
*
|
|
51
|
+
* - Why do we have this? We don't want to dynamically import (download) all of the code in StandardController if we don't need to.
|
|
52
|
+
*
|
|
53
|
+
* - Only includes implementation for getAccounts and handleRedirectPromise
|
|
54
|
+
* - All other methods are will throw initialization error (because either initialize method or the factory method were not used)
|
|
55
|
+
* - This controller is necessary for React Native wrapper, server side rendering and any other scenario where we don't have a DOM
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export class UnknownOperatingContextController implements IController {
|
|
59
|
+
// OperatingContext
|
|
60
|
+
protected readonly operatingContext: UnknownOperatingContext;
|
|
61
|
+
|
|
62
|
+
// Logger
|
|
63
|
+
protected logger: Logger;
|
|
64
|
+
|
|
65
|
+
// Storage interface implementation
|
|
66
|
+
protected readonly browserStorage: BrowserCacheManager;
|
|
67
|
+
|
|
68
|
+
// Input configuration by developer/user
|
|
69
|
+
protected readonly config: BrowserConfiguration;
|
|
70
|
+
|
|
71
|
+
// Performance telemetry client
|
|
72
|
+
protected readonly performanceClient: IPerformanceClient;
|
|
73
|
+
|
|
74
|
+
// Crypto interface implementation
|
|
75
|
+
protected readonly browserCrypto: ICrypto;
|
|
76
|
+
|
|
77
|
+
// Flag to indicate if in browser environment
|
|
78
|
+
protected isBrowserEnvironment: boolean;
|
|
79
|
+
|
|
80
|
+
// Flag representing whether or not the initialize API has been called and completed
|
|
81
|
+
protected initialized: boolean = false;
|
|
82
|
+
|
|
83
|
+
protected readonly eventHandler: EventHandler;
|
|
84
|
+
|
|
85
|
+
constructor(operatingContext: UnknownOperatingContext) {
|
|
86
|
+
this.operatingContext = operatingContext;
|
|
87
|
+
|
|
88
|
+
this.isBrowserEnvironment =
|
|
89
|
+
this.operatingContext.isBrowserEnvironment();
|
|
90
|
+
|
|
91
|
+
this.config = operatingContext.getConfig();
|
|
92
|
+
|
|
93
|
+
this.logger = operatingContext.getLogger();
|
|
94
|
+
|
|
95
|
+
// Initialize performance client
|
|
96
|
+
this.performanceClient = this.config.telemetry.client;
|
|
97
|
+
|
|
98
|
+
// Initialize the crypto class.
|
|
99
|
+
this.browserCrypto = this.isBrowserEnvironment
|
|
100
|
+
? new CryptoOps(this.logger, this.performanceClient)
|
|
101
|
+
: DEFAULT_CRYPTO_IMPLEMENTATION;
|
|
102
|
+
|
|
103
|
+
// Initialize the browser storage class.
|
|
104
|
+
this.browserStorage = this.isBrowserEnvironment
|
|
105
|
+
? new BrowserCacheManager(
|
|
106
|
+
this.config.auth.clientId,
|
|
107
|
+
this.config.cache,
|
|
108
|
+
this.browserCrypto,
|
|
109
|
+
this.logger
|
|
110
|
+
)
|
|
111
|
+
: DEFAULT_BROWSER_CACHE_MANAGER(
|
|
112
|
+
this.config.auth.clientId,
|
|
113
|
+
this.logger
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
|
|
117
|
+
}
|
|
118
|
+
getBrowserStorage(): BrowserCacheManager {
|
|
119
|
+
return this.browserStorage;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getEventHandler(): EventHandler {
|
|
123
|
+
return this.eventHandler;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
127
|
+
getAccount(accountFilter: AccountFilter): AccountInfo | null {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
131
|
+
getAccountByHomeId(homeAccountId: string): AccountInfo | null {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
135
|
+
getAccountByLocalId(localAccountId: string): AccountInfo | null {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
139
|
+
getAccountByUsername(username: string): AccountInfo | null {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
getAllAccounts(): AccountInfo[] {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
initialize(): Promise<void> {
|
|
146
|
+
this.initialized = true;
|
|
147
|
+
return Promise.resolve();
|
|
148
|
+
}
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
150
|
+
acquireTokenPopup(request: PopupRequest): Promise<AuthenticationResult> {
|
|
151
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
152
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
153
|
+
return {} as Promise<AuthenticationResult>;
|
|
154
|
+
}
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
156
|
+
acquireTokenRedirect(request: RedirectRequest): Promise<void> {
|
|
157
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
158
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
159
|
+
return Promise.resolve();
|
|
160
|
+
}
|
|
161
|
+
acquireTokenSilent(
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
+
silentRequest: SilentRequest
|
|
164
|
+
): Promise<AuthenticationResult> {
|
|
165
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
166
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
167
|
+
return {} as Promise<AuthenticationResult>;
|
|
168
|
+
}
|
|
169
|
+
acquireTokenByCode(
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
+
request: AuthorizationCodeRequest
|
|
172
|
+
): Promise<AuthenticationResult> {
|
|
173
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
174
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
175
|
+
return {} as Promise<AuthenticationResult>;
|
|
176
|
+
}
|
|
177
|
+
acquireTokenNative(
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
179
|
+
request:
|
|
180
|
+
| PopupRequest
|
|
181
|
+
| SilentRequest
|
|
182
|
+
| Partial<
|
|
183
|
+
Omit<
|
|
184
|
+
CommonAuthorizationUrlRequest,
|
|
185
|
+
| "responseMode"
|
|
186
|
+
| "codeChallenge"
|
|
187
|
+
| "codeChallengeMethod"
|
|
188
|
+
| "requestedClaimsHash"
|
|
189
|
+
| "nativeBroker"
|
|
190
|
+
>
|
|
191
|
+
>,
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
193
|
+
apiId: ApiId,
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
195
|
+
accountId?: string | undefined
|
|
196
|
+
): Promise<AuthenticationResult> {
|
|
197
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
198
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
199
|
+
return {} as Promise<AuthenticationResult>;
|
|
200
|
+
}
|
|
201
|
+
acquireTokenByRefreshToken(
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
203
|
+
commonRequest: CommonSilentFlowRequest,
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
205
|
+
silentRequest: SilentRequest
|
|
206
|
+
): Promise<AuthenticationResult> {
|
|
207
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
208
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
209
|
+
return {} as Promise<AuthenticationResult>;
|
|
210
|
+
}
|
|
211
|
+
addEventCallback(callback: EventCallbackFunction): string | null {
|
|
212
|
+
return this.eventHandler.addEventCallback(callback);
|
|
213
|
+
}
|
|
214
|
+
removeEventCallback(callbackId: string): void {
|
|
215
|
+
this.eventHandler.removeEventCallback(callbackId);
|
|
216
|
+
}
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
218
|
+
addPerformanceCallback(callback: PerformanceCallbackFunction): string {
|
|
219
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
220
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
221
|
+
return "";
|
|
222
|
+
}
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
224
|
+
removePerformanceCallback(callbackId: string): boolean {
|
|
225
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
226
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
enableAccountStorageEvents(): void {
|
|
230
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
231
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
232
|
+
}
|
|
233
|
+
disableAccountStorageEvents(): void {
|
|
234
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
235
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
handleRedirectPromise(
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
240
|
+
hash?: string | undefined
|
|
241
|
+
): Promise<AuthenticationResult | null> {
|
|
242
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
243
|
+
return Promise.resolve(null);
|
|
244
|
+
}
|
|
245
|
+
loginPopup(
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
247
|
+
request?: PopupRequest | undefined
|
|
248
|
+
): Promise<AuthenticationResult> {
|
|
249
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
250
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
251
|
+
return {} as Promise<AuthenticationResult>;
|
|
252
|
+
}
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
254
|
+
loginRedirect(request?: RedirectRequest | undefined): Promise<void> {
|
|
255
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
256
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
257
|
+
return {} as Promise<void>;
|
|
258
|
+
}
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
260
|
+
logout(logoutRequest?: EndSessionRequest | undefined): Promise<void> {
|
|
261
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
262
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
263
|
+
return {} as Promise<void>;
|
|
264
|
+
}
|
|
265
|
+
logoutRedirect(
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
267
|
+
logoutRequest?: EndSessionRequest | undefined
|
|
268
|
+
): Promise<void> {
|
|
269
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
270
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
271
|
+
return {} as Promise<void>;
|
|
272
|
+
}
|
|
273
|
+
logoutPopup(
|
|
274
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
275
|
+
logoutRequest?: EndSessionPopupRequest | undefined
|
|
276
|
+
): Promise<void> {
|
|
277
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
278
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
279
|
+
return {} as Promise<void>;
|
|
280
|
+
}
|
|
281
|
+
ssoSilent(
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
283
|
+
request: Partial<
|
|
284
|
+
Omit<
|
|
285
|
+
CommonAuthorizationUrlRequest,
|
|
286
|
+
| "responseMode"
|
|
287
|
+
| "codeChallenge"
|
|
288
|
+
| "codeChallengeMethod"
|
|
289
|
+
| "requestedClaimsHash"
|
|
290
|
+
| "nativeBroker"
|
|
291
|
+
>
|
|
292
|
+
>
|
|
293
|
+
): Promise<AuthenticationResult> {
|
|
294
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
295
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
296
|
+
return {} as Promise<AuthenticationResult>;
|
|
297
|
+
}
|
|
298
|
+
getTokenCache(): ITokenCache {
|
|
299
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
300
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
301
|
+
return {} as ITokenCache;
|
|
302
|
+
}
|
|
303
|
+
getLogger(): Logger {
|
|
304
|
+
return this.logger;
|
|
305
|
+
}
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
307
|
+
setLogger(logger: Logger): void {
|
|
308
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
309
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
310
|
+
}
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
312
|
+
setActiveAccount(account: AccountInfo | null): void {
|
|
313
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
314
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
315
|
+
}
|
|
316
|
+
getActiveAccount(): AccountInfo | null {
|
|
317
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
318
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
322
|
+
initializeWrapperLibrary(sku: WrapperSKU, version: string): void {
|
|
323
|
+
this.browserStorage.setWrapperMetadata(sku, version);
|
|
324
|
+
}
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
326
|
+
setNavigationClient(navigationClient: INavigationClient): void {
|
|
327
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
328
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
329
|
+
}
|
|
330
|
+
getConfiguration(): BrowserConfiguration {
|
|
331
|
+
return this.config;
|
|
332
|
+
}
|
|
333
|
+
isBrowserEnv(): boolean {
|
|
334
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
335
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
getBrowserCrypto(): ICrypto {
|
|
339
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
340
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
341
|
+
return {} as ICrypto;
|
|
342
|
+
}
|
|
343
|
+
getPerformanceClient(): IPerformanceClient {
|
|
344
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
345
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
346
|
+
return {} as IPerformanceClient;
|
|
347
|
+
}
|
|
348
|
+
getRedirectResponse(): Map<string, Promise<AuthenticationResult | null>> {
|
|
349
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
350
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
351
|
+
return {} as Map<string, Promise<AuthenticationResult | null>>;
|
|
352
|
+
}
|
|
353
|
+
preflightBrowserEnvironmentCheck(
|
|
354
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
355
|
+
interactionType: InteractionType,
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
357
|
+
isAppEmbedded?: boolean | undefined
|
|
358
|
+
): void {
|
|
359
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
360
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
364
|
+
async clearCache(logoutRequest?: ClearCacheRequest): Promise<void> {
|
|
365
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
366
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
370
|
+
async hydrateCache(
|
|
371
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
372
|
+
result: AuthenticationResult,
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
374
|
+
request:
|
|
375
|
+
| SilentRequest
|
|
376
|
+
| SsoSilentRequest
|
|
377
|
+
| RedirectRequest
|
|
378
|
+
| PopupRequest
|
|
379
|
+
): Promise<void> {
|
|
380
|
+
blockAPICallsBeforeInitialize(this.initialized);
|
|
381
|
+
blockNonBrowserEnvironment(this.isBrowserEnvironment);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
@@ -3,14 +3,22 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { BrowserStringUtils } from "../utils/BrowserStringUtils";
|
|
7
6
|
import {
|
|
8
7
|
createBrowserAuthError,
|
|
9
8
|
BrowserAuthErrorCodes,
|
|
10
9
|
} from "../error/BrowserAuthError";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import {
|
|
11
|
+
IPerformanceClient,
|
|
12
|
+
Logger,
|
|
13
|
+
PerformanceEvents,
|
|
14
|
+
} from "@azure/msal-common";
|
|
15
|
+
import { KEY_FORMAT_JWK } from "../utils/BrowserConstants";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This file defines functions used by the browser library to perform cryptography operations such as
|
|
19
|
+
* hashing and encoding. It also has helper functions to validate the availability of specific APIs.
|
|
20
|
+
*/
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* See here for more info on RsaHashedKeyGenParams: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
|
|
16
24
|
*/
|
|
@@ -23,113 +31,121 @@ const MODULUS_LENGTH = 2048;
|
|
|
23
31
|
// Public Exponent
|
|
24
32
|
const PUBLIC_EXPONENT: Uint8Array = new Uint8Array([0x01, 0x00, 0x01]);
|
|
25
33
|
|
|
34
|
+
const keygenAlgorithmOptions: RsaHashedKeyGenParams = {
|
|
35
|
+
name: PKCS1_V15_KEYGEN_ALG,
|
|
36
|
+
hash: S256_HASH_ALG,
|
|
37
|
+
modulusLength: MODULUS_LENGTH,
|
|
38
|
+
publicExponent: PUBLIC_EXPONENT,
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
/**
|
|
27
|
-
*
|
|
28
|
-
* hashing and encoding. It also has helper functions to validate the availability of specific APIs.
|
|
42
|
+
* Check whether browser crypto is available.
|
|
29
43
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.logger = logger;
|
|
37
|
-
|
|
38
|
-
if (this.hasBrowserCrypto()) {
|
|
39
|
-
// Use standard modern web crypto if available
|
|
40
|
-
this.logger.verbose(
|
|
41
|
-
"BrowserCrypto: modern crypto interface available"
|
|
42
|
-
);
|
|
43
|
-
this.subtleCrypto = new ModernBrowserCrypto();
|
|
44
|
-
} else {
|
|
45
|
-
this.logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
46
|
-
throw createBrowserAuthError(
|
|
47
|
-
BrowserAuthErrorCodes.cryptoNonExistent
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.keygenAlgorithmOptions = {
|
|
52
|
-
name: PKCS1_V15_KEYGEN_ALG,
|
|
53
|
-
hash: S256_HASH_ALG,
|
|
54
|
-
modulusLength: MODULUS_LENGTH,
|
|
55
|
-
publicExponent: PUBLIC_EXPONENT,
|
|
56
|
-
};
|
|
44
|
+
export function validateCryptoAvailable(logger: Logger): void {
|
|
45
|
+
if ("crypto" in window) {
|
|
46
|
+
logger.verbose("BrowserCrypto: modern crypto interface available");
|
|
47
|
+
} else {
|
|
48
|
+
logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
49
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.cryptoNonExistent);
|
|
57
50
|
}
|
|
51
|
+
}
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Returns a sha-256 hash of the given dataString as an ArrayBuffer.
|
|
55
|
+
* @param dataString
|
|
56
|
+
*/
|
|
57
|
+
export async function sha256Digest(
|
|
58
|
+
dataString: string,
|
|
59
|
+
performanceClient?: IPerformanceClient,
|
|
60
|
+
correlationId?: string
|
|
61
|
+
): Promise<ArrayBuffer> {
|
|
62
|
+
performanceClient?.addQueueMeasurement(
|
|
63
|
+
PerformanceEvents.Sha256Digest,
|
|
64
|
+
correlationId
|
|
65
|
+
);
|
|
66
|
+
const encoder = new TextEncoder();
|
|
67
|
+
const data = encoder.encode(dataString);
|
|
68
|
+
return window.crypto.subtle.digest(
|
|
69
|
+
S256_HASH_ALG,
|
|
70
|
+
data
|
|
71
|
+
) as Promise<ArrayBuffer>;
|
|
72
|
+
}
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return this.subtleCrypto.digest({ name: S256_HASH_ALG }, data);
|
|
74
|
-
}
|
|
74
|
+
/**
|
|
75
|
+
* Populates buffer with cryptographically random values.
|
|
76
|
+
* @param dataBuffer
|
|
77
|
+
*/
|
|
78
|
+
export function getRandomValues(dataBuffer: Uint8Array): Uint8Array {
|
|
79
|
+
return window.crypto.getRandomValues(dataBuffer);
|
|
80
|
+
}
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new random GUID
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
export function createNewGuid(): string {
|
|
87
|
+
return window.crypto.randomUUID();
|
|
88
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Generates a keypair based on current keygen algorithm config.
|
|
92
|
+
* @param extractable
|
|
93
|
+
* @param usages
|
|
94
|
+
*/
|
|
95
|
+
export async function generateKeyPair(
|
|
96
|
+
extractable: boolean,
|
|
97
|
+
usages: Array<KeyUsage>
|
|
98
|
+
): Promise<CryptoKeyPair> {
|
|
99
|
+
return window.crypto.subtle.generateKey(
|
|
100
|
+
keygenAlgorithmOptions,
|
|
101
|
+
extractable,
|
|
102
|
+
usages
|
|
103
|
+
) as Promise<CryptoKeyPair>;
|
|
104
|
+
}
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Export key as Json Web Key (JWK)
|
|
108
|
+
* @param key
|
|
109
|
+
*/
|
|
110
|
+
export async function exportJwk(key: CryptoKey): Promise<JsonWebKey> {
|
|
111
|
+
return window.crypto.subtle.exportKey(
|
|
112
|
+
KEY_FORMAT_JWK,
|
|
113
|
+
key
|
|
114
|
+
) as Promise<JsonWebKey>;
|
|
115
|
+
}
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Imports key as Json Web Key (JWK), can set extractable and usages.
|
|
119
|
+
* @param key
|
|
120
|
+
* @param extractable
|
|
121
|
+
* @param usages
|
|
122
|
+
*/
|
|
123
|
+
export async function importJwk(
|
|
124
|
+
key: JsonWebKey,
|
|
125
|
+
extractable: boolean,
|
|
126
|
+
usages: Array<KeyUsage>
|
|
127
|
+
): Promise<CryptoKey> {
|
|
128
|
+
return window.crypto.subtle.importKey(
|
|
129
|
+
KEY_FORMAT_JWK,
|
|
130
|
+
key,
|
|
131
|
+
keygenAlgorithmOptions,
|
|
132
|
+
extractable,
|
|
133
|
+
usages
|
|
134
|
+
) as Promise<CryptoKey>;
|
|
135
|
+
}
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Signs given data with given key
|
|
139
|
+
* @param key
|
|
140
|
+
* @param data
|
|
141
|
+
*/
|
|
142
|
+
export async function sign(
|
|
143
|
+
key: CryptoKey,
|
|
144
|
+
data: ArrayBuffer
|
|
145
|
+
): Promise<ArrayBuffer> {
|
|
146
|
+
return window.crypto.subtle.sign(
|
|
147
|
+
keygenAlgorithmOptions,
|
|
148
|
+
key,
|
|
149
|
+
data
|
|
150
|
+
) as Promise<ArrayBuffer>;
|
|
135
151
|
}
|