@azure/msal-browser 3.0.0-alpha.1 → 3.0.0-alpha.2

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.
Files changed (142) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +213 -213
  3. package/dist/app/IPublicClientApplication.d.ts +45 -45
  4. package/dist/app/IPublicClientApplication.js +96 -96
  5. package/dist/app/PublicClientApplication.d.ts +244 -244
  6. package/dist/app/PublicClientApplication.js +307 -307
  7. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +63 -63
  8. package/dist/broker/nativeBroker/NativeMessageHandler.js +255 -255
  9. package/dist/broker/nativeBroker/NativeRequest.d.ts +43 -43
  10. package/dist/broker/nativeBroker/NativeResponse.d.ts +48 -48
  11. package/dist/cache/AsyncMemoryStorage.d.ts +51 -51
  12. package/dist/cache/AsyncMemoryStorage.js +132 -132
  13. package/dist/cache/BrowserCacheManager.d.ts +377 -377
  14. package/dist/cache/BrowserCacheManager.js +1276 -1276
  15. package/dist/cache/BrowserStorage.d.ts +11 -11
  16. package/dist/cache/BrowserStorage.js +35 -35
  17. package/dist/cache/CryptoKeyStore.d.ts +17 -17
  18. package/dist/cache/CryptoKeyStore.js +41 -41
  19. package/dist/cache/DatabaseStorage.d.ts +56 -56
  20. package/dist/cache/DatabaseStorage.js +190 -190
  21. package/dist/cache/IAsyncMemoryStorage.d.ts +27 -27
  22. package/dist/cache/ITokenCache.d.ts +10 -10
  23. package/dist/cache/IWindowStorage.d.ts +27 -27
  24. package/dist/cache/MemoryStorage.d.ts +11 -11
  25. package/dist/cache/MemoryStorage.js +31 -31
  26. package/dist/cache/TokenCache.d.ts +76 -76
  27. package/dist/cache/TokenCache.js +225 -225
  28. package/dist/config/Configuration.d.ts +203 -203
  29. package/dist/config/Configuration.js +101 -101
  30. package/dist/controllers/ControllerFactory.d.ts +9 -9
  31. package/dist/controllers/ControllerFactory.js +37 -37
  32. package/dist/controllers/IController.d.ts +66 -66
  33. package/dist/controllers/StandardController.d.ts +413 -413
  34. package/dist/controllers/StandardController.js +1272 -1272
  35. package/dist/crypto/BrowserCrypto.d.ts +61 -61
  36. package/dist/crypto/BrowserCrypto.js +131 -131
  37. package/dist/crypto/CryptoOps.d.ts +73 -73
  38. package/dist/crypto/CryptoOps.js +150 -150
  39. package/dist/crypto/GuidGenerator.d.ts +12 -12
  40. package/dist/crypto/GuidGenerator.js +96 -96
  41. package/dist/crypto/ISubtleCrypto.d.ts +9 -9
  42. package/dist/crypto/ModernBrowserCrypto.d.ts +9 -9
  43. package/dist/crypto/ModernBrowserCrypto.js +24 -24
  44. package/dist/crypto/MsBrowserCrypto.d.ts +9 -9
  45. package/dist/crypto/MsBrowserCrypto.js +79 -79
  46. package/dist/crypto/MsrBrowserCrypto.d.ts +17 -17
  47. package/dist/crypto/MsrBrowserCrypto.js +28 -28
  48. package/dist/crypto/PkceGenerator.d.ts +24 -24
  49. package/dist/crypto/PkceGenerator.js +58 -58
  50. package/dist/crypto/SignedHttpRequest.d.ts +30 -30
  51. package/dist/crypto/SignedHttpRequest.js +39 -39
  52. package/dist/encode/Base64Decode.d.ts +22 -22
  53. package/dist/encode/Base64Decode.js +73 -73
  54. package/dist/encode/Base64Encode.d.ts +31 -31
  55. package/dist/encode/Base64Encode.js +79 -79
  56. package/dist/error/BrowserAuthError.d.ts +382 -382
  57. package/dist/error/BrowserAuthError.js +483 -483
  58. package/dist/error/BrowserConfigurationAuthError.d.ts +70 -70
  59. package/dist/error/BrowserConfigurationAuthError.js +96 -96
  60. package/dist/error/NativeAuthError.d.ts +56 -56
  61. package/dist/error/NativeAuthError.js +88 -88
  62. package/dist/event/EventHandler.d.ts +41 -41
  63. package/dist/event/EventHandler.js +119 -119
  64. package/dist/event/EventMessage.d.ts +25 -25
  65. package/dist/event/EventMessage.js +67 -67
  66. package/dist/event/EventType.d.ts +26 -26
  67. package/dist/event/EventType.js +31 -31
  68. package/dist/index.d.ts +35 -35
  69. package/dist/index.js +1 -1
  70. package/dist/interaction_client/BaseInteractionClient.d.ts +52 -52
  71. package/dist/interaction_client/BaseInteractionClient.js +138 -138
  72. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts +4 -4
  73. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +10 -10
  74. package/dist/interaction_client/NativeInteractionClient.d.ts +148 -148
  75. package/dist/interaction_client/NativeInteractionClient.js +516 -516
  76. package/dist/interaction_client/PopupClient.d.ts +111 -111
  77. package/dist/interaction_client/PopupClient.js +476 -476
  78. package/dist/interaction_client/RedirectClient.d.ts +48 -48
  79. package/dist/interaction_client/RedirectClient.js +290 -290
  80. package/dist/interaction_client/SilentAuthCodeClient.d.ts +22 -22
  81. package/dist/interaction_client/SilentAuthCodeClient.js +62 -62
  82. package/dist/interaction_client/SilentCacheClient.d.ts +21 -21
  83. package/dist/interaction_client/SilentCacheClient.js +67 -67
  84. package/dist/interaction_client/SilentIframeClient.d.ts +31 -31
  85. package/dist/interaction_client/SilentIframeClient.js +127 -127
  86. package/dist/interaction_client/SilentRefreshClient.d.ts +19 -19
  87. package/dist/interaction_client/SilentRefreshClient.js +62 -62
  88. package/dist/interaction_client/StandardInteractionClient.d.ts +59 -59
  89. package/dist/interaction_client/StandardInteractionClient.js +259 -259
  90. package/dist/interaction_handler/InteractionHandler.d.ts +39 -39
  91. package/dist/interaction_handler/InteractionHandler.js +127 -127
  92. package/dist/interaction_handler/RedirectHandler.d.ts +24 -24
  93. package/dist/interaction_handler/RedirectHandler.js +118 -118
  94. package/dist/interaction_handler/SilentHandler.d.ts +47 -47
  95. package/dist/interaction_handler/SilentHandler.js +162 -162
  96. package/dist/internals.d.ts +23 -23
  97. package/dist/internals.js +4 -4
  98. package/dist/navigation/INavigationClient.d.ts +16 -16
  99. package/dist/navigation/NavigationClient.d.ts +22 -22
  100. package/dist/navigation/NavigationClient.js +40 -40
  101. package/dist/navigation/NavigationOptions.d.ts +12 -12
  102. package/dist/network/FetchClient.d.ts +26 -26
  103. package/dist/network/FetchClient.js +99 -99
  104. package/dist/network/XhrClient.d.ts +40 -40
  105. package/dist/network/XhrClient.js +117 -117
  106. package/dist/operatingcontext/BaseOperatingContext.d.ts +40 -40
  107. package/dist/operatingcontext/BaseOperatingContext.js +44 -44
  108. package/dist/operatingcontext/StandardOperatingContext.d.ts +25 -25
  109. package/dist/operatingcontext/StandardOperatingContext.js +43 -43
  110. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +25 -25
  111. package/dist/operatingcontext/TeamsAppOperatingContext.js +42 -42
  112. package/dist/packageMetadata.d.ts +2 -2
  113. package/dist/packageMetadata.js +4 -4
  114. package/dist/request/AuthorizationCodeRequest.d.ts +8 -8
  115. package/dist/request/AuthorizationUrlRequest.d.ts +8 -8
  116. package/dist/request/EndSessionPopupRequest.d.ts +18 -18
  117. package/dist/request/EndSessionRequest.d.ts +15 -15
  118. package/dist/request/PopupRequest.d.ts +32 -32
  119. package/dist/request/PopupWindowAttributes.d.ts +15 -15
  120. package/dist/request/RedirectRequest.d.ts +33 -33
  121. package/dist/request/SilentRequest.d.ts +30 -30
  122. package/dist/request/SsoSilentRequest.d.ts +26 -26
  123. package/dist/telemetry/BrowserPerformanceClient.d.ts +38 -38
  124. package/dist/telemetry/BrowserPerformanceClient.js +124 -124
  125. package/dist/telemetry/BrowserPerformanceMeasurement.d.ts +21 -21
  126. package/dist/telemetry/BrowserPerformanceMeasurement.js +92 -92
  127. package/dist/utils/BrowserConstants.d.ts +166 -166
  128. package/dist/utils/BrowserConstants.js +214 -214
  129. package/dist/utils/BrowserProtocolUtils.d.ts +18 -18
  130. package/dist/utils/BrowserProtocolUtils.js +34 -34
  131. package/dist/utils/BrowserStringUtils.d.ts +26 -26
  132. package/dist/utils/BrowserStringUtils.js +149 -149
  133. package/dist/utils/BrowserUtils.d.ts +65 -65
  134. package/dist/utils/BrowserUtils.js +138 -138
  135. package/dist/utils/MathUtils.d.ts +11 -11
  136. package/dist/utils/MathUtils.js +21 -21
  137. package/lib/msal-browser.cjs.js +18383 -0
  138. package/lib/msal-browser.cjs.js.map +1 -0
  139. package/lib/msal-browser.js +18389 -0
  140. package/lib/msal-browser.js.map +1 -0
  141. package/lib/msal-browser.min.js +74 -0
  142. package/package.json +97 -95
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v3.0.0-alpha.1 2023-05-08 */
1
+ /*! @azure/msal-browser v3.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import { PerformanceEvents, JoseHeader } from '@azure/msal-common';
4
4
  import { GuidGenerator } from './GuidGenerator.js';
@@ -10,155 +10,155 @@ import { BrowserStringUtils } from '../utils/BrowserStringUtils.js';
10
10
  import { BrowserAuthError } from '../error/BrowserAuthError.js';
11
11
  import { CryptoKeyStore } from '../cache/CryptoKeyStore.js';
12
12
 
13
- /*
14
- * Copyright (c) Microsoft Corporation. All rights reserved.
15
- * Licensed under the MIT License.
16
- */
17
- /**
18
- * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
19
- * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
20
- */
21
- class CryptoOps {
22
- constructor(logger, performanceClient, cryptoConfig) {
23
- this.logger = logger;
24
- // Browser crypto needs to be validated first before any other classes can be set.
25
- this.browserCrypto = new BrowserCrypto(this.logger, cryptoConfig);
26
- this.b64Encode = new Base64Encode();
27
- this.b64Decode = new Base64Decode();
28
- this.guidGenerator = new GuidGenerator(this.browserCrypto);
29
- this.pkceGenerator = new PkceGenerator(this.browserCrypto);
30
- this.cache = new CryptoKeyStore(this.logger);
31
- this.performanceClient = performanceClient;
32
- }
33
- /**
34
- * Creates a new random GUID - used to populate state and nonce.
35
- * @returns string (GUID)
36
- */
37
- createNewGuid() {
38
- return this.guidGenerator.generateGuid();
39
- }
40
- /**
41
- * Encodes input string to base64.
42
- * @param input
43
- */
44
- base64Encode(input) {
45
- return this.b64Encode.encode(input);
46
- }
47
- /**
48
- * Decodes input string from base64.
49
- * @param input
50
- */
51
- base64Decode(input) {
52
- return this.b64Decode.decode(input);
53
- }
54
- /**
55
- * Generates PKCE codes used in Authorization Code Flow.
56
- */
57
- async generatePkceCodes() {
58
- return this.pkceGenerator.generateCodes();
59
- }
60
- /**
61
- * Generates a keypair, stores it and returns a thumbprint
62
- * @param request
63
- */
64
- async getPublicKeyThumbprint(request) {
65
- const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);
66
- // Generate Keypair
67
- const keyPair = await this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);
68
- // Generate Thumbprint for Public Key
69
- const publicKeyJwk = await this.browserCrypto.exportJwk(keyPair.publicKey);
70
- const pubKeyThumprintObj = {
71
- e: publicKeyJwk.e,
72
- kty: publicKeyJwk.kty,
73
- n: publicKeyJwk.n,
74
- };
75
- const publicJwkString = BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
76
- const publicJwkHash = await this.hashString(publicJwkString);
77
- // Generate Thumbprint for Private Key
78
- const privateKeyJwk = await this.browserCrypto.exportJwk(keyPair.privateKey);
79
- // Re-import private key to make it unextractable
80
- const unextractablePrivateKey = await this.browserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
81
- // Store Keypair data in keystore
82
- await this.cache.asymmetricKeys.setItem(publicJwkHash, {
83
- privateKey: unextractablePrivateKey,
84
- publicKey: keyPair.publicKey,
85
- requestMethod: request.resourceRequestMethod,
86
- requestUri: request.resourceRequestUri,
87
- });
88
- if (publicKeyThumbMeasurement) {
89
- publicKeyThumbMeasurement.endMeasurement({
90
- success: true,
91
- });
92
- }
93
- return publicJwkHash;
94
- }
95
- /**
96
- * Removes cryptographic keypair from key store matching the keyId passed in
97
- * @param kid
98
- */
99
- async removeTokenBindingKey(kid) {
100
- await this.cache.asymmetricKeys.removeItem(kid);
101
- const keyFound = await this.cache.asymmetricKeys.containsKey(kid);
102
- return !keyFound;
103
- }
104
- /**
105
- * Removes all cryptographic keys from IndexedDB storage
106
- */
107
- async clearKeystore() {
108
- return await this.cache.clear();
109
- }
110
- /**
111
- * Signs the given object as a jwt payload with private key retrieved by given kid.
112
- * @param payload
113
- * @param kid
114
- */
115
- async signJwt(payload, kid, correlationId) {
116
- const signJwtMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsSignJwt, correlationId);
117
- const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);
118
- if (!cachedKeyPair) {
119
- throw BrowserAuthError.createSigningKeyNotFoundInStorageError(kid);
120
- }
121
- // Get public key as JWK
122
- const publicKeyJwk = await this.browserCrypto.exportJwk(cachedKeyPair.publicKey);
123
- const publicKeyJwkString = BrowserStringUtils.getSortedObjectString(publicKeyJwk);
124
- // Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
125
- const encodedKeyIdThumbprint = this.b64Encode.urlEncode(JSON.stringify({ kid: kid }));
126
- // Generate header
127
- const shrHeader = JoseHeader.getShrHeaderString({
128
- kid: encodedKeyIdThumbprint,
129
- alg: publicKeyJwk.alg,
130
- });
131
- const encodedShrHeader = this.b64Encode.urlEncode(shrHeader);
132
- // Generate payload
133
- payload.cnf = {
134
- jwk: JSON.parse(publicKeyJwkString),
135
- };
136
- const encodedPayload = this.b64Encode.urlEncode(JSON.stringify(payload));
137
- // Form token string
138
- const tokenString = `${encodedShrHeader}.${encodedPayload}`;
139
- // Sign token
140
- const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);
141
- const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);
142
- const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));
143
- const signedJwt = `${tokenString}.${encodedSignature}`;
144
- if (signJwtMeasurement) {
145
- signJwtMeasurement.endMeasurement({
146
- success: true,
147
- });
148
- }
149
- return signedJwt;
150
- }
151
- /**
152
- * Returns the SHA-256 hash of an input string
153
- * @param plainText
154
- */
155
- async hashString(plainText) {
156
- const hashBuffer = await this.browserCrypto.sha256Digest(plainText);
157
- const hashBytes = new Uint8Array(hashBuffer);
158
- return this.b64Encode.urlEncodeArr(hashBytes);
159
- }
160
- }
161
- CryptoOps.POP_KEY_USAGES = ["sign", "verify"];
13
+ /*
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License.
16
+ */
17
+ /**
18
+ * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
19
+ * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
20
+ */
21
+ class CryptoOps {
22
+ constructor(logger, performanceClient, cryptoConfig) {
23
+ this.logger = logger;
24
+ // Browser crypto needs to be validated first before any other classes can be set.
25
+ this.browserCrypto = new BrowserCrypto(this.logger, cryptoConfig);
26
+ this.b64Encode = new Base64Encode();
27
+ this.b64Decode = new Base64Decode();
28
+ this.guidGenerator = new GuidGenerator(this.browserCrypto);
29
+ this.pkceGenerator = new PkceGenerator(this.browserCrypto);
30
+ this.cache = new CryptoKeyStore(this.logger);
31
+ this.performanceClient = performanceClient;
32
+ }
33
+ /**
34
+ * Creates a new random GUID - used to populate state and nonce.
35
+ * @returns string (GUID)
36
+ */
37
+ createNewGuid() {
38
+ return this.guidGenerator.generateGuid();
39
+ }
40
+ /**
41
+ * Encodes input string to base64.
42
+ * @param input
43
+ */
44
+ base64Encode(input) {
45
+ return this.b64Encode.encode(input);
46
+ }
47
+ /**
48
+ * Decodes input string from base64.
49
+ * @param input
50
+ */
51
+ base64Decode(input) {
52
+ return this.b64Decode.decode(input);
53
+ }
54
+ /**
55
+ * Generates PKCE codes used in Authorization Code Flow.
56
+ */
57
+ async generatePkceCodes() {
58
+ return this.pkceGenerator.generateCodes();
59
+ }
60
+ /**
61
+ * Generates a keypair, stores it and returns a thumbprint
62
+ * @param request
63
+ */
64
+ async getPublicKeyThumbprint(request) {
65
+ const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);
66
+ // Generate Keypair
67
+ const keyPair = await this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);
68
+ // Generate Thumbprint for Public Key
69
+ const publicKeyJwk = await this.browserCrypto.exportJwk(keyPair.publicKey);
70
+ const pubKeyThumprintObj = {
71
+ e: publicKeyJwk.e,
72
+ kty: publicKeyJwk.kty,
73
+ n: publicKeyJwk.n,
74
+ };
75
+ const publicJwkString = BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
76
+ const publicJwkHash = await this.hashString(publicJwkString);
77
+ // Generate Thumbprint for Private Key
78
+ const privateKeyJwk = await this.browserCrypto.exportJwk(keyPair.privateKey);
79
+ // Re-import private key to make it unextractable
80
+ const unextractablePrivateKey = await this.browserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
81
+ // Store Keypair data in keystore
82
+ await this.cache.asymmetricKeys.setItem(publicJwkHash, {
83
+ privateKey: unextractablePrivateKey,
84
+ publicKey: keyPair.publicKey,
85
+ requestMethod: request.resourceRequestMethod,
86
+ requestUri: request.resourceRequestUri,
87
+ });
88
+ if (publicKeyThumbMeasurement) {
89
+ publicKeyThumbMeasurement.endMeasurement({
90
+ success: true,
91
+ });
92
+ }
93
+ return publicJwkHash;
94
+ }
95
+ /**
96
+ * Removes cryptographic keypair from key store matching the keyId passed in
97
+ * @param kid
98
+ */
99
+ async removeTokenBindingKey(kid) {
100
+ await this.cache.asymmetricKeys.removeItem(kid);
101
+ const keyFound = await this.cache.asymmetricKeys.containsKey(kid);
102
+ return !keyFound;
103
+ }
104
+ /**
105
+ * Removes all cryptographic keys from IndexedDB storage
106
+ */
107
+ async clearKeystore() {
108
+ return await this.cache.clear();
109
+ }
110
+ /**
111
+ * Signs the given object as a jwt payload with private key retrieved by given kid.
112
+ * @param payload
113
+ * @param kid
114
+ */
115
+ async signJwt(payload, kid, correlationId) {
116
+ const signJwtMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsSignJwt, correlationId);
117
+ const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);
118
+ if (!cachedKeyPair) {
119
+ throw BrowserAuthError.createSigningKeyNotFoundInStorageError(kid);
120
+ }
121
+ // Get public key as JWK
122
+ const publicKeyJwk = await this.browserCrypto.exportJwk(cachedKeyPair.publicKey);
123
+ const publicKeyJwkString = BrowserStringUtils.getSortedObjectString(publicKeyJwk);
124
+ // Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
125
+ const encodedKeyIdThumbprint = this.b64Encode.urlEncode(JSON.stringify({ kid: kid }));
126
+ // Generate header
127
+ const shrHeader = JoseHeader.getShrHeaderString({
128
+ kid: encodedKeyIdThumbprint,
129
+ alg: publicKeyJwk.alg,
130
+ });
131
+ const encodedShrHeader = this.b64Encode.urlEncode(shrHeader);
132
+ // Generate payload
133
+ payload.cnf = {
134
+ jwk: JSON.parse(publicKeyJwkString),
135
+ };
136
+ const encodedPayload = this.b64Encode.urlEncode(JSON.stringify(payload));
137
+ // Form token string
138
+ const tokenString = `${encodedShrHeader}.${encodedPayload}`;
139
+ // Sign token
140
+ const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);
141
+ const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);
142
+ const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));
143
+ const signedJwt = `${tokenString}.${encodedSignature}`;
144
+ if (signJwtMeasurement) {
145
+ signJwtMeasurement.endMeasurement({
146
+ success: true,
147
+ });
148
+ }
149
+ return signedJwt;
150
+ }
151
+ /**
152
+ * Returns the SHA-256 hash of an input string
153
+ * @param plainText
154
+ */
155
+ async hashString(plainText) {
156
+ const hashBuffer = await this.browserCrypto.sha256Digest(plainText);
157
+ const hashBytes = new Uint8Array(hashBuffer);
158
+ return this.b64Encode.urlEncodeArr(hashBytes);
159
+ }
160
+ }
161
+ CryptoOps.POP_KEY_USAGES = ["sign", "verify"];
162
162
  CryptoOps.EXTRACTABLE = true;
