@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
package/src/crypto/CryptoOps.ts
CHANGED
|
@@ -9,14 +9,12 @@ import {
|
|
|
9
9
|
JoseHeader,
|
|
10
10
|
Logger,
|
|
11
11
|
PerformanceEvents,
|
|
12
|
-
PkceCodes,
|
|
13
12
|
SignedHttpRequest,
|
|
14
13
|
SignedHttpRequestParameters,
|
|
15
14
|
} from "@azure/msal-common";
|
|
16
15
|
import { base64Encode, urlEncode, urlEncodeArr } from "../encode/Base64Encode";
|
|
17
16
|
import { base64Decode } from "../encode/Base64Decode";
|
|
18
|
-
import
|
|
19
|
-
import { BrowserCrypto } from "./BrowserCrypto";
|
|
17
|
+
import * as BrowserCrypto from "./BrowserCrypto";
|
|
20
18
|
import { BrowserStringUtils } from "../utils/BrowserStringUtils";
|
|
21
19
|
import {
|
|
22
20
|
createBrowserAuthError,
|
|
@@ -36,8 +34,6 @@ export type CachedKeyPair = {
|
|
|
36
34
|
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
|
37
35
|
*/
|
|
38
36
|
export class CryptoOps implements ICrypto {
|
|
39
|
-
private browserCrypto: BrowserCrypto;
|
|
40
|
-
private pkceGenerator: PkceGenerator;
|
|
41
37
|
private logger: Logger;
|
|
42
38
|
|
|
43
39
|
/**
|
|
@@ -53,8 +49,7 @@ export class CryptoOps implements ICrypto {
|
|
|
53
49
|
constructor(logger: Logger, performanceClient?: IPerformanceClient) {
|
|
54
50
|
this.logger = logger;
|
|
55
51
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
56
|
-
|
|
57
|
-
this.pkceGenerator = new PkceGenerator(this.browserCrypto);
|
|
52
|
+
BrowserCrypto.validateCryptoAvailable(logger);
|
|
58
53
|
this.cache = new CryptoKeyStore(this.logger);
|
|
59
54
|
this.performanceClient = performanceClient;
|
|
60
55
|
}
|
|
@@ -64,7 +59,7 @@ export class CryptoOps implements ICrypto {
|
|
|
64
59
|
* @returns string (GUID)
|
|
65
60
|
*/
|
|
66
61
|
createNewGuid(): string {
|
|
67
|
-
return
|
|
62
|
+
return BrowserCrypto.createNewGuid();
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
/**
|
|
@@ -83,13 +78,6 @@ export class CryptoOps implements ICrypto {
|
|
|
83
78
|
return base64Decode(input);
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
/**
|
|
87
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
88
|
-
*/
|
|
89
|
-
async generatePkceCodes(): Promise<PkceCodes> {
|
|
90
|
-
return this.pkceGenerator.generateCodes();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
81
|
/**
|
|
94
82
|
* Generates a keypair, stores it and returns a thumbprint
|
|
95
83
|
* @param request
|
|
@@ -104,13 +92,13 @@ export class CryptoOps implements ICrypto {
|
|
|
104
92
|
);
|
|
105
93
|
|
|
106
94
|
// Generate Keypair
|
|
107
|
-
const keyPair: CryptoKeyPair = await
|
|
95
|
+
const keyPair: CryptoKeyPair = await BrowserCrypto.generateKeyPair(
|
|
108
96
|
CryptoOps.EXTRACTABLE,
|
|
109
97
|
CryptoOps.POP_KEY_USAGES
|
|
110
98
|
);
|
|
111
99
|
|
|
112
100
|
// Generate Thumbprint for Public Key
|
|
113
|
-
const publicKeyJwk: JsonWebKey = await
|
|
101
|
+
const publicKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
|
|
114
102
|
keyPair.publicKey
|
|
115
103
|
);
|
|
116
104
|
|
|
@@ -125,12 +113,12 @@ export class CryptoOps implements ICrypto {
|
|
|
125
113
|
const publicJwkHash = await this.hashString(publicJwkString);
|
|
126
114
|
|
|
127
115
|
// Generate Thumbprint for Private Key
|
|
128
|
-
const privateKeyJwk: JsonWebKey = await
|
|
116
|
+
const privateKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
|
|
129
117
|
keyPair.privateKey
|
|
130
118
|
);
|
|
131
119
|
// Re-import private key to make it unextractable
|
|
132
120
|
const unextractablePrivateKey: CryptoKey =
|
|
133
|
-
await
|
|
121
|
+
await BrowserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
|
|
134
122
|
|
|
135
123
|
// Store Keypair data in keystore
|
|
136
124
|
await this.cache.asymmetricKeys.setItem(publicJwkHash, {
|
|
@@ -189,7 +177,7 @@ export class CryptoOps implements ICrypto {
|
|
|
189
177
|
}
|
|
190
178
|
|
|
191
179
|
// Get public key as JWK
|
|
192
|
-
const publicKeyJwk = await
|
|
180
|
+
const publicKeyJwk = await BrowserCrypto.exportJwk(
|
|
193
181
|
cachedKeyPair.publicKey
|
|
194
182
|
);
|
|
195
183
|
const publicKeyJwkString =
|
|
@@ -216,7 +204,7 @@ export class CryptoOps implements ICrypto {
|
|
|
216
204
|
|
|
217
205
|
// Sign token
|
|
218
206
|
const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
|
|
219
|
-
const signatureBuffer = await
|
|
207
|
+
const signatureBuffer = await BrowserCrypto.sign(
|
|
220
208
|
cachedKeyPair.privateKey,
|
|
221
209
|
tokenBuffer
|
|
222
210
|
);
|
|
@@ -238,7 +226,7 @@ export class CryptoOps implements ICrypto {
|
|
|
238
226
|
* @param plainText
|
|
239
227
|
*/
|
|
240
228
|
async hashString(plainText: string): Promise<string> {
|
|
241
|
-
const hashBuffer: ArrayBuffer = await
|
|
229
|
+
const hashBuffer: ArrayBuffer = await BrowserCrypto.sha256Digest(
|
|
242
230
|
plainText
|
|
243
231
|
);
|
|
244
232
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
@@ -3,74 +3,113 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
IPerformanceClient,
|
|
8
|
+
Logger,
|
|
9
|
+
PerformanceEvents,
|
|
10
|
+
PkceCodes,
|
|
11
|
+
invoke,
|
|
12
|
+
invokeAsync,
|
|
13
|
+
} from "@azure/msal-common";
|
|
7
14
|
import {
|
|
8
15
|
createBrowserAuthError,
|
|
9
16
|
BrowserAuthErrorCodes,
|
|
10
17
|
} from "../error/BrowserAuthError";
|
|
11
18
|
import { urlEncodeArr } from "../encode/Base64Encode";
|
|
12
|
-
import {
|
|
19
|
+
import { getRandomValues, sha256Digest } from "./BrowserCrypto";
|
|
13
20
|
|
|
14
21
|
// Constant byte array length
|
|
15
22
|
const RANDOM_BYTE_ARR_LENGTH = 32;
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
|
-
*
|
|
25
|
+
* This file defines APIs to generate PKCE codes and code verifiers.
|
|
19
26
|
*/
|
|
20
|
-
export class PkceGenerator {
|
|
21
|
-
private cryptoObj: BrowserCrypto;
|
|
22
|
-
|
|
23
|
-
constructor(cryptoObj: BrowserCrypto) {
|
|
24
|
-
this.cryptoObj = cryptoObj;
|
|
25
|
-
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
|
|
30
|
+
*/
|
|
31
|
+
export async function generatePkceCodes(
|
|
32
|
+
performanceClient: IPerformanceClient,
|
|
33
|
+
logger: Logger,
|
|
34
|
+
correlationId: string
|
|
35
|
+
): Promise<PkceCodes> {
|
|
36
|
+
performanceClient.addQueueMeasurement(
|
|
37
|
+
PerformanceEvents.GeneratePkceCodes,
|
|
38
|
+
correlationId
|
|
39
|
+
);
|
|
40
|
+
const codeVerifier = invoke(
|
|
41
|
+
generateCodeVerifier,
|
|
42
|
+
PerformanceEvents.GenerateCodeVerifier,
|
|
43
|
+
logger,
|
|
44
|
+
performanceClient,
|
|
45
|
+
correlationId
|
|
46
|
+
)(performanceClient, logger, correlationId);
|
|
47
|
+
const codeChallenge = await invokeAsync(
|
|
48
|
+
generateCodeChallengeFromVerifier,
|
|
49
|
+
PerformanceEvents.GenerateCodeChallengeFromVerifier,
|
|
50
|
+
logger,
|
|
51
|
+
performanceClient,
|
|
52
|
+
correlationId
|
|
53
|
+
)(codeVerifier, performanceClient, logger, correlationId);
|
|
54
|
+
return {
|
|
55
|
+
verifier: codeVerifier,
|
|
56
|
+
challenge: codeChallenge,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
40
59
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Generates a random 32 byte buffer and returns the base64
|
|
62
|
+
* encoded string to be used as a PKCE Code Verifier
|
|
63
|
+
*/
|
|
64
|
+
function generateCodeVerifier(
|
|
65
|
+
performanceClient: IPerformanceClient,
|
|
66
|
+
logger: Logger,
|
|
67
|
+
correlationId: string
|
|
68
|
+
): string {
|
|
69
|
+
try {
|
|
70
|
+
// Generate random values as utf-8
|
|
71
|
+
const buffer: Uint8Array = new Uint8Array(RANDOM_BYTE_ARR_LENGTH);
|
|
72
|
+
invoke(
|
|
73
|
+
getRandomValues,
|
|
74
|
+
PerformanceEvents.GetRandomValues,
|
|
75
|
+
logger,
|
|
76
|
+
performanceClient,
|
|
77
|
+
correlationId
|
|
78
|
+
)(buffer);
|
|
79
|
+
// encode verifier as base64
|
|
80
|
+
const pkceCodeVerifierB64: string = urlEncodeArr(buffer);
|
|
81
|
+
return pkceCodeVerifierB64;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
|
|
56
84
|
}
|
|
85
|
+
}
|
|
57
86
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Creates a base64 encoded PKCE Code Challenge string from the
|
|
89
|
+
* hash created from the PKCE Code Verifier supplied
|
|
90
|
+
*/
|
|
91
|
+
async function generateCodeChallengeFromVerifier(
|
|
92
|
+
pkceCodeVerifier: string,
|
|
93
|
+
performanceClient: IPerformanceClient,
|
|
94
|
+
logger: Logger,
|
|
95
|
+
correlationId: string
|
|
96
|
+
): Promise<string> {
|
|
97
|
+
performanceClient.addQueueMeasurement(
|
|
98
|
+
PerformanceEvents.GenerateCodeChallengeFromVerifier,
|
|
99
|
+
correlationId
|
|
100
|
+
);
|
|
101
|
+
try {
|
|
102
|
+
// hashed verifier
|
|
103
|
+
const pkceHashedCodeVerifier = await invokeAsync(
|
|
104
|
+
sha256Digest,
|
|
105
|
+
PerformanceEvents.Sha256Digest,
|
|
106
|
+
logger,
|
|
107
|
+
performanceClient,
|
|
108
|
+
correlationId
|
|
109
|
+
)(pkceCodeVerifier, performanceClient, correlationId);
|
|
110
|
+
// encode hash as base64
|
|
111
|
+
return urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
|
|
75
114
|
}
|
|
76
115
|
}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
BrowserAuthErrorCodes,
|
|
8
|
+
createBrowserAuthError,
|
|
9
|
+
} from "../error/BrowserAuthError";
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:
|
|
8
13
|
* https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
|
@@ -21,6 +26,21 @@ export function base64Decode(input: string): string {
|
|
|
21
26
|
* @param base64String
|
|
22
27
|
*/
|
|
23
28
|
function base64DecToArr(base64String: string): Uint8Array {
|
|
24
|
-
|
|
29
|
+
let encodedString = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
30
|
+
switch (encodedString.length % 4) {
|
|
31
|
+
case 0:
|
|
32
|
+
break;
|
|
33
|
+
case 2:
|
|
34
|
+
encodedString += "==";
|
|
35
|
+
break;
|
|
36
|
+
case 3:
|
|
37
|
+
encodedString += "=";
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
throw createBrowserAuthError(
|
|
41
|
+
BrowserAuthErrorCodes.invalidBase64String
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const binString = atob(encodedString);
|
|
25
45
|
return Uint8Array.from(binString, (m) => m.codePointAt(0) || 0);
|
|
26
46
|
}
|
|
@@ -88,11 +88,17 @@ export const BrowserAuthErrorMessages = {
|
|
|
88
88
|
[BrowserAuthErrorCodes.uninitializedPublicClientApplication]: `You must call and await the initialize function before attempting to call any other MSAL API. ${ErrorLink}`,
|
|
89
89
|
[BrowserAuthErrorCodes.nativePromptNotSupported]:
|
|
90
90
|
"The provided prompt is not supported by the native platform. This request should be routed to the web based flow.",
|
|
91
|
+
[BrowserAuthErrorCodes.invalidBase64String]:
|
|
92
|
+
"Invalid base64 encoded string.",
|
|
91
93
|
};
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
|
|
95
|
-
* @deprecated Use
|
|
97
|
+
* @deprecated Use exported BrowserAuthErrorCodes instead.
|
|
98
|
+
* In your app you can do :
|
|
99
|
+
* ```
|
|
100
|
+
* import { BrowserAuthErrorCodes } from "@azure/msal-browser";
|
|
101
|
+
* ```
|
|
96
102
|
*/
|
|
97
103
|
export const BrowserAuthErrorMessage = {
|
|
98
104
|
pkceNotGenerated: {
|
|
@@ -321,6 +327,12 @@ export const BrowserAuthErrorMessage = {
|
|
|
321
327
|
BrowserAuthErrorCodes.nativePromptNotSupported
|
|
322
328
|
],
|
|
323
329
|
},
|
|
330
|
+
invalidBase64StringError: {
|
|
331
|
+
code: BrowserAuthErrorCodes.invalidBase64String,
|
|
332
|
+
desc: BrowserAuthErrorMessages[
|
|
333
|
+
BrowserAuthErrorCodes.invalidBase64String
|
|
334
|
+
],
|
|
335
|
+
},
|
|
324
336
|
};
|
|
325
337
|
|
|
326
338
|
/**
|
|
@@ -54,3 +54,4 @@ export const nativeConnectionNotEstablished =
|
|
|
54
54
|
export const uninitializedPublicClientApplication =
|
|
55
55
|
"uninitialized_public_client_application";
|
|
56
56
|
export const nativePromptNotSupported = "native_prompt_not_supported";
|
|
57
|
+
export const invalidBase64String = "invalid_base64_string";
|
|
@@ -4,46 +4,41 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { AuthError } from "@azure/msal-common";
|
|
7
|
+
import * as BrowserConfigurationAuthErrorCodes from "./BrowserConfigurationAuthErrorCodes";
|
|
8
|
+
export { BrowserConfigurationAuthErrorCodes };
|
|
9
|
+
|
|
10
|
+
export const BrowserConfigurationAuthErrorMessages = {
|
|
11
|
+
[BrowserConfigurationAuthErrorCodes.storageNotSupported]:
|
|
12
|
+
"Given storage configuration option was not supported.",
|
|
13
|
+
[BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled]:
|
|
14
|
+
"Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
|
|
15
|
+
[BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable]:
|
|
16
|
+
"Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
|
|
17
|
+
};
|
|
7
18
|
|
|
8
19
|
/**
|
|
9
20
|
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
|
|
21
|
+
* @deprecated Use BrowserAuthErrorCodes instead
|
|
10
22
|
*/
|
|
11
23
|
export const BrowserConfigurationAuthErrorMessage = {
|
|
12
|
-
redirectUriNotSet: {
|
|
13
|
-
code: "redirect_uri_empty",
|
|
14
|
-
desc: "A redirect URI is required for all calls, and none has been set.",
|
|
15
|
-
},
|
|
16
|
-
postLogoutUriNotSet: {
|
|
17
|
-
code: "post_logout_uri_empty",
|
|
18
|
-
desc: "A post logout redirect has not been set.",
|
|
19
|
-
},
|
|
20
24
|
storageNotSupportedError: {
|
|
21
|
-
code:
|
|
22
|
-
desc:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
code: "no_redirect_callbacks",
|
|
26
|
-
desc:
|
|
27
|
-
"No redirect callbacks have been set. Please call setRedirectCallbacks() with the appropriate function arguments before continuing. " +
|
|
28
|
-
"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.",
|
|
29
|
-
},
|
|
30
|
-
invalidCallbackObject: {
|
|
31
|
-
code: "invalid_callback_object",
|
|
32
|
-
desc:
|
|
33
|
-
"The object passed for the callback was invalid. " +
|
|
34
|
-
"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.",
|
|
25
|
+
code: BrowserConfigurationAuthErrorCodes.storageNotSupported,
|
|
26
|
+
desc: BrowserConfigurationAuthErrorMessages[
|
|
27
|
+
BrowserConfigurationAuthErrorCodes.storageNotSupported
|
|
28
|
+
],
|
|
35
29
|
},
|
|
36
30
|
stubPcaInstanceCalled: {
|
|
37
|
-
code:
|
|
38
|
-
desc:
|
|
31
|
+
code: BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled,
|
|
32
|
+
desc: BrowserConfigurationAuthErrorMessages[
|
|
33
|
+
BrowserConfigurationAuthErrorCodes
|
|
34
|
+
.stubbedPublicClientApplicationCalled
|
|
35
|
+
],
|
|
39
36
|
},
|
|
40
37
|
inMemRedirectUnavailable: {
|
|
41
|
-
code:
|
|
42
|
-
desc:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
code: "entropy_not_provided",
|
|
46
|
-
desc: "The available browser crypto interface requires entropy set via system.cryptoOptions.entropy configuration option.",
|
|
38
|
+
code: BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable,
|
|
39
|
+
desc: BrowserConfigurationAuthErrorMessages[
|
|
40
|
+
BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable
|
|
41
|
+
],
|
|
47
42
|
},
|
|
48
43
|
};
|
|
49
44
|
|
|
@@ -57,77 +52,13 @@ export class BrowserConfigurationAuthError extends AuthError {
|
|
|
57
52
|
|
|
58
53
|
Object.setPrototypeOf(this, BrowserConfigurationAuthError.prototype);
|
|
59
54
|
}
|
|
55
|
+
}
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Creates an error thrown when the post-logout redirect uri is empty (not set by caller)
|
|
73
|
-
*/
|
|
74
|
-
static createPostLogoutRedirectUriEmptyError(): BrowserConfigurationAuthError {
|
|
75
|
-
return new BrowserConfigurationAuthError(
|
|
76
|
-
BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.code,
|
|
77
|
-
BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.desc
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Creates error thrown when given storage location is not supported.
|
|
83
|
-
* @param givenStorageLocation
|
|
84
|
-
*/
|
|
85
|
-
static createStorageNotSupportedError(
|
|
86
|
-
givenStorageLocation: string
|
|
87
|
-
): BrowserConfigurationAuthError {
|
|
88
|
-
return new BrowserConfigurationAuthError(
|
|
89
|
-
BrowserConfigurationAuthErrorMessage.storageNotSupportedError.code,
|
|
90
|
-
`${BrowserConfigurationAuthErrorMessage.storageNotSupportedError.desc} Given Location: ${givenStorageLocation}`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Creates error thrown when redirect callbacks are not set before calling loginRedirect() or acquireTokenRedirect().
|
|
96
|
-
*/
|
|
97
|
-
static createRedirectCallbacksNotSetError(): BrowserConfigurationAuthError {
|
|
98
|
-
return new BrowserConfigurationAuthError(
|
|
99
|
-
BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.code,
|
|
100
|
-
BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.desc
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Creates error thrown when the stub instance of PublicClientApplication is called.
|
|
106
|
-
*/
|
|
107
|
-
static createStubPcaInstanceCalledError(): BrowserConfigurationAuthError {
|
|
108
|
-
return new BrowserConfigurationAuthError(
|
|
109
|
-
BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code,
|
|
110
|
-
BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/*
|
|
115
|
-
* Create an error thrown when in-memory storage is used and storeAuthStateInCookie=false.
|
|
116
|
-
*/
|
|
117
|
-
static createInMemoryRedirectUnavailableError(): BrowserConfigurationAuthError {
|
|
118
|
-
return new BrowserConfigurationAuthError(
|
|
119
|
-
BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.code,
|
|
120
|
-
BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.desc
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Creates an error thrown when a crypto interface that requires entropy is initialized without entropy
|
|
126
|
-
*/
|
|
127
|
-
static createEntropyNotProvided(): BrowserConfigurationAuthError {
|
|
128
|
-
return new BrowserConfigurationAuthError(
|
|
129
|
-
BrowserConfigurationAuthErrorMessage.entropyNotProvided.code,
|
|
130
|
-
BrowserConfigurationAuthErrorMessage.entropyNotProvided.desc
|
|
131
|
-
);
|
|
132
|
-
}
|
|
57
|
+
export function createBrowserConfigurationAuthError(
|
|
58
|
+
errorCode: string
|
|
59
|
+
): BrowserConfigurationAuthError {
|
|
60
|
+
return new BrowserConfigurationAuthError(
|
|
61
|
+
errorCode,
|
|
62
|
+
BrowserConfigurationAuthErrorMessages[errorCode]
|
|
63
|
+
);
|
|
133
64
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const storageNotSupported = "storage_not_supported";
|
|
7
|
+
export const stubbedPublicClientApplicationCalled =
|
|
8
|
+
"stubbed_public_client_application_called";
|
|
9
|
+
export const inMemRedirectUnavailable = "in_mem_redirect_unavailable";
|