@azure/msal-browser 3.1.0 → 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.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 +17 -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 +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 +3 -3
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +8 -7
- 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.map +1 -1
- package/dist/config/Configuration.mjs +7 -7
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/IController.d.ts +3 -2
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +11 -6
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +53 -34
- 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 +76 -76
- 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 +11 -19
- 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/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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -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/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +12 -10
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +1 -1
- package/dist/interaction_client/RedirectClient.mjs +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +5 -8
- 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 +10 -18
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +2 -2
- 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 +12 -33
- 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.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +3 -4
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- 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.mjs +1 -1
- 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/BrowserStringUtils.mjs +1 -1
- package/dist/utils/BrowserUtils.mjs +1 -1
- package/lib/msal-browser.cjs +1413 -1727
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +1413 -1727
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +68 -65
- package/package.json +2 -2
- package/src/app/IPublicClientApplication.ts +55 -18
- package/src/app/PublicClientApplication.ts +18 -6
- package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/BrowserCacheManager.ts +21 -6
- package/src/cache/BrowserStorage.ts +9 -11
- package/src/config/Configuration.ts +16 -8
- package/src/controllers/IController.ts +4 -1
- package/src/controllers/StandardController.ts +155 -92
- package/src/crypto/BrowserCrypto.ts +118 -102
- package/src/crypto/CryptoOps.ts +10 -22
- 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/event/EventHandler.ts +2 -1
- package/src/index.ts +5 -0
- package/src/interaction_client/BaseInteractionClient.ts +13 -7
- package/src/interaction_client/NativeInteractionClient.ts +29 -11
- package/src/interaction_client/SilentAuthCodeClient.ts +18 -16
- package/src/interaction_client/SilentCacheClient.ts +22 -30
- package/src/interaction_client/SilentIframeClient.ts +1 -1
- package/src/interaction_client/SilentRefreshClient.ts +26 -28
- package/src/interaction_client/StandardInteractionClient.ts +36 -67
- package/src/interaction_handler/InteractionHandler.ts +20 -15
- package/src/interaction_handler/RedirectHandler.ts +6 -2
- package/src/interaction_handler/SilentHandler.ts +6 -3
- package/src/packageMetadata.ts +1 -1
- package/src/utils/BrowserProtocolUtils.ts +3 -2
- 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/src/crypto/ISubtleCrypto.ts +0 -30
- package/src/crypto/ModernBrowserCrypto.ts +0 -69
|
@@ -1,50 +1,45 @@
|
|
|
1
|
-
import { Logger } from "@azure/msal-common";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* @param key
|
|
46
|
-
* @param data
|
|
47
|
-
*/
|
|
48
|
-
sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
49
|
-
}
|
|
1
|
+
import { IPerformanceClient, Logger } from "@azure/msal-common";
|
|
2
|
+
/**
|
|
3
|
+
* Check whether browser crypto is available.
|
|
4
|
+
*/
|
|
5
|
+
export declare function validateCryptoAvailable(logger: Logger): void;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a sha-256 hash of the given dataString as an ArrayBuffer.
|
|
8
|
+
* @param dataString
|
|
9
|
+
*/
|
|
10
|
+
export declare function sha256Digest(dataString: string, performanceClient?: IPerformanceClient, correlationId?: string): Promise<ArrayBuffer>;
|
|
11
|
+
/**
|
|
12
|
+
* Populates buffer with cryptographically random values.
|
|
13
|
+
* @param dataBuffer
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRandomValues(dataBuffer: Uint8Array): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new random GUID
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function createNewGuid(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a keypair based on current keygen algorithm config.
|
|
23
|
+
* @param extractable
|
|
24
|
+
* @param usages
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateKeyPair(extractable: boolean, usages: Array<KeyUsage>): Promise<CryptoKeyPair>;
|
|
27
|
+
/**
|
|
28
|
+
* Export key as Json Web Key (JWK)
|
|
29
|
+
* @param key
|
|
30
|
+
*/
|
|
31
|
+
export declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
|
|
32
|
+
/**
|
|
33
|
+
* Imports key as Json Web Key (JWK), can set extractable and usages.
|
|
34
|
+
* @param key
|
|
35
|
+
* @param extractable
|
|
36
|
+
* @param usages
|
|
37
|
+
*/
|
|
38
|
+
export declare function importJwk(key: JsonWebKey, extractable: boolean, usages: Array<KeyUsage>): Promise<CryptoKey>;
|
|
39
|
+
/**
|
|
40
|
+
* Signs given data with given key
|
|
41
|
+
* @param key
|
|
42
|
+
* @param data
|
|
43
|
+
*/
|
|
44
|
+
export declare function sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
50
45
|
//# sourceMappingURL=BrowserCrypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserCrypto.d.ts","sourceRoot":"","sources":["../../src/crypto/BrowserCrypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BrowserCrypto.d.ts","sourceRoot":"","sources":["../../src/crypto/BrowserCrypto.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,kBAAkB,EAClB,MAAM,EAET,MAAM,oBAAoB,CAAC;AA2B5B;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAO5D;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAC9B,UAAU,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,kBAAkB,EACtC,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAElE;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACjC,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,GACxB,OAAO,CAAC,aAAa,CAAC,CAMxB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAKnE;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC3B,GAAG,EAAE,UAAU,EACf,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,GACxB,OAAO,CAAC,SAAS,CAAC,CAQpB;AAED;;;;GAIG;AACH,wBAAsB,IAAI,CACtB,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,CAAC,CAMtB"}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.mjs';
|
|
4
4
|
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { PerformanceEvents } from '@azure/msal-common';
|
|
6
|
+
import { KEY_FORMAT_JWK } from '../utils/BrowserConstants.mjs';
|
|
6
7
|
import { cryptoNonExistent } from '../error/BrowserAuthErrorCodes.mjs';
|
|
7
8
|
|
|
8
9
|
/*
|
|
9
10
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
11
|
* Licensed under the MIT License.
|
|
11
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
|
+
*/
|
|
12
17
|
/**
|
|
13
18
|
* See here for more info on RsaHashedKeyGenParams: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
|
|
14
19
|
*/
|
|
@@ -20,84 +25,79 @@ const S256_HASH_ALG = "SHA-256";
|
|
|
20
25
|
const MODULUS_LENGTH = 2048;
|
|
21
26
|
// Public Exponent
|
|
22
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
|
+
};
|
|
23
34
|
/**
|
|
24
|
-
*
|
|
25
|
-
* hashing and encoding. It also has helper functions to validate the availability of specific APIs.
|
|
35
|
+
* Check whether browser crypto is available.
|
|
26
36
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (this.hasBrowserCrypto()) {
|
|
31
|
-
// Use standard modern web crypto if available
|
|
32
|
-
this.logger.verbose("BrowserCrypto: modern crypto interface available");
|
|
33
|
-
this.subtleCrypto = new ModernBrowserCrypto();
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
37
|
-
throw createBrowserAuthError(cryptoNonExistent);
|
|
38
|
-
}
|
|
39
|
-
this.keygenAlgorithmOptions = {
|
|
40
|
-
name: PKCS1_V15_KEYGEN_ALG,
|
|
41
|
-
hash: S256_HASH_ALG,
|
|
42
|
-
modulusLength: MODULUS_LENGTH,
|
|
43
|
-
publicExponent: PUBLIC_EXPONENT,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Check whether browser crypto is available.
|
|
48
|
-
*/
|
|
49
|
-
hasBrowserCrypto() {
|
|
50
|
-
return "crypto" in window;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns a sha-256 hash of the given dataString as an ArrayBuffer.
|
|
54
|
-
* @param dataString
|
|
55
|
-
*/
|
|
56
|
-
async sha256Digest(dataString) {
|
|
57
|
-
const data = BrowserStringUtils.stringToUtf8Arr(dataString);
|
|
58
|
-
// MSR Crypto wants object with name property, instead of string
|
|
59
|
-
return this.subtleCrypto.digest({ name: S256_HASH_ALG }, data);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Populates buffer with cryptographically random values.
|
|
63
|
-
* @param dataBuffer
|
|
64
|
-
*/
|
|
65
|
-
getRandomValues(dataBuffer) {
|
|
66
|
-
return this.subtleCrypto.getRandomValues(dataBuffer);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Generates a keypair based on current keygen algorithm config.
|
|
70
|
-
* @param extractable
|
|
71
|
-
* @param usages
|
|
72
|
-
*/
|
|
73
|
-
async generateKeyPair(extractable, usages) {
|
|
74
|
-
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");
|
|
75
40
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*/
|
|
80
|
-
async exportJwk(key) {
|
|
81
|
-
return this.subtleCrypto.exportKey(key);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Imports key as Json Web Key (JWK), can set extractable and usages.
|
|
85
|
-
* @param key
|
|
86
|
-
* @param extractable
|
|
87
|
-
* @param usages
|
|
88
|
-
*/
|
|
89
|
-
async importJwk(key, extractable, usages) {
|
|
90
|
-
return this.subtleCrypto.importKey(key, this.keygenAlgorithmOptions, extractable, usages);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Signs given data with given key
|
|
94
|
-
* @param key
|
|
95
|
-
* @param data
|
|
96
|
-
*/
|
|
97
|
-
async sign(key, data) {
|
|
98
|
-
return this.subtleCrypto.sign(this.keygenAlgorithmOptions, key, data);
|
|
41
|
+
else {
|
|
42
|
+
logger.error("BrowserCrypto: crypto interface is unavailable");
|
|
43
|
+
throw createBrowserAuthError(cryptoNonExistent);
|
|
99
44
|
}
|
|
100
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
|
+
}
|
|
101
101
|
|
|
102
|
-
export {
|
|
102
|
+
export { createNewGuid, exportJwk, generateKeyPair, getRandomValues, importJwk, sha256Digest, sign, validateCryptoAvailable };
|
|
103
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,8 +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 pkceGenerator;
|
|
15
13
|
private logger;
|
|
16
14
|
/**
|
|
17
15
|
* CryptoOps can be used in contexts outside a PCA instance,
|
|
@@ -37,10 +35,6 @@ export declare class CryptoOps implements ICrypto {
|
|
|
37
35
|
* @param input
|
|
38
36
|
*/
|
|
39
37
|
base64Decode(input: string): string;
|
|
40
|
-
/**
|
|
41
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
42
|
-
*/
|
|
43
|
-
generatePkceCodes(): Promise<PkceCodes>;
|
|
44
38
|
/**
|
|
45
39
|
* Generates a keypair, stores it and returns a thumbprint
|
|
46
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,10 +1,9 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { PerformanceEvents, JoseHeader } from '@azure/msal-common';
|
|
4
4
|
import { base64Encode, urlEncode, urlEncodeArr } from '../encode/Base64Encode.mjs';
|
|
5
5
|
import { base64Decode } from '../encode/Base64Decode.mjs';
|
|
6
|
-
import {
|
|
7
|
-
import { BrowserCrypto } from './BrowserCrypto.mjs';
|
|
6
|
+
import { validateCryptoAvailable, createNewGuid, generateKeyPair, exportJwk, importJwk, sign, sha256Digest } from './BrowserCrypto.mjs';
|
|
8
7
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.mjs';
|
|
9
8
|
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
10
9
|
import { CryptoKeyStore } from '../cache/CryptoKeyStore.mjs';
|
|
@@ -22,8 +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.pkceGenerator = new PkceGenerator(this.browserCrypto);
|
|
24
|
+
validateCryptoAvailable(logger);
|
|
27
25
|
this.cache = new CryptoKeyStore(this.logger);
|
|
28
26
|
this.performanceClient = performanceClient;
|
|
29
27
|
}
|
|
@@ -32,7 +30,7 @@ class CryptoOps {
|
|
|
32
30
|
* @returns string (GUID)
|
|
33
31
|
*/
|
|
34
32
|
createNewGuid() {
|
|
35
|
-
return
|
|
33
|
+
return createNewGuid();
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
36
|
* Encodes input string to base64.
|
|
@@ -48,12 +46,6 @@ class CryptoOps {
|
|
|
48
46
|
base64Decode(input) {
|
|
49
47
|
return base64Decode(input);
|
|
50
48
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
53
|
-
*/
|
|
54
|
-
async generatePkceCodes() {
|
|
55
|
-
return this.pkceGenerator.generateCodes();
|
|
56
|
-
}
|
|
57
49
|
/**
|
|
58
50
|
* Generates a keypair, stores it and returns a thumbprint
|
|
59
51
|
* @param request
|
|
@@ -61,9 +53,9 @@ class CryptoOps {
|
|
|
61
53
|
async getPublicKeyThumbprint(request) {
|
|
62
54
|
const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);
|
|
63
55
|
// Generate Keypair
|
|
64
|
-
const keyPair = await
|
|
56
|
+
const keyPair = await generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);
|
|
65
57
|
// Generate Thumbprint for Public Key
|
|
66
|
-
const publicKeyJwk = await
|
|
58
|
+
const publicKeyJwk = await exportJwk(keyPair.publicKey);
|
|
67
59
|
const pubKeyThumprintObj = {
|
|
68
60
|
e: publicKeyJwk.e,
|
|
69
61
|
kty: publicKeyJwk.kty,
|
|
@@ -72,9 +64,9 @@ class CryptoOps {
|
|
|
72
64
|
const publicJwkString = BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
|
|
73
65
|
const publicJwkHash = await this.hashString(publicJwkString);
|
|
74
66
|
// Generate Thumbprint for Private Key
|
|
75
|
-
const privateKeyJwk = await
|
|
67
|
+
const privateKeyJwk = await exportJwk(keyPair.privateKey);
|
|
76
68
|
// Re-import private key to make it unextractable
|
|
77
|
-
const unextractablePrivateKey = await
|
|
69
|
+
const unextractablePrivateKey = await importJwk(privateKeyJwk, false, ["sign"]);
|
|
78
70
|
// Store Keypair data in keystore
|
|
79
71
|
await this.cache.asymmetricKeys.setItem(publicJwkHash, {
|
|
80
72
|
privateKey: unextractablePrivateKey,
|
|
@@ -116,7 +108,7 @@ class CryptoOps {
|
|
|
116
108
|
throw createBrowserAuthError(cryptoKeyNotFound);
|
|
117
109
|
}
|
|
118
110
|
// Get public key as JWK
|
|
119
|
-
const publicKeyJwk = await
|
|
111
|
+
const publicKeyJwk = await exportJwk(cachedKeyPair.publicKey);
|
|
120
112
|
const publicKeyJwkString = BrowserStringUtils.getSortedObjectString(publicKeyJwk);
|
|
121
113
|
// Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
|
|
122
114
|
const encodedKeyIdThumbprint = urlEncode(JSON.stringify({ kid: kid }));
|
|
@@ -135,7 +127,7 @@ class CryptoOps {
|
|
|
135
127
|
const tokenString = `${encodedShrHeader}.${encodedPayload}`;
|
|
136
128
|
// Sign token
|
|
137
129
|
const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
|
|
138
|
-
const signatureBuffer = await
|
|
130
|
+
const signatureBuffer = await sign(cachedKeyPair.privateKey, tokenBuffer);
|
|
139
131
|
const encodedSignature = urlEncodeArr(new Uint8Array(signatureBuffer));
|
|
140
132
|
const signedJwt = `${tokenString}.${encodedSignature}`;
|
|
141
133
|
if (signJwtMeasurement) {
|
|
@@ -150,7 +142,7 @@ class CryptoOps {
|
|
|
150
142
|
* @param plainText
|
|
151
143
|
*/
|
|
152
144
|
async hashString(plainText) {
|
|
153
|
-
const hashBuffer = await
|
|
145
|
+
const hashBuffer = await sha256Digest(plainText);
|
|
154
146
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
155
147
|
return urlEncodeArr(hashBytes);
|
|
156
148
|
}
|
|
@@ -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,24 +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
|
-
* Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
|
|
11
|
-
*/
|
|
12
|
-
generateCodes(): Promise<PkceCodes>;
|
|
13
|
-
/**
|
|
14
|
-
* Generates a random 32 byte buffer and returns the base64
|
|
15
|
-
* encoded string to be used as a PKCE Code Verifier
|
|
16
|
-
*/
|
|
17
|
-
private generateCodeVerifier;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a base64 encoded PKCE Code Challenge string from the
|
|
20
|
-
* hash created from the PKCE Code Verifier supplied
|
|
21
|
-
*/
|
|
22
|
-
private generateCodeChallengeFromVerifier;
|
|
23
|
-
}
|
|
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>;
|
|
24
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,9 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { PerformanceEvents, invoke, invokeAsync } from '@azure/msal-common';
|
|
3
4
|
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
4
5
|
import { urlEncodeArr } from '../encode/Base64Encode.mjs';
|
|
6
|
+
import { getRandomValues, sha256Digest } from './BrowserCrypto.mjs';
|
|
5
7
|
import { pkceNotCreated } from '../error/BrowserAuthErrorCodes.mjs';
|
|
6
8
|
|
|
7
9
|
/*
|
|
@@ -11,56 +13,53 @@ import { pkceNotCreated } from '../error/BrowserAuthErrorCodes.mjs';
|
|
|
11
13
|
// Constant byte array length
|
|
12
14
|
const RANDOM_BYTE_ARR_LENGTH = 32;
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
16
|
+
* This file defines APIs to generate PKCE codes and code verifiers.
|
|
15
17
|
*/
|
|
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 createBrowserAuthError(pkceNotCreated);
|
|
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 urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
throw createBrowserAuthError(pkceNotCreated);
|
|
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":"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"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.
|
|
1
|
+
/*! @azure/msal-browser v3.2.0 2023-10-05 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
|
|
4
|
+
import { invalidBase64String } from '../error/BrowserAuthErrorCodes.mjs';
|
|
5
|
+
|
|
3
6
|
/*
|
|
4
7
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
8
|
* Licensed under the MIT License.
|
|
@@ -20,7 +23,20 @@ function base64Decode(input) {
|
|
|
20
23
|
* @param base64String
|
|
21
24
|
*/
|
|
22
25
|
function base64DecToArr(base64String) {
|
|
23
|
-
|
|
26
|
+
let encodedString = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
27
|
+
switch (encodedString.length % 4) {
|
|
28
|
+
case 0:
|
|
29
|
+
break;
|
|
30
|
+
case 2:
|
|
31
|
+
encodedString += "==";
|
|
32
|
+
break;
|
|
33
|
+
case 3:
|
|
34
|
+
encodedString += "=";
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw createBrowserAuthError(invalidBase64String);
|
|
38
|
+
}
|
|
39
|
+
const binString = atob(encodedString);
|
|
24
40
|
return Uint8Array.from(binString, (m) => m.codePointAt(0) || 0);
|
|
25
41
|
}
|
|
26
42
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Decode.mjs","sources":["../../src/encode/Base64Decode.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Base64Decode.mjs","sources":["../../src/encode/Base64Decode.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA;;;AAGG;;;AAKA;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|