163
163
 
164
164
  export { CryptoOps };
@@ -1,13 +1,13 @@
1
- import { IGuidGenerator } from "@azure/msal-common";
2
- import { BrowserCrypto } from "./BrowserCrypto";
3
- export declare class GuidGenerator implements IGuidGenerator {
4
- private cryptoObj;
5
- constructor(cryptoObj: BrowserCrypto);
6
- generateGuid(): string;
7
- /**
8
- * verifies if a string is GUID
9
- * @param guid
10
- */
11
- isGuid(guid: string): boolean;
12
- }
1
+ import { IGuidGenerator } from "@azure/msal-common";
2
+ import { BrowserCrypto } from "./BrowserCrypto";
3
+ export declare class GuidGenerator implements IGuidGenerator {
4
+ private cryptoObj;
5
+ constructor(cryptoObj: BrowserCrypto);
6
+ generateGuid(): string;
7
+ /**
8
+ * verifies if a string is GUID
9
+ * @param guid
10
+ */
11
+ isGuid(guid: string): boolean;
12
+ }
13
13
  //# sourceMappingURL=GuidGenerator.d.ts.map
@@ -1,103 +1,103 @@
1
- /*! @azure/msal-browser v3.0.0-alpha.1 2023-05-08 */
1
+ /*! @azure/msal-browser v3.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import { Constants } from '@azure/msal-common';
4
4
  import { MathUtils } from '../utils/MathUtils.js';
5
5
 
6
- /*
7
- * Copyright (c) Microsoft Corporation. All rights reserved.
8
- * Licensed under the MIT License.
9
- */
10
- class GuidGenerator {
11
- constructor(cryptoObj) {
12
- this.cryptoObj = cryptoObj;
13
- }
14
- /*
15
- * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or
16
- * pseudo-random numbers.
17
- * The algorithm is as follows:
18
- * Set the two most significant bits (bits 6 and 7) of the
19
- * clock_seq_hi_and_reserved to zero and one, respectively.
20
- * Set the four most significant bits (bits 12 through 15) of the
21
- * time_hi_and_version field to the 4-bit version number from
22
- * Section 4.1.3. Version4
23
- * Set all the other bits to randomly (or pseudo-randomly) chosen
24
- * values.
25
- * UUID = time-low "-" time-mid "-"time-high-and-version "-"clock-seq-reserved and low(2hexOctet)"-" node
26
- * time-low = 4hexOctet
27
- * time-mid = 2hexOctet
28
- * time-high-and-version = 2hexOctet
29
- * clock-seq-and-reserved = hexOctet:
30
- * clock-seq-low = hexOctet
31
- * node = 6hexOctet
32
- * Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
33
- * y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10
34
- * y values are 8, 9, A, B
35
- */
36
- generateGuid() {
37
- try {
38
- const buffer = new Uint8Array(16);
39
- this.cryptoObj.getRandomValues(buffer);
40
- // buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).
41
- buffer[6] |= 0x40; // buffer[6] | 01000000 will set the 6 bit to 1.
42
- buffer[6] &= 0x4f; // buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = "4".
43
- // buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.
44
- buffer[8] |= 0x80; // buffer[8] | 10000000 will set the 7 bit to 1.
45
- buffer[8] &= 0xbf; // buffer[8] & 10111111 will set the 6 bit to 0.
46
- return (MathUtils.decimalToHex(buffer[0]) +
47
- MathUtils.decimalToHex(buffer[1]) +
48
- MathUtils.decimalToHex(buffer[2]) +
49
- MathUtils.decimalToHex(buffer[3]) +
50
- "-" +
51
- MathUtils.decimalToHex(buffer[4]) +
52
- MathUtils.decimalToHex(buffer[5]) +
53
- "-" +
54
- MathUtils.decimalToHex(buffer[6]) +
55
- MathUtils.decimalToHex(buffer[7]) +
56
- "-" +
57
- MathUtils.decimalToHex(buffer[8]) +
58
- MathUtils.decimalToHex(buffer[9]) +
59
- "-" +
60
- MathUtils.decimalToHex(buffer[10]) +
61
- MathUtils.decimalToHex(buffer[11]) +
62
- MathUtils.decimalToHex(buffer[12]) +
63
- MathUtils.decimalToHex(buffer[13]) +
64
- MathUtils.decimalToHex(buffer[14]) +
65
- MathUtils.decimalToHex(buffer[15]));
66
- }
67
- catch (err) {
68
- const guidHolder = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
69
- const hex = "0123456789abcdef";
70
- let r = 0;
71
- let guidResponse = Constants.EMPTY_STRING;
72
- for (let i = 0; i < 36; i++) {
73
- if (guidHolder[i] !== "-" && guidHolder[i] !== "4") {
74
- // each x and y needs to be random
75
- r = (Math.random() * 16) | 0;
76
- }
77
- if (guidHolder[i] === "x") {
78
- guidResponse += hex[r];
79
- }
80
- else if (guidHolder[i] === "y") {
81
- // clock-seq-and-reserved first hex is filtered and remaining hex values are random
82
- r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??
83
- r |= 0x8; // set pos 3 to 1 as 1???
84
- guidResponse += hex[r];
85
- }
86
- else {
87
- guidResponse += guidHolder[i];
88
- }
89
- }
90
- return guidResponse;
91
- }
92
- }
93
- /**
94
- * verifies if a string is GUID
95
- * @param guid
96
- */
97
- isGuid(guid) {
98
- const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
99
- return regexGuid.test(guid);
100
- }
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ class GuidGenerator {
11
+ constructor(cryptoObj) {
12
+ this.cryptoObj = cryptoObj;
13
+ }
14
+ /*
15
+ * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or
16
+ * pseudo-random numbers.
17
+ * The algorithm is as follows:
18
+ * Set the two most significant bits (bits 6 and 7) of the
19
+ * clock_seq_hi_and_reserved to zero and one, respectively.
20
+ * Set the four most significant bits (bits 12 through 15) of the
21
+ * time_hi_and_version field to the 4-bit version number from
22
+ * Section 4.1.3. Version4
23
+ * Set all the other bits to randomly (or pseudo-randomly) chosen
24
+ * values.
25
+ * UUID = time-low "-" time-mid "-"time-high-and-version "-"clock-seq-reserved and low(2hexOctet)"-" node
26
+ * time-low = 4hexOctet
27
+ * time-mid = 2hexOctet
28
+ * time-high-and-version = 2hexOctet
29
+ * clock-seq-and-reserved = hexOctet:
30
+ * clock-seq-low = hexOctet
31
+ * node = 6hexOctet
32
+ * Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
33
+ * y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10
34
+ * y values are 8, 9, A, B
35
+ */
36
+ generateGuid() {
37
+ try {
38
+ const buffer = new Uint8Array(16);
39
+ this.cryptoObj.getRandomValues(buffer);
40
+ // buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).
41
+ buffer[6] |= 0x40; // buffer[6] | 01000000 will set the 6 bit to 1.
42
+ buffer[6] &= 0x4f; // buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = "4".
43
+ // buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.
44
+ buffer[8] |= 0x80; // buffer[8] | 10000000 will set the 7 bit to 1.
45
+ buffer[8] &= 0xbf; // buffer[8] & 10111111 will set the 6 bit to 0.
46
+ return (MathUtils.decimalToHex(buffer[0]) +
47
+ MathUtils.decimalToHex(buffer[1]) +
48
+ MathUtils.decimalToHex(buffer[2]) +
49
+ MathUtils.decimalToHex(buffer[3]) +
50
+ "-" +
51
+ MathUtils.decimalToHex(buffer[4]) +
52
+ MathUtils.decimalToHex(buffer[5]) +
53
+ "-" +
54
+ MathUtils.decimalToHex(buffer[6]) +
55
+ MathUtils.decimalToHex(buffer[7]) +
56
+ "-" +
57
+ MathUtils.decimalToHex(buffer[8]) +
58
+ MathUtils.decimalToHex(buffer[9]) +
59
+ "-" +
60
+ MathUtils.decimalToHex(buffer[10]) +
61
+ MathUtils.decimalToHex(buffer[11]) +
62
+ MathUtils.decimalToHex(buffer[12]) +
63
+ MathUtils.decimalToHex(buffer[13]) +
64
+ MathUtils.decimalToHex(buffer[14]) +
65
+ MathUtils.decimalToHex(buffer[15]));
66
+ }
67
+ catch (err) {
68
+ const guidHolder = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
69
+ const hex = "0123456789abcdef";
70
+ let r = 0;
71
+ let guidResponse = Constants.EMPTY_STRING;
72
+ for (let i = 0; i < 36; i++) {
73
+ if (guidHolder[i] !== "-" && guidHolder[i] !== "4") {
74
+ // each x and y needs to be random
75
+ r = (Math.random() * 16) | 0;
76
+ }
77
+ if (guidHolder[i] === "x") {
78
+ guidResponse += hex[r];
79
+ }
80
+ else if (guidHolder[i] === "y") {
81
+ // clock-seq-and-reserved first hex is filtered and remaining hex values are random
82
+ r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??
83
+ r |= 0x8; // set pos 3 to 1 as 1???
84
+ guidResponse += hex[r];
85
+ }
86
+ else {
87
+ guidResponse += guidHolder[i];
88
+ }
89
+ }
90
+ return guidResponse;
91
+ }
92
+ }
93
+ /**
94
+ * verifies if a string is GUID
95
+ * @param guid
96
+ */
97
+ isGuid(guid) {
98
+ const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
99
+ return regexGuid.test(guid);
100
+ }
101
101
  }
102
102
 
103
103
  export { GuidGenerator };
@@ -1,10 +1,10 @@
1
- export interface ISubtleCrypto {
2
- initPrng?(entropy: Uint8Array): void;
3
- getRandomValues(dataBuffer: Uint8Array): Uint8Array;
4
- generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
5
- exportKey(key: CryptoKey): Promise<JsonWebKey>;
6
- importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
7
- sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
8
- digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise<ArrayBuffer>;
9
- }
1
+ export interface ISubtleCrypto {
2
+ initPrng?(entropy: Uint8Array): void;
3
+ getRandomValues(dataBuffer: Uint8Array): Uint8Array;
4
+ generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
5
+ exportKey(key: CryptoKey): Promise<JsonWebKey>;
6
+ importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
7
+ sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
8
+ digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise<ArrayBuffer>;
9
+ }
10
10
  //# sourceMappingURL=ISubtleCrypto.d.ts.map
@@ -1,10 +1,10 @@
1
- import { ISubtleCrypto } from "./ISubtleCrypto";
2
- export declare class ModernBrowserCrypto implements ISubtleCrypto {
3
- getRandomValues(dataBuffer: Uint8Array): Uint8Array;
4
- generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
5
- exportKey(key: CryptoKey): Promise<JsonWebKey>;
6
- importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
7
- sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
8
- digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise<ArrayBuffer>;
9
- }
1
+ import { ISubtleCrypto } from "./ISubtleCrypto";
2
+ export declare class ModernBrowserCrypto implements ISubtleCrypto {
3
+ getRandomValues(dataBuffer: Uint8Array): Uint8Array;
4
+ generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
5
+ exportKey(key: CryptoKey): Promise<JsonWebKey>;
6
+ importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
7
+ sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
8
+ digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise<ArrayBuffer>;
9
+ }
10
10
  //# sourceMappingURL=ModernBrowserCrypto.d.ts.map
@@ -1,30 +1,30 @@
1
- /*! @azure/msal-browser v3.0.0-alpha.1 2023-05-08 */
1
+ /*! @azure/msal-browser v3.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import { KEY_FORMAT_JWK } from '../utils/BrowserConstants.js';
4
4
 
5
- /*
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- class ModernBrowserCrypto {
10
- getRandomValues(dataBuffer) {
11
- return window.crypto.getRandomValues(dataBuffer);
12
- }
13
- async generateKey(algorithm, extractable, keyUsages) {
14
- return window.crypto.subtle.generateKey(algorithm, extractable, keyUsages);
15
- }
16
- async exportKey(key) {
17
- return window.crypto.subtle.exportKey(KEY_FORMAT_JWK, key);
18
- }
19
- async importKey(keyData, algorithm, extractable, keyUsages) {
20
- return window.crypto.subtle.importKey(KEY_FORMAT_JWK, keyData, algorithm, extractable, keyUsages);
21
- }
22
- async sign(algorithm, key, data) {
23
- return window.crypto.subtle.sign(algorithm, key, data);
24
- }
25
- async digest(algorithm, data) {
26
- return window.crypto.subtle.digest(algorithm, data);
27
- }
5
+ /*
6
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7
+ * Licensed under the MIT License.
8
+ */
9
+ class ModernBrowserCrypto {
10
+ getRandomValues(dataBuffer) {
11
+ return window.crypto.getRandomValues(dataBuffer);
12
+ }
13
+ async generateKey(algorithm, extractable, keyUsages) {
14
+ return window.crypto.subtle.generateKey(algorithm, extractable, keyUsages);
15
+ }
16
+ async exportKey(key) {
17
+ return window.crypto.subtle.exportKey(KEY_FORMAT_JWK, key);
18
+ }
19
+ async importKey(keyData, algorithm, extractable, keyUsages) {
20
+ return window.crypto.subtle.importKey(KEY_FORMAT_JWK, keyData, algorithm, extractable, keyUsages);
21
+ }
22
+ async sign(algorithm, key, data) {
23
+ return window.crypto.subtle.sign(algorithm, key, data);
24
+ }
25
+ async digest(algorithm, data) {
26
+ return window.crypto.subtle.digest(algorithm, data);
27
+ }
28
28
  }
29
29
 
30
30
  export { ModernBrowserCrypto };