@azure/msal-browser 3.0.1 → 3.1.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/README.md +5 -5
- package/dist/app/IPublicClientApplication.d.ts +6 -2
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +4 -1
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +11 -3
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +10 -2
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +5 -4
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +4 -3
- package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +13 -3
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +54 -26
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.mjs +1 -1
- package/dist/cache/BrowserStorage.mjs.map +1 -1
- package/dist/cache/CryptoKeyStore.mjs +1 -1
- package/dist/cache/CryptoKeyStore.mjs.map +1 -1
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.mjs +9 -8
- package/dist/cache/DatabaseStorage.mjs.map +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +30 -30
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/config/Configuration.d.ts +3 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +7 -11
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +11 -18
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +7 -26
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +28 -52
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +4 -3
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +0 -3
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +14 -17
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +1 -1
- package/dist/crypto/ModernBrowserCrypto.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +0 -1
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +8 -8
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
- package/dist/encode/Base64Decode.d.ts +6 -19
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.mjs +17 -70
- package/dist/encode/Base64Decode.mjs.map +1 -1
- package/dist/encode/Base64Encode.d.ts +15 -27
- package/dist/encode/Base64Encode.d.ts.map +1 -1
- package/dist/encode/Base64Encode.mjs +36 -75
- package/dist/encode/Base64Encode.mjs.map +1 -1
- package/dist/error/BrowserAuthError.d.ts +54 -195
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +150 -381
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +45 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserAuthErrorCodes.mjs +53 -0
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/NativeAuthError.d.ts.map +1 -1
- package/dist/error/NativeAuthError.mjs +5 -4
- package/dist/error/NativeAuthError.mjs.map +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventHandler.mjs.map +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventMessage.mjs.map +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/event/EventType.mjs.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +22 -30
- 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 +16 -15
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -6
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +5 -4
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +10 -8
- 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 +20 -47
- 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 +4 -3
- 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 +8 -7
- 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 +9 -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 +11 -10
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +10 -9
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/navigation/NavigationClient.mjs.map +1 -1
- package/dist/network/FetchClient.d.ts.map +1 -1
- package/dist/network/FetchClient.mjs +9 -8
- package/dist/network/FetchClient.mjs.map +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.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/ClearCacheRequest.d.ts +11 -0
- package/dist/request/ClearCacheRequest.d.ts.map +1 -0
- package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
- package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs.map +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/BrowserStringUtils.mjs +1 -1
- package/dist/utils/BrowserStringUtils.mjs.map +1 -1
- package/dist/utils/BrowserUtils.d.ts +0 -9
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +8 -33
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +6601 -7104
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +6601 -7104
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +65 -62
- package/package.json +7 -5
- package/src/app/IPublicClientApplication.ts +199 -0
- package/src/app/PublicClientApplication.ts +405 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +419 -0
- package/src/broker/nativeBroker/NativeRequest.ts +52 -0
- package/src/broker/nativeBroker/NativeResponse.ts +56 -0
- package/src/cache/AsyncMemoryStorage.ts +158 -0
- package/src/cache/BrowserCacheManager.ts +1994 -0
- package/src/cache/BrowserStorage.ts +54 -0
- package/src/cache/CryptoKeyStore.ts +63 -0
- package/src/cache/DatabaseStorage.ts +287 -0
- package/src/cache/IAsyncMemoryStorage.ts +36 -0
- package/src/cache/ITokenCache.ts +21 -0
- package/src/cache/IWindowStorage.ts +36 -0
- package/src/cache/MemoryStorage.ts +42 -0
- package/src/cache/TokenCache.ts +484 -0
- package/src/config/Configuration.ts +375 -0
- package/src/controllers/ControllerFactory.ts +55 -0
- package/src/controllers/IController.ts +131 -0
- package/src/controllers/StandardController.ts +2107 -0
- package/src/crypto/BrowserCrypto.ts +135 -0
- package/src/crypto/CryptoOps.ts +247 -0
- package/src/crypto/ISubtleCrypto.ts +30 -0
- package/src/crypto/ModernBrowserCrypto.ts +69 -0
- package/src/crypto/PkceGenerator.ts +76 -0
- package/src/crypto/SignedHttpRequest.ts +76 -0
- package/src/encode/Base64Decode.ts +26 -0
- package/src/encode/Base64Encode.ts +52 -0
- package/src/error/BrowserAuthError.ts +340 -0
- package/src/error/BrowserAuthErrorCodes.ts +56 -0
- package/src/error/BrowserConfigurationAuthError.ts +133 -0
- package/src/error/NativeAuthError.ts +141 -0
- package/src/event/EventHandler.ts +176 -0
- package/src/event/EventMessage.ts +125 -0
- package/src/event/EventType.ts +33 -0
- package/src/index.ts +152 -0
- package/src/interaction_client/BaseInteractionClient.ts +301 -0
- package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
- package/src/interaction_client/NativeInteractionClient.ts +907 -0
- package/src/interaction_client/PopupClient.ts +926 -0
- package/src/interaction_client/RedirectClient.ts +616 -0
- package/src/interaction_client/SilentAuthCodeClient.ts +163 -0
- package/src/interaction_client/SilentCacheClient.ts +133 -0
- package/src/interaction_client/SilentIframeClient.ts +301 -0
- package/src/interaction_client/SilentRefreshClient.ts +120 -0
- package/src/interaction_client/StandardInteractionClient.ts +481 -0
- package/src/interaction_handler/InteractionHandler.ts +246 -0
- package/src/interaction_handler/RedirectHandler.ts +225 -0
- package/src/interaction_handler/SilentHandler.ts +266 -0
- package/src/navigation/INavigationClient.ts +23 -0
- package/src/navigation/NavigationClient.ts +55 -0
- package/src/navigation/NavigationOptions.ts +18 -0
- package/src/network/FetchClient.ts +130 -0
- package/src/operatingcontext/BaseOperatingContext.ts +82 -0
- package/src/operatingcontext/StandardOperatingContext.ts +49 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthorizationCodeRequest.ts +19 -0
- package/src/request/AuthorizationUrlRequest.ts +17 -0
- package/src/request/ClearCacheRequest.ts +16 -0
- package/src/request/EndSessionPopupRequest.ts +26 -0
- package/src/request/EndSessionRequest.ts +23 -0
- package/src/request/PopupRequest.ts +51 -0
- package/src/request/PopupWindowAttributes.ts +22 -0
- package/src/request/RedirectRequest.ts +51 -0
- package/src/request/SilentRequest.ts +49 -0
- package/src/request/SsoSilentRequest.ts +44 -0
- package/src/response/AuthenticationResult.ts +13 -0
- package/src/telemetry/BrowserPerformanceClient.ts +226 -0
- package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
- package/src/utils/BrowserConstants.ts +241 -0
- package/src/utils/BrowserProtocolUtils.ts +57 -0
- package/src/utils/BrowserStringUtils.ts +143 -0
- package/src/utils/BrowserUtils.ts +156 -0
- package/dist/crypto/GuidGenerator.d.ts +0 -13
- package/dist/crypto/GuidGenerator.d.ts.map +0 -1
- package/dist/crypto/GuidGenerator.mjs +0 -104
- package/dist/crypto/GuidGenerator.mjs.map +0 -1
- package/dist/internals.d.ts +0 -23
- package/dist/internals.d.ts.map +0 -1
- package/dist/internals.mjs +0 -28
- package/dist/internals.mjs.map +0 -1
- package/dist/network/XhrClient.d.ts +0 -41
- package/dist/network/XhrClient.d.ts.map +0 -1
- package/dist/network/XhrClient.mjs +0 -125
- package/dist/network/XhrClient.mjs.map +0 -1
- package/dist/utils/MathUtils.d.ts +0 -12
- package/dist/utils/MathUtils.d.ts.map +0 -1
- package/dist/utils/MathUtils.mjs +0 -26
- package/dist/utils/MathUtils.mjs.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BrowserConfigurationAuthError } from "../error/BrowserConfigurationAuthError";
|
|
7
|
+
import { BrowserCacheLocation } from "../utils/BrowserConstants";
|
|
8
|
+
import { IWindowStorage } from "./IWindowStorage";
|
|
9
|
+
|
|
10
|
+
export class BrowserStorage implements IWindowStorage<string> {
|
|
11
|
+
private windowStorage: Storage;
|
|
12
|
+
|
|
13
|
+
constructor(cacheLocation: string) {
|
|
14
|
+
this.validateWindowStorage(cacheLocation);
|
|
15
|
+
this.windowStorage = window[cacheLocation];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private validateWindowStorage(cacheLocation: string): void {
|
|
19
|
+
if (
|
|
20
|
+
cacheLocation !== BrowserCacheLocation.LocalStorage &&
|
|
21
|
+
cacheLocation !== BrowserCacheLocation.SessionStorage
|
|
22
|
+
) {
|
|
23
|
+
throw BrowserConfigurationAuthError.createStorageNotSupportedError(
|
|
24
|
+
cacheLocation
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const storageSupported = !!window[cacheLocation];
|
|
28
|
+
if (!storageSupported) {
|
|
29
|
+
throw BrowserConfigurationAuthError.createStorageNotSupportedError(
|
|
30
|
+
cacheLocation
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getItem(key: string): string | null {
|
|
36
|
+
return this.windowStorage.getItem(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setItem(key: string, value: string): void {
|
|
40
|
+
this.windowStorage.setItem(key, value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
removeItem(key: string): void {
|
|
44
|
+
this.windowStorage.removeItem(key);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getKeys(): string[] {
|
|
48
|
+
return Object.keys(this.windowStorage);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
containsKey(key: string): boolean {
|
|
52
|
+
return this.windowStorage.hasOwnProperty(key);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Logger } from "@azure/msal-common";
|
|
7
|
+
import { CachedKeyPair } from "../crypto/CryptoOps";
|
|
8
|
+
import { AsyncMemoryStorage } from "./AsyncMemoryStorage";
|
|
9
|
+
|
|
10
|
+
export const CryptoKeyStoreNames = {
|
|
11
|
+
asymmetricKeys: "asymmetricKeys",
|
|
12
|
+
symmetricKeys: "symmetricKeys",
|
|
13
|
+
} as const;
|
|
14
|
+
export type CryptoKeyStoreNames =
|
|
15
|
+
(typeof CryptoKeyStoreNames)[keyof typeof CryptoKeyStoreNames];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* MSAL CryptoKeyStore DB Version 2
|
|
19
|
+
*/
|
|
20
|
+
export class CryptoKeyStore {
|
|
21
|
+
public asymmetricKeys: AsyncMemoryStorage<CachedKeyPair>;
|
|
22
|
+
public symmetricKeys: AsyncMemoryStorage<CryptoKey>;
|
|
23
|
+
public logger: Logger;
|
|
24
|
+
|
|
25
|
+
constructor(logger: Logger) {
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
this.asymmetricKeys = new AsyncMemoryStorage<CachedKeyPair>(
|
|
28
|
+
this.logger,
|
|
29
|
+
CryptoKeyStoreNames.asymmetricKeys
|
|
30
|
+
);
|
|
31
|
+
this.symmetricKeys = new AsyncMemoryStorage<CryptoKey>(
|
|
32
|
+
this.logger,
|
|
33
|
+
CryptoKeyStoreNames.symmetricKeys
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async clear(): Promise<boolean> {
|
|
38
|
+
// Delete in-memory keystores
|
|
39
|
+
this.asymmetricKeys.clearInMemory();
|
|
40
|
+
this.symmetricKeys.clearInMemory();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* There is only one database, so calling clearPersistent on asymmetric keystore takes care of
|
|
44
|
+
* every persistent keystore
|
|
45
|
+
*/
|
|
46
|
+
try {
|
|
47
|
+
await this.asymmetricKeys.clearPersistent();
|
|
48
|
+
return true;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof Error) {
|
|
51
|
+
this.logger.error(
|
|
52
|
+
`Clearing keystore failed with error: ${e.message}`
|
|
53
|
+
);
|
|
54
|
+
} else {
|
|
55
|
+
this.logger.error(
|
|
56
|
+
"Clearing keystore failed with unknown error"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
createBrowserAuthError,
|
|
8
|
+
BrowserAuthErrorCodes,
|
|
9
|
+
} from "../error/BrowserAuthError";
|
|
10
|
+
import { DB_NAME, DB_TABLE_NAME, DB_VERSION } from "../utils/BrowserConstants";
|
|
11
|
+
import { IAsyncStorage } from "./IAsyncMemoryStorage";
|
|
12
|
+
|
|
13
|
+
interface IDBOpenDBRequestEvent extends Event {
|
|
14
|
+
target: IDBOpenDBRequest & EventTarget;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IDBOpenOnUpgradeNeededEvent extends IDBVersionChangeEvent {
|
|
18
|
+
target: IDBOpenDBRequest & EventTarget;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IDBRequestEvent extends Event {
|
|
22
|
+
target: IDBRequest & EventTarget;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Storage wrapper for IndexedDB storage in browsers: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
|
|
27
|
+
*/
|
|
28
|
+
export class DatabaseStorage<T> implements IAsyncStorage<T> {
|
|
29
|
+
private db: IDBDatabase | undefined;
|
|
30
|
+
private dbName: string;
|
|
31
|
+
private tableName: string;
|
|
32
|
+
private version: number;
|
|
33
|
+
private dbOpen: boolean;
|
|
34
|
+
|
|
35
|
+
constructor() {
|
|
36
|
+
this.dbName = DB_NAME;
|
|
37
|
+
this.version = DB_VERSION;
|
|
38
|
+
this.tableName = DB_TABLE_NAME;
|
|
39
|
+
this.dbOpen = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Opens IndexedDB instance.
|
|
44
|
+
*/
|
|
45
|
+
async open(): Promise<void> {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const openDB = window.indexedDB.open(this.dbName, this.version);
|
|
48
|
+
openDB.addEventListener(
|
|
49
|
+
"upgradeneeded",
|
|
50
|
+
(e: IDBVersionChangeEvent) => {
|
|
51
|
+
const event = e as IDBOpenOnUpgradeNeededEvent;
|
|
52
|
+
event.target.result.createObjectStore(this.tableName);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
openDB.addEventListener("success", (e: Event) => {
|
|
56
|
+
const event = e as IDBOpenDBRequestEvent;
|
|
57
|
+
this.db = event.target.result;
|
|
58
|
+
this.dbOpen = true;
|
|
59
|
+
resolve();
|
|
60
|
+
});
|
|
61
|
+
openDB.addEventListener("error", () =>
|
|
62
|
+
reject(
|
|
63
|
+
createBrowserAuthError(
|
|
64
|
+
BrowserAuthErrorCodes.databaseUnavailable
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Closes the connection to IndexedDB database when all pending transactions
|
|
73
|
+
* complete.
|
|
74
|
+
*/
|
|
75
|
+
closeConnection(): void {
|
|
76
|
+
const db = this.db;
|
|
77
|
+
if (db && this.dbOpen) {
|
|
78
|
+
db.close();
|
|
79
|
+
this.dbOpen = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Opens database if it's not already open
|
|
85
|
+
*/
|
|
86
|
+
private async validateDbIsOpen(): Promise<void> {
|
|
87
|
+
if (!this.dbOpen) {
|
|
88
|
+
return await this.open();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves item from IndexedDB instance.
|
|
94
|
+
* @param key
|
|
95
|
+
*/
|
|
96
|
+
async getItem(key: string): Promise<T | null> {
|
|
97
|
+
await this.validateDbIsOpen();
|
|
98
|
+
return new Promise<T>((resolve, reject) => {
|
|
99
|
+
// TODO: Add timeouts?
|
|
100
|
+
if (!this.db) {
|
|
101
|
+
return reject(
|
|
102
|
+
createBrowserAuthError(
|
|
103
|
+
BrowserAuthErrorCodes.databaseNotOpen
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const transaction = this.db.transaction(
|
|
108
|
+
[this.tableName],
|
|
109
|
+
"readonly"
|
|
110
|
+
);
|
|
111
|
+
const objectStore = transaction.objectStore(this.tableName);
|
|
112
|
+
const dbGet = objectStore.get(key);
|
|
113
|
+
|
|
114
|
+
dbGet.addEventListener("success", (e: Event) => {
|
|
115
|
+
const event = e as IDBRequestEvent;
|
|
116
|
+
this.closeConnection();
|
|
117
|
+
resolve(event.target.result);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
dbGet.addEventListener("error", (e: Event) => {
|
|
121
|
+
this.closeConnection();
|
|
122
|
+
reject(e);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Adds item to IndexedDB under given key
|
|
129
|
+
* @param key
|
|
130
|
+
* @param payload
|
|
131
|
+
*/
|
|
132
|
+
async setItem(key: string, payload: T): Promise<void> {
|
|
133
|
+
await this.validateDbIsOpen();
|
|
134
|
+
return new Promise<void>((resolve: Function, reject: Function) => {
|
|
135
|
+
// TODO: Add timeouts?
|
|
136
|
+
if (!this.db) {
|
|
137
|
+
return reject(
|
|
138
|
+
createBrowserAuthError(
|
|
139
|
+
BrowserAuthErrorCodes.databaseNotOpen
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
const transaction = this.db.transaction(
|
|
144
|
+
[this.tableName],
|
|
145
|
+
"readwrite"
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const objectStore = transaction.objectStore(this.tableName);
|
|
149
|
+
|
|
150
|
+
const dbPut = objectStore.put(payload, key);
|
|
151
|
+
|
|
152
|
+
dbPut.addEventListener("success", () => {
|
|
153
|
+
this.closeConnection();
|
|
154
|
+
resolve();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
dbPut.addEventListener("error", (e) => {
|
|
158
|
+
this.closeConnection();
|
|
159
|
+
reject(e);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Removes item from IndexedDB under given key
|
|
166
|
+
* @param key
|
|
167
|
+
*/
|
|
168
|
+
async removeItem(key: string): Promise<void> {
|
|
169
|
+
await this.validateDbIsOpen();
|
|
170
|
+
return new Promise<void>((resolve: Function, reject: Function) => {
|
|
171
|
+
if (!this.db) {
|
|
172
|
+
return reject(
|
|
173
|
+
createBrowserAuthError(
|
|
174
|
+
BrowserAuthErrorCodes.databaseNotOpen
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const transaction = this.db.transaction(
|
|
180
|
+
[this.tableName],
|
|
181
|
+
"readwrite"
|
|
182
|
+
);
|
|
183
|
+
const objectStore = transaction.objectStore(this.tableName);
|
|
184
|
+
const dbDelete = objectStore.delete(key);
|
|
185
|
+
|
|
186
|
+
dbDelete.addEventListener("success", () => {
|
|
187
|
+
this.closeConnection();
|
|
188
|
+
resolve();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
dbDelete.addEventListener("error", (e) => {
|
|
192
|
+
this.closeConnection();
|
|
193
|
+
reject(e);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Get all the keys from the storage object as an iterable array of strings.
|
|
200
|
+
*/
|
|
201
|
+
async getKeys(): Promise<string[]> {
|
|
202
|
+
await this.validateDbIsOpen();
|
|
203
|
+
return new Promise<string[]>((resolve: Function, reject: Function) => {
|
|
204
|
+
if (!this.db) {
|
|
205
|
+
return reject(
|
|
206
|
+
createBrowserAuthError(
|
|
207
|
+
BrowserAuthErrorCodes.databaseNotOpen
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const transaction = this.db.transaction(
|
|
213
|
+
[this.tableName],
|
|
214
|
+
"readonly"
|
|
215
|
+
);
|
|
216
|
+
const objectStore = transaction.objectStore(this.tableName);
|
|
217
|
+
const dbGetKeys = objectStore.getAllKeys();
|
|
218
|
+
|
|
219
|
+
dbGetKeys.addEventListener("success", (e: Event) => {
|
|
220
|
+
const event = e as IDBRequestEvent;
|
|
221
|
+
this.closeConnection();
|
|
222
|
+
resolve(event.target.result);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
dbGetKeys.addEventListener("error", (e: Event) => {
|
|
226
|
+
this.closeConnection();
|
|
227
|
+
reject(e);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
* Checks whether there is an object under the search key in the object store
|
|
235
|
+
*/
|
|
236
|
+
async containsKey(key: string): Promise<boolean> {
|
|
237
|
+
await this.validateDbIsOpen();
|
|
238
|
+
|
|
239
|
+
return new Promise<boolean>((resolve: Function, reject: Function) => {
|
|
240
|
+
if (!this.db) {
|
|
241
|
+
return reject(
|
|
242
|
+
createBrowserAuthError(
|
|
243
|
+
BrowserAuthErrorCodes.databaseNotOpen
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const transaction = this.db.transaction(
|
|
249
|
+
[this.tableName],
|
|
250
|
+
"readonly"
|
|
251
|
+
);
|
|
252
|
+
const objectStore = transaction.objectStore(this.tableName);
|
|
253
|
+
const dbContainsKey = objectStore.count(key);
|
|
254
|
+
|
|
255
|
+
dbContainsKey.addEventListener("success", (e: Event) => {
|
|
256
|
+
const event = e as IDBRequestEvent;
|
|
257
|
+
this.closeConnection();
|
|
258
|
+
resolve(event.target.result === 1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
dbContainsKey.addEventListener("error", (e: Event) => {
|
|
262
|
+
this.closeConnection();
|
|
263
|
+
reject(e);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Deletes the MSAL database. The database is deleted rather than cleared to make it possible
|
|
270
|
+
* for client applications to downgrade to a previous MSAL version without worrying about forward compatibility issues
|
|
271
|
+
* with IndexedDB database versions.
|
|
272
|
+
*/
|
|
273
|
+
async deleteDatabase(): Promise<boolean> {
|
|
274
|
+
// Check if database being deleted exists
|
|
275
|
+
|
|
276
|
+
if (this.db && this.dbOpen) {
|
|
277
|
+
this.closeConnection();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return new Promise<boolean>((resolve: Function, reject: Function) => {
|
|
281
|
+
const deleteDbRequest = window.indexedDB.deleteDatabase(DB_NAME);
|
|
282
|
+
deleteDbRequest.addEventListener("success", () => resolve(true));
|
|
283
|
+
deleteDbRequest.addEventListener("blocked", () => resolve(true));
|
|
284
|
+
deleteDbRequest.addEventListener("error", () => reject(false));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface IAsyncStorage<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Get the item from the asynchronous storage object matching the given key.
|
|
9
|
+
* @param key
|
|
10
|
+
*/
|
|
11
|
+
getItem(key: string): Promise<T | null>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sets the item in the asynchronous storage object with the given key.
|
|
15
|
+
* @param key
|
|
16
|
+
* @param value
|
|
17
|
+
*/
|
|
18
|
+
setItem(key: string, value: T): Promise<void>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Removes the item in the asynchronous storage object matching the given key.
|
|
22
|
+
* @param key
|
|
23
|
+
*/
|
|
24
|
+
removeItem(key: string): Promise<void>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get all the keys from the asynchronous storage object as an iterable array of strings.
|
|
28
|
+
*/
|
|
29
|
+
getKeys(): Promise<string[]>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns true or false if the given key is present in the cache.
|
|
33
|
+
* @param key
|
|
34
|
+
*/
|
|
35
|
+
containsKey(key: string): Promise<boolean>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ExternalTokenResponse } from "@azure/msal-common";
|
|
7
|
+
import { SilentRequest } from "../request/SilentRequest";
|
|
8
|
+
import { LoadTokenOptions } from "./TokenCache";
|
|
9
|
+
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
10
|
+
|
|
11
|
+
export interface ITokenCache {
|
|
12
|
+
/**
|
|
13
|
+
* API to side-load tokens to MSAL cache
|
|
14
|
+
* @returns `AuthenticationResult` for the response that was loaded.
|
|
15
|
+
*/
|
|
16
|
+
loadExternalTokens(
|
|
17
|
+
request: SilentRequest,
|
|
18
|
+
response: ExternalTokenResponse,
|
|
19
|
+
options: LoadTokenOptions
|
|
20
|
+
): AuthenticationResult;
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface IWindowStorage<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Get the item from the window storage object matching the given key.
|
|
9
|
+
* @param key
|
|
10
|
+
*/
|
|
11
|
+
getItem(key: string): T | null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sets the item in the window storage object with the given key.
|
|
15
|
+
* @param key
|
|
16
|
+
* @param value
|
|
17
|
+
*/
|
|
18
|
+
setItem(key: string, value: T): void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Removes the item in the window storage object matching the given key.
|
|
22
|
+
* @param key
|
|
23
|
+
*/
|
|
24
|
+
removeItem(key: string): void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get all the keys from the window storage object as an iterable array of strings.
|
|
28
|
+
*/
|
|
29
|
+
getKeys(): string[];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns true or false if the given key is present in the cache.
|
|
33
|
+
* @param key
|
|
34
|
+
*/
|
|
35
|
+
containsKey(key: string): boolean;
|
|
36
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IWindowStorage } from "./IWindowStorage";
|
|
7
|
+
|
|
8
|
+
export class MemoryStorage<T> implements IWindowStorage<T> {
|
|
9
|
+
private cache: Map<string, T>;
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
this.cache = new Map<string, T>();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getItem(key: string): T | null {
|
|
16
|
+
return this.cache.get(key) || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setItem(key: string, value: T): void {
|
|
20
|
+
this.cache.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
removeItem(key: string): void {
|
|
24
|
+
this.cache.delete(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getKeys(): string[] {
|
|
28
|
+
const cacheKeys: string[] = [];
|
|
29
|
+
this.cache.forEach((value: T, key: string) => {
|
|
30
|
+
cacheKeys.push(key);
|
|
31
|
+
});
|
|
32
|
+
return cacheKeys;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
containsKey(key: string): boolean {
|
|
36
|
+
return this.cache.has(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clear(): void {
|
|
40
|
+
this.cache.clear();
|
|
41
|
+
}
|
|
42
|
+
}
|