@azure/msal-browser 3.0.2 → 3.2.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 +2 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +22 -18
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +20 -6
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +24 -7
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- 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 +17 -16
- 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 +4 -3
- package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +10 -3
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +58 -29
- 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/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 +1 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +12 -16
- 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 +5 -28
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +17 -31
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +78 -83
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +44 -49
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +78 -77
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +1 -10
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +23 -34
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +6 -22
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +48 -49
- 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 +31 -68
- 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 +63 -195
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +159 -381
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
- 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 +49 -79
- 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/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/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 +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +8 -4
- 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 +7 -8
- 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 +32 -38
- 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 +9 -11
- 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 +19 -25
- 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 +11 -20
- 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 +18 -38
- 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 +13 -16
- 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 +12 -11
- 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 +11 -11
- 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 +4 -4
- 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 +8729 -9566
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +8729 -9566
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +68 -62
- package/package.json +7 -5
- package/src/app/IPublicClientApplication.ts +236 -0
- package/src/app/PublicClientApplication.ts +417 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
- package/src/broker/nativeBroker/NativeRequest.ts +52 -0
- package/src/broker/nativeBroker/NativeResponse.ts +56 -0
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/AsyncMemoryStorage.ts +158 -0
- package/src/cache/BrowserCacheManager.ts +2009 -0
- package/src/cache/BrowserStorage.ts +52 -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 +383 -0
- package/src/controllers/ControllerFactory.ts +55 -0
- package/src/controllers/IController.ts +134 -0
- package/src/controllers/StandardController.ts +2170 -0
- package/src/crypto/BrowserCrypto.ts +151 -0
- package/src/crypto/CryptoOps.ts +235 -0
- package/src/crypto/PkceGenerator.ts +115 -0
- package/src/crypto/SignedHttpRequest.ts +76 -0
- package/src/encode/Base64Decode.ts +46 -0
- package/src/encode/Base64Encode.ts +52 -0
- package/src/error/BrowserAuthError.ts +352 -0
- package/src/error/BrowserAuthErrorCodes.ts +57 -0
- package/src/error/BrowserConfigurationAuthError.ts +64 -0
- package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
- package/src/error/NativeAuthError.ts +113 -0
- package/src/error/NativeAuthErrorCodes.ts +7 -0
- package/src/event/EventHandler.ts +177 -0
- package/src/event/EventMessage.ts +125 -0
- package/src/event/EventType.ts +33 -0
- package/src/index.ts +157 -0
- package/src/interaction_client/BaseInteractionClient.ts +307 -0
- package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
- package/src/interaction_client/NativeInteractionClient.ts +925 -0
- package/src/interaction_client/PopupClient.ts +926 -0
- package/src/interaction_client/RedirectClient.ts +616 -0
- package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
- package/src/interaction_client/SilentCacheClient.ts +125 -0
- package/src/interaction_client/SilentIframeClient.ts +301 -0
- package/src/interaction_client/SilentRefreshClient.ts +118 -0
- package/src/interaction_client/StandardInteractionClient.ts +450 -0
- package/src/interaction_handler/InteractionHandler.ts +251 -0
- package/src/interaction_handler/RedirectHandler.ts +229 -0
- package/src/interaction_handler/SilentHandler.ts +269 -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 +58 -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/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/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
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.0
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
5
|
+
import { PerformanceEvents } from '@azure/msal-common';
|
|
6
|
+
import { KEY_FORMAT_JWK } from '../utils/BrowserConstants.mjs';
|
|
7
|
+
import { cryptoNonExistent } from '../error/BrowserAuthErrorCodes.mjs';
|
|
6
8
|
|
|
7
9
|
/*
|
|
8
10
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
11
|
* Licensed under the MIT License.
|
|
10
12
|
*/
|
|
13
|
+
/**
|
|
14
|
+
* This file defines functions used by the browser library to perform cryptography operations such as
|
|
15
|
+
* hashing and encoding. It also has helper functions to validate the availability of specific APIs.
|
|
16
|
+
*/
|
|
11
17
|
/**
|
|
12
18
|
* See here for more info on RsaHashedKeyGenParams: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
|
|
13
19
|
*/
|
|
@@ -19,84 +25,79 @@ const S256_HASH_ALG = "SHA-256";
|
|
|
19
25
|
const MODULUS_LENGTH = 2048;
|
|
20
26
|
// Public Exponent
|
|
21
27
|
const PUBLIC_EXPONENT = new Uint8Array([0x01, 0x00, 0x01]);
|
|
28
|
+
const keygenAlgorithmOptions = {
|
|
29
|
+
name: PKCS1_V15_KEYGEN_ALG,
|
|
30
|
+
hash: S256_HASH_ALG,
|
|
31
|
+
modulusLength: MODULUS_LENGTH,
|
|
32
|
+
publicExponent: PUBLIC_EXPONENT,
|
|
33
|
+
};
|
|
22
34
|
/**
|
|
23
|
-
*
|
|
24
|
-
* hashing and encoding. It also has helper functions to validate the availability of specific APIs.
|
|
35
|
+
* Check whether browser crypto is available.
|
|
25
36
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (this.hasBrowserCrypto()) {
|
|
30
|
-
// Use standard modern web crypto if available
|
|
31
|
-
this.logger.verbose("BrowserCrypto: modern crypto interface available");
|
|
32
|
-
this.subtleCrypto = new ModernBrowserCrypto();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
36
|
-
throw BrowserAuthError.createCryptoNotAvailableError("Browser crypto interface is not available.");
|
|
37
|
-
}
|
|
38
|
-
this.keygenAlgorithmOptions = {
|
|
39
|
-
name: PKCS1_V15_KEYGEN_ALG,
|
|
40
|
-
hash: S256_HASH_ALG,
|
|
41
|
-
modulusLength: MODULUS_LENGTH,
|
|
42
|
-
publicExponent: PUBLIC_EXPONENT,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Check whether browser crypto is available.
|
|
47
|
-
*/
|
|
48
|
-
hasBrowserCrypto() {
|
|
49
|
-
return "crypto" in window;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns a sha-256 hash of the given dataString as an ArrayBuffer.
|
|
53
|
-
* @param dataString
|
|
54
|
-
*/
|
|
55
|
-
async sha256Digest(dataString) {
|
|
56
|
-
const data = BrowserStringUtils.stringToUtf8Arr(dataString);
|
|
57
|
-
// MSR Crypto wants object with name property, instead of string
|
|
58
|
-
return this.subtleCrypto.digest({ name: S256_HASH_ALG }, data);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Populates buffer with cryptographically random values.
|
|
62
|
-
* @param dataBuffer
|
|
63
|
-
*/
|
|
64
|
-
getRandomValues(dataBuffer) {
|
|
65
|
-
return this.subtleCrypto.getRandomValues(dataBuffer);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Generates a keypair based on current keygen algorithm config.
|
|
69
|
-
* @param extractable
|
|
70
|
-
* @param usages
|
|
71
|
-
*/
|
|
72
|
-
async generateKeyPair(extractable, usages) {
|
|
73
|
-
return this.subtleCrypto.generateKey(this.keygenAlgorithmOptions, extractable, usages);
|
|
37
|
+
function validateCryptoAvailable(logger) {
|
|
38
|
+
if ("crypto" in window) {
|
|
39
|
+
logger.verbose("BrowserCrypto: modern crypto interface available");
|
|
74
40
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/
|
|
79
|
-
async exportJwk(key) {
|
|
80
|
-
return this.subtleCrypto.exportKey(key);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Imports key as Json Web Key (JWK), can set extractable and usages.
|
|
84
|
-
* @param key
|
|
85
|
-
* @param extractable
|
|
86
|
-
* @param usages
|
|
87
|
-
*/
|
|
88
|
-
async importJwk(key, extractable, usages) {
|
|
89
|
-
return this.subtleCrypto.importKey(key, this.keygenAlgorithmOptions, extractable, usages);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Signs given data with given key
|
|
93
|
-
* @param key
|
|
94
|
-
* @param data
|
|
95
|
-
*/
|
|
96
|
-
async sign(key, data) {
|
|
97
|
-
return this.subtleCrypto.sign(this.keygenAlgorithmOptions, key, data);
|
|
41
|
+
else {
|
|
42
|
+
logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
43
|
+
throw createBrowserAuthError(cryptoNonExistent);
|
|
98
44
|
}
|
|
99
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns a sha-256 hash of the given dataString as an ArrayBuffer.
|
|
48
|
+
* @param dataString
|
|
49
|
+
*/
|
|
50
|
+
async function sha256Digest(dataString, performanceClient, correlationId) {
|
|
51
|
+
performanceClient?.addQueueMeasurement(PerformanceEvents.Sha256Digest, correlationId);
|
|
52
|
+
const data = BrowserStringUtils.stringToUtf8Arr(dataString);
|
|
53
|
+
return window.crypto.subtle.digest(S256_HASH_ALG, data);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Populates buffer with cryptographically random values.
|
|
57
|
+
* @param dataBuffer
|
|
58
|
+
*/
|
|
59
|
+
function getRandomValues(dataBuffer) {
|
|
60
|
+
return window.crypto.getRandomValues(dataBuffer);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new random GUID
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
function createNewGuid() {
|
|
67
|
+
return window.crypto.randomUUID();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generates a keypair based on current keygen algorithm config.
|
|
71
|
+
* @param extractable
|
|
72
|
+
* @param usages
|
|
73
|
+
*/
|
|
74
|
+
async function generateKeyPair(extractable, usages) {
|
|
75
|
+
return window.crypto.subtle.generateKey(keygenAlgorithmOptions, extractable, usages);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Export key as Json Web Key (JWK)
|
|
79
|
+
* @param key
|
|
80
|
+
*/
|
|
81
|
+
async function exportJwk(key) {
|
|
82
|
+
return window.crypto.subtle.exportKey(KEY_FORMAT_JWK, key);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Imports key as Json Web Key (JWK), can set extractable and usages.
|
|
86
|
+
* @param key
|
|
87
|
+
* @param extractable
|
|
88
|
+
* @param usages
|
|
89
|
+
*/
|
|
90
|
+
async function importJwk(key, extractable, usages) {
|
|
91
|
+
return window.crypto.subtle.importKey(KEY_FORMAT_JWK, key, keygenAlgorithmOptions, extractable, usages);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Signs given data with given key
|
|
95
|
+
* @param key
|
|
96
|
+
* @param data
|
|
97
|
+
*/
|
|
98
|
+
async function sign(key, data) {
|
|
99
|
+
return window.crypto.subtle.sign(keygenAlgorithmOptions, key, data);
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
export {
|
|
102
|
+
export { createNewGuid, exportJwk, generateKeyPair, getRandomValues, importJwk, sha256Digest, sign, validateCryptoAvailable };
|
|
102
103
|
//# sourceMappingURL=BrowserCrypto.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserCrypto.mjs","sources":["../../src/crypto/BrowserCrypto.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BrowserCrypto.mjs","sources":["../../src/crypto/BrowserCrypto.ts"],"sourcesContent":[null],"names":["BrowserAuthErrorCodes.cryptoNonExistent"],"mappings":";;;;;;;;AAUA;AA+BA;;AAEG;AAaA;AACH;AAgBA;;;AAGG;AACH;AAIA;;;AAGG,MAAA,aAAA,GAAA,SAAA,CAAA;AACH;AAIA,MAAA,cAAA,GAAA,IAAA,CAAA;;;;AAIG,IAAA,IAAA,EAAA,oBAAA;AACH,IAAA,IAAA,EAAA,aAAA;AAWA,IAAA,aAAA,EAAA,cAAA;;;AAGG;AACH;AAOA;;;;;AAKG,SAAA;AACH,QAAsB,MAAA,CAAA,KAAA,CAAA,gDAEE,CAAA,CAAA;AAYxB,QAAA,MAAA,sBAAA,CAAAA,iBAAA,CAAA,CAAA;;;;AAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICrypto, IPerformanceClient, Logger,
|
|
1
|
+
import { ICrypto, IPerformanceClient, Logger, SignedHttpRequest, SignedHttpRequestParameters } from "@azure/msal-common";
|
|
2
2
|
export type CachedKeyPair = {
|
|
3
3
|
publicKey: CryptoKey;
|
|
4
4
|
privateKey: CryptoKey;
|
|
@@ -10,11 +10,6 @@ export type CachedKeyPair = {
|
|
|
10
10
|
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
|
11
11
|
*/
|
|
12
12
|
export declare class CryptoOps implements ICrypto {
|
|
13
|
-
private browserCrypto;
|
|
14
|
-
private guidGenerator;
|
|
15
|
-
private b64Encode;
|
|
16
|
-
private b64Decode;
|
|
17
|
-
private pkceGenerator;
|
|
18
13
|
private logger;
|
|
19
14
|
/**
|
|
20
15
|
* CryptoOps can be used in contexts outside a PCA instance,
|
|
@@ -40,10 +35,6 @@ export declare class CryptoOps implements ICrypto {
|
|
|
40
35
|
* @param input
|
|
41
36
|
*/
|
|
42
37
|
base64Decode(input: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
45
|
-
*/
|
|
46
|
-
generatePkceCodes(): Promise<PkceCodes>;
|
|
47
38
|
/**
|
|
48
39
|
* Generates a keypair, stores it and returns a thumbprint
|
|
49
40
|
* @param request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoOps.d.ts","sourceRoot":"","sources":["../../src/crypto/CryptoOps.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,OAAO,EACP,kBAAkB,EAElB,MAAM,EAEN,
|
|
1
|
+
{"version":3,"file":"CryptoOps.d.ts","sourceRoot":"","sources":["../../src/crypto/CryptoOps.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,OAAO,EACP,kBAAkB,EAElB,MAAM,EAEN,iBAAiB,EACjB,2BAA2B,EAC9B,MAAM,oBAAoB,CAAC;AAW5B,MAAM,MAAM,aAAa,GAAG;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,qBAAa,SAAU,YAAW,OAAO;IACrC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAiC;IAE1D,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuC;IACpE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAiB;IAC3C,OAAO,CAAC,KAAK,CAAiB;gBAElB,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,kBAAkB;IAQlE;;;OAGG;IACH,aAAa,IAAI,MAAM;IAIvB;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;;OAGG;IACG,sBAAsB,CACxB,OAAO,EAAE,2BAA2B,GACrC,OAAO,CAAC,MAAM,CAAC;IAqDlB;;;OAGG;IACG,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM1D;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIvC;;;;OAIG;IACG,OAAO,CACT,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE,MAAM,EACX,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC;IA0DlB;;;OAGG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAOvD"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.0
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { PerformanceEvents, JoseHeader } from '@azure/msal-common';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { PkceGenerator } from './PkceGenerator.mjs';
|
|
8
|
-
import { BrowserCrypto } from './BrowserCrypto.mjs';
|
|
4
|
+
import { base64Encode, urlEncode, urlEncodeArr } from '../encode/Base64Encode.mjs';
|
|
5
|
+
import { base64Decode } from '../encode/Base64Decode.mjs';
|
|
6
|
+
import { validateCryptoAvailable, createNewGuid, generateKeyPair, exportJwk, importJwk, sign, sha256Digest } from './BrowserCrypto.mjs';
|
|
9
7
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.mjs';
|
|
10
|
-
import {
|
|
8
|
+
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
11
9
|
import { CryptoKeyStore } from '../cache/CryptoKeyStore.mjs';
|
|
10
|
+
import { cryptoKeyNotFound } from '../error/BrowserAuthErrorCodes.mjs';
|
|
12
11
|
|
|
13
12
|
/*
|
|
14
13
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -22,11 +21,7 @@ class CryptoOps {
|
|
|
22
21
|
constructor(logger, performanceClient) {
|
|
23
22
|
this.logger = logger;
|
|
24
23
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
25
|
-
|
|
26
|
-
this.b64Encode = new Base64Encode();
|
|
27
|
-
this.b64Decode = new Base64Decode();
|
|
28
|
-
this.guidGenerator = new GuidGenerator(this.browserCrypto);
|
|
29
|
-
this.pkceGenerator = new PkceGenerator(this.browserCrypto);
|
|
24
|
+
validateCryptoAvailable(logger);
|
|
30
25
|
this.cache = new CryptoKeyStore(this.logger);
|
|
31
26
|
this.performanceClient = performanceClient;
|
|
32
27
|
}
|
|
@@ -35,27 +30,21 @@ class CryptoOps {
|
|
|
35
30
|
* @returns string (GUID)
|
|
36
31
|
*/
|
|
37
32
|
createNewGuid() {
|
|
38
|
-
return
|
|
33
|
+
return createNewGuid();
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
36
|
* Encodes input string to base64.
|
|
42
37
|
* @param input
|
|
43
38
|
*/
|
|
44
39
|
base64Encode(input) {
|
|
45
|
-
return
|
|
40
|
+
return base64Encode(input);
|
|
46
41
|
}
|
|
47
42
|
/**
|
|
48
43
|
* Decodes input string from base64.
|
|
49
44
|
* @param input
|
|
50
45
|
*/
|
|
51
46
|
base64Decode(input) {
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
56
|
-
*/
|
|
57
|
-
async generatePkceCodes() {
|
|
58
|
-
return this.pkceGenerator.generateCodes();
|
|
47
|
+
return base64Decode(input);
|
|
59
48
|
}
|
|
60
49
|
/**
|
|
61
50
|
* Generates a keypair, stores it and returns a thumbprint
|
|
@@ -64,9 +53,9 @@ class CryptoOps {
|
|
|
64
53
|
async getPublicKeyThumbprint(request) {
|
|
65
54
|
const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);
|
|
66
55
|
// Generate Keypair
|
|
67
|
-
const keyPair = await
|
|
56
|
+
const keyPair = await generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);
|
|
68
57
|
// Generate Thumbprint for Public Key
|
|
69
|
-
const publicKeyJwk = await
|
|
58
|
+
const publicKeyJwk = await exportJwk(keyPair.publicKey);
|
|
70
59
|
const pubKeyThumprintObj = {
|
|
71
60
|
e: publicKeyJwk.e,
|
|
72
61
|
kty: publicKeyJwk.kty,
|
|
@@ -75,9 +64,9 @@ class CryptoOps {
|
|
|
75
64
|
const publicJwkString = BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
|
|
76
65
|
const publicJwkHash = await this.hashString(publicJwkString);
|
|
77
66
|
// Generate Thumbprint for Private Key
|
|
78
|
-
const privateKeyJwk = await
|
|
67
|
+
const privateKeyJwk = await exportJwk(keyPair.privateKey);
|
|
79
68
|
// Re-import private key to make it unextractable
|
|
80
|
-
const unextractablePrivateKey = await
|
|
69
|
+
const unextractablePrivateKey = await importJwk(privateKeyJwk, false, ["sign"]);
|
|
81
70
|
// Store Keypair data in keystore
|
|
82
71
|
await this.cache.asymmetricKeys.setItem(publicJwkHash, {
|
|
83
72
|
privateKey: unextractablePrivateKey,
|
|
@@ -116,30 +105,30 @@ class CryptoOps {
|
|
|
116
105
|
const signJwtMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsSignJwt, correlationId);
|
|
117
106
|
const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);
|
|
118
107
|
if (!cachedKeyPair) {
|
|
119
|
-
throw
|
|
108
|
+
throw createBrowserAuthError(cryptoKeyNotFound);
|
|
120
109
|
}
|
|
121
110
|
// Get public key as JWK
|
|
122
|
-
const publicKeyJwk = await
|
|
111
|
+
const publicKeyJwk = await exportJwk(cachedKeyPair.publicKey);
|
|
123
112
|
const publicKeyJwkString = BrowserStringUtils.getSortedObjectString(publicKeyJwk);
|
|
124
113
|
// Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
|
|
125
|
-
const encodedKeyIdThumbprint =
|
|
114
|
+
const encodedKeyIdThumbprint = urlEncode(JSON.stringify({ kid: kid }));
|
|
126
115
|
// Generate header
|
|
127
116
|
const shrHeader = JoseHeader.getShrHeaderString({
|
|
128
117
|
kid: encodedKeyIdThumbprint,
|
|
129
118
|
alg: publicKeyJwk.alg,
|
|
130
119
|
});
|
|
131
|
-
const encodedShrHeader =
|
|
120
|
+
const encodedShrHeader = urlEncode(shrHeader);
|
|
132
121
|
// Generate payload
|
|
133
122
|
payload.cnf = {
|
|
134
123
|
jwk: JSON.parse(publicKeyJwkString),
|
|
135
124
|
};
|
|
136
|
-
const encodedPayload =
|
|
125
|
+
const encodedPayload = urlEncode(JSON.stringify(payload));
|
|
137
126
|
// Form token string
|
|
138
127
|
const tokenString = `${encodedShrHeader}.${encodedPayload}`;
|
|
139
128
|
// Sign token
|
|
140
129
|
const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
|
|
141
|
-
const signatureBuffer = await
|
|
142
|
-
const encodedSignature =
|
|
130
|
+
const signatureBuffer = await sign(cachedKeyPair.privateKey, tokenBuffer);
|
|
131
|
+
const encodedSignature = urlEncodeArr(new Uint8Array(signatureBuffer));
|
|
143
132
|
const signedJwt = `${tokenString}.${encodedSignature}`;
|
|
144
133
|
if (signJwtMeasurement) {
|
|
145
134
|
signJwtMeasurement.end({
|
|
@@ -153,9 +142,9 @@ class CryptoOps {
|
|
|
153
142
|
* @param plainText
|
|
154
143
|
*/
|
|
155
144
|
async hashString(plainText) {
|
|
156
|
-
const hashBuffer = await
|
|
145
|
+
const hashBuffer = await sha256Digest(plainText);
|
|
157
146
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
158
|
-
return
|
|
147
|
+
return urlEncodeArr(hashBytes);
|
|
159
148
|
}
|
|
160
149
|
}
|
|
161
150
|
CryptoOps.POP_KEY_USAGES = ["sign", "verify"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoOps.mjs","sources":["../../src/crypto/CryptoOps.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoOps.mjs","sources":["../../src/crypto/CryptoOps.ts"],"sourcesContent":[null],"names":["BrowserCrypto.validateCryptoAvailable","BrowserCrypto.generateKeyPair","BrowserCrypto.exportJwk"],"mappings":";;;;;;;;;;;AAKA;AAmBA;;;AAWA;;AAGI;;;AAGG,IAAA,WAAA,CAAA,MAAA,EAAA,iBAAA,EAAA;QACI,IAAC,iBAAiB;AAEzB;AACA,QAAAA,uBAA2C,CAAA,MAAA,CAAA,CAAA;QACpC,IAAC,MAAsB,GAAA,IAAA,cAAA,CAAA,IAAA,CAAA,MAAA,CAAA,CAAA;AAElB,QAAA,IAAA,CAAA,iBAAc,GAAmB,iBAAC;AAQ9C,KAAA;;;AAGG;AACH;AAIA,IAAA,aAAA,GAAA;;;AAGG;AACH;AAIA;;;AAGG,QAAA,OAAA,YAAA,CAAA,KAAA,CAAA,CAAA;AACH,KAAA;AAIA;;;AAGG;IACG,YAAsB,CAAA,KAAA,EAAA;AAuD5B,QAAA,OAAA,YAAA,CAAA,KAAA,CAAA,CAAA;;;AAGG;;AAOH;;AAEG,QAAA,MAAA,yBAAA,GAAA,IAAA,CAAA,iBAAA,EAAA,gBAAA,CAAA,iBAAA,CAAA,gCAAA,EAAA,OAAA,CAAA,aAAA,CAAA,CAAA;AACG;AAIN,QAAA,MAAA,OAAA,GAAA,MAAAC,eAAA,CAAA,SAAA,CAAA,WAAA,EAAA,SAAA,CAAA,cAAA,CAAA,CAAA;;;;AAIG,YAAA,CAAA,EAAA,YAAA,CAAA,CAAA;AACG,YACF,GAAO,EAAA,YAAmB,CAAA,GAAA;AA6D9B,YAAA,CAAA,EAAA,YAAA,CAAA,CAAA;;;AAGG,QAAA,MAAA,aAAA,GAAA,MAAA,IAAA,CAAA,UAAA,CAAA,eAAA,CAAA,CAAA;;AAQN,QAAA,MAAA,aAAA,GAAA,MAAAC,SAAA,CAAA,OAAA,CAAA,UAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import { PkceCodes } from "@azure/msal-common";
|
|
2
|
-
import { BrowserCrypto } from "./BrowserCrypto";
|
|
1
|
+
import { IPerformanceClient, Logger, PkceCodes } from "@azure/msal-common";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* This file defines APIs to generate PKCE codes and code verifiers.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
|
|
12
|
-
*/
|
|
13
|
-
generateCodes(): Promise<PkceCodes>;
|
|
14
|
-
/**
|
|
15
|
-
* Generates a random 32 byte buffer and returns the base64
|
|
16
|
-
* encoded string to be used as a PKCE Code Verifier
|
|
17
|
-
*/
|
|
18
|
-
private generateCodeVerifier;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a base64 encoded PKCE Code Challenge string from the
|
|
21
|
-
* hash created from the PKCE Code Verifier supplied
|
|
22
|
-
*/
|
|
23
|
-
private generateCodeChallengeFromVerifier;
|
|
24
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
|
|
7
|
+
*/
|
|
8
|
+
export declare function generatePkceCodes(performanceClient: IPerformanceClient, logger: Logger, correlationId: string): Promise<PkceCodes>;
|
|
25
9
|
//# sourceMappingURL=PkceGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PkceGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/PkceGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"PkceGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/PkceGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,kBAAkB,EAClB,MAAM,EAEN,SAAS,EAGZ,MAAM,oBAAoB,CAAC;AAW5B;;GAEG;AAEH;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,iBAAiB,EAAE,kBAAkB,EACrC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,SAAS,CAAC,CAuBpB"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.0
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PerformanceEvents, invoke, invokeAsync } from '@azure/msal-common';
|
|
4
|
+
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
5
|
+
import { urlEncodeArr } from '../encode/Base64Encode.mjs';
|
|
6
|
+
import { getRandomValues, sha256Digest } from './BrowserCrypto.mjs';
|
|
7
|
+
import { pkceNotCreated } from '../error/BrowserAuthErrorCodes.mjs';
|
|
5
8
|
|
|
6
9
|
/*
|
|
7
10
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -10,57 +13,53 @@ import { Base64Encode } from '../encode/Base64Encode.mjs';
|
|
|
10
13
|
// Constant byte array length
|
|
11
14
|
const RANDOM_BYTE_ARR_LENGTH = 32;
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* This file defines APIs to generate PKCE codes and code verifiers.
|
|
14
17
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
|
|
20
|
+
*/
|
|
21
|
+
async function generatePkceCodes(performanceClient, logger, correlationId) {
|
|
22
|
+
performanceClient.addQueueMeasurement(PerformanceEvents.GeneratePkceCodes, correlationId);
|
|
23
|
+
const codeVerifier = invoke(generateCodeVerifier, PerformanceEvents.GenerateCodeVerifier, logger, performanceClient, correlationId)(performanceClient, logger, correlationId);
|
|
24
|
+
const codeChallenge = await invokeAsync(generateCodeChallengeFromVerifier, PerformanceEvents.GenerateCodeChallengeFromVerifier, logger, performanceClient, correlationId)(codeVerifier, performanceClient, logger, correlationId);
|
|
25
|
+
return {
|
|
26
|
+
verifier: codeVerifier,
|
|
27
|
+
challenge: codeChallenge,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generates a random 32 byte buffer and returns the base64
|
|
32
|
+
* encoded string to be used as a PKCE Code Verifier
|
|
33
|
+
*/
|
|
34
|
+
function generateCodeVerifier(performanceClient, logger, correlationId) {
|
|
35
|
+
try {
|
|
36
|
+
// Generate random values as utf-8
|
|
37
|
+
const buffer = new Uint8Array(RANDOM_BYTE_ARR_LENGTH);
|
|
38
|
+
invoke(getRandomValues, PerformanceEvents.GetRandomValues, logger, performanceClient, correlationId)(buffer);
|
|
39
|
+
// encode verifier as base64
|
|
40
|
+
const pkceCodeVerifierB64 = urlEncodeArr(buffer);
|
|
41
|
+
return pkceCodeVerifierB64;
|
|
19
42
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
async generateCodes() {
|
|
24
|
-
const codeVerifier = this.generateCodeVerifier();
|
|
25
|
-
const codeChallenge = await this.generateCodeChallengeFromVerifier(codeVerifier);
|
|
26
|
-
return {
|
|
27
|
-
verifier: codeVerifier,
|
|
28
|
-
challenge: codeChallenge,
|
|
29
|
-
};
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw createBrowserAuthError(pkceNotCreated);
|
|
30
45
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
throw BrowserAuthError.createPkceNotGeneratedError(e);
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a base64 encoded PKCE Code Challenge string from the
|
|
49
|
+
* hash created from the PKCE Code Verifier supplied
|
|
50
|
+
*/
|
|
51
|
+
async function generateCodeChallengeFromVerifier(pkceCodeVerifier, performanceClient, logger, correlationId) {
|
|
52
|
+
performanceClient.addQueueMeasurement(PerformanceEvents.GenerateCodeChallengeFromVerifier, correlationId);
|
|
53
|
+
try {
|
|
54
|
+
// hashed verifier
|
|
55
|
+
const pkceHashedCodeVerifier = await invokeAsync(sha256Digest, PerformanceEvents.Sha256Digest, logger, performanceClient, correlationId)(pkceCodeVerifier, performanceClient, correlationId);
|
|
56
|
+
// encode hash as base64
|
|
57
|
+
return urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* hash created from the PKCE Code Verifier supplied
|
|
51
|
-
*/
|
|
52
|
-
async generateCodeChallengeFromVerifier(pkceCodeVerifier) {
|
|
53
|
-
try {
|
|
54
|
-
// hashed verifier
|
|
55
|
-
const pkceHashedCodeVerifier = await this.cryptoObj.sha256Digest(pkceCodeVerifier);
|
|
56
|
-
// encode hash as base64
|
|
57
|
-
return this.base64Encode.urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
throw BrowserAuthError.createPkceNotGeneratedError(e);
|
|
61
|
-
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw createBrowserAuthError(pkceNotCreated);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
export {
|
|
64
|
+
export { generatePkceCodes };
|
|
66
65
|
//# sourceMappingURL=PkceGenerator.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PkceGenerator.mjs","sources":["../../src/crypto/PkceGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PkceGenerator.mjs","sources":["../../src/crypto/PkceGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;AAKA;AAkBA;;AAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignedHttpRequest.mjs","sources":["../../src/crypto/SignedHttpRequest.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"SignedHttpRequest.mjs","sources":["../../src/crypto/SignedHttpRequest.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAMA;AAQA;;;AAOW,uBAA4C,CAAA;IACnD,yBAAuB,EAAA,UAAA,EAAA;AAGnB,QAAA,MAAA,aAAA,IAAe,UAA2B,IAAA,UAAA,CAAA,aAChC,KAA2B,EAAA,CAAA;AASzC,QAAA,IAAA,CAAA,MAAA,GAAA,IAAA,MAAA,CAAA,aAAA,EAAA,IAAA,EAAA,OAAA,CAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,aAAA,GAAA,aAAA,CAAA;AACG,KAAA;AAQN;;;;;;AAMG,QAAA,OAAA,GAAA,CAAA;AACG,KAAA;AAaN;;;;AAIG;;AAIN;;;;;;;;;;;;;;;;"}
|
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:
|
|
3
|
-
* https://developer.mozilla.org/en-US/docs/
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
decode(input: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Decodes base64 into Uint8Array
|
|
13
|
-
* @param base64String
|
|
14
|
-
* @param nBlockSize
|
|
15
|
-
*/
|
|
16
|
-
private base64DecToArr;
|
|
17
|
-
/**
|
|
18
|
-
* Base64 string to array decoding helper
|
|
19
|
-
* @param charNum
|
|
20
|
-
*/
|
|
21
|
-
private b64ToUint6;
|
|
22
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Returns a URL-safe plaintext decoded string from b64 encoded input.
|
|
7
|
+
* @param input
|
|
8
|
+
*/
|
|
9
|
+
export declare function base64Decode(input: string): string;
|
|
23
10
|
//# sourceMappingURL=Base64Decode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Decode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Base64Decode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Decode.ts"],"names":[],"mappings":"AAUA;;;GAGG;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD"}
|