@azure/msal-browser 3.1.0 → 3.3.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 +18 -8
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.d.ts +274 -0
- package/dist/app/PublicClientNext.d.ts.map +1 -0
- package/dist/app/PublicClientNext.mjs +362 -0
- package/dist/app/PublicClientNext.mjs.map +1 -0
- 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 +4 -15
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +13 -69
- 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 +4 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +8 -7
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.d.ts +2 -1
- package/dist/controllers/ControllerFactory.d.ts.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +26 -19
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +3 -2
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts +96 -0
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
- package/dist/controllers/NestedAppAuthController.mjs +345 -0
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
- package/dist/controllers/StandardController.d.ts +11 -6
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +67 -45
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
- package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
- package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
- package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
- package/dist/crypto/BrowserCrypto.d.ts +44 -49
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +77 -77
- 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 +18 -23
- 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/error/NestedAppAuthError.d.ts +15 -0
- package/dist/error/NestedAppAuthError.d.ts.map +1 -0
- package/dist/error/NestedAppAuthError.mjs +30 -0
- package/dist/error/NestedAppAuthError.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 +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +10 -11
- 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 +26 -13
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +5 -4
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -7
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +7 -10
- 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 +11 -18
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +27 -13
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +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 +16 -37
- 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 +13 -47
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +120 -156
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/naa/AccountInfo.d.ts +13 -0
- package/dist/naa/AccountInfo.d.ts.map +1 -0
- package/dist/naa/AccountRequests.d.ts +10 -0
- package/dist/naa/AccountRequests.d.ts.map +1 -0
- package/dist/naa/AuthBridge.d.ts +6 -0
- package/dist/naa/AuthBridge.d.ts.map +1 -0
- package/dist/naa/BridgeCapabilities.d.ts +4 -0
- package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
- package/dist/naa/BridgeError.d.ts +10 -0
- package/dist/naa/BridgeError.d.ts.map +1 -0
- package/dist/naa/BridgeError.mjs +12 -0
- package/dist/naa/BridgeError.mjs.map +1 -0
- package/dist/naa/BridgeProxy.d.ts +72 -0
- package/dist/naa/BridgeProxy.d.ts.map +1 -0
- package/dist/naa/BridgeProxy.mjs +154 -0
- package/dist/naa/BridgeProxy.mjs.map +1 -0
- package/dist/naa/BridgeRequest.d.ts +7 -0
- package/dist/naa/BridgeRequest.d.ts.map +1 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.d.ts +11 -0
- package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.mjs +20 -0
- package/dist/naa/BridgeStatusCode.mjs.map +1 -0
- package/dist/naa/IBridgeProxy.d.ts +11 -0
- package/dist/naa/IBridgeProxy.d.ts.map +1 -0
- package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
- package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
- package/dist/naa/TokenRequest.d.ts +22 -0
- package/dist/naa/TokenRequest.d.ts.map +1 -0
- package/dist/naa/TokenResponse.d.ts +17 -0
- package/dist/naa/TokenResponse.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
- 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.d.ts +7 -0
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
- package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
- 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/BrowserUtils.d.ts +54 -53
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +114 -102
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +61 -18042
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +13593 -12505
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +66 -65
- package/package.json +2 -2
- package/src/app/IPublicClientApplication.ts +55 -18
- package/src/app/PublicClientApplication.ts +19 -7
- package/src/app/PublicClientNext.ts +442 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/BrowserCacheManager.ts +29 -103
- package/src/cache/BrowserStorage.ts +9 -11
- package/src/config/Configuration.ts +21 -8
- package/src/controllers/ControllerFactory.ts +36 -25
- package/src/controllers/IController.ts +4 -1
- package/src/controllers/NestedAppAuthController.ts +525 -0
- package/src/controllers/StandardController.ts +163 -98
- package/src/controllers/UnknownOperatingContextController.ts +383 -0
- package/src/crypto/BrowserCrypto.ts +119 -103
- package/src/crypto/CryptoOps.ts +18 -27
- 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/error/NestedAppAuthError.ts +32 -0
- package/src/event/EventHandler.ts +2 -1
- package/src/index.ts +8 -10
- package/src/interaction_client/BaseInteractionClient.ts +14 -8
- package/src/interaction_client/NativeInteractionClient.ts +48 -14
- package/src/interaction_client/PopupClient.ts +2 -1
- package/src/interaction_client/RedirectClient.ts +1 -1
- package/src/interaction_client/SilentAuthCodeClient.ts +22 -19
- package/src/interaction_client/SilentCacheClient.ts +28 -28
- package/src/interaction_client/SilentIframeClient.ts +54 -18
- package/src/interaction_client/SilentRefreshClient.ts +26 -28
- package/src/interaction_client/StandardInteractionClient.ts +37 -68
- package/src/interaction_handler/InteractionHandler.ts +20 -15
- package/src/interaction_handler/RedirectHandler.ts +6 -2
- package/src/interaction_handler/SilentHandler.ts +177 -230
- package/src/naa/AccountInfo.ts +17 -0
- package/src/naa/AccountRequests.ts +16 -0
- package/src/naa/AuthBridge.ts +16 -0
- package/src/naa/BridgeCapabilities.ts +8 -0
- package/src/naa/BridgeError.ts +18 -0
- package/src/naa/BridgeProxy.ts +230 -0
- package/src/naa/BridgeRequest.ts +12 -0
- package/src/naa/BridgeRequestEnvelope.ts +46 -0
- package/src/naa/BridgeResponseEnvelope.ts +21 -0
- package/src/naa/BridgeStatusCode.ts +15 -0
- package/src/naa/IBridgeProxy.ts +25 -0
- package/src/naa/InitializeBridgeResponse.ts +12 -0
- package/src/naa/TokenRequest.ts +26 -0
- package/src/naa/TokenResponse.ts +61 -0
- package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
- package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +1 -1
- package/src/utils/BrowserProtocolUtils.ts +3 -2
- package/src/utils/BrowserUtils.ts +133 -125
- package/dist/crypto/ISubtleCrypto.d.ts +0 -10
- package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
- package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
- package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
- package/dist/utils/BrowserStringUtils.d.ts +0 -22
- package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
- package/dist/utils/BrowserStringUtils.mjs +0 -144
- package/dist/utils/BrowserStringUtils.mjs.map +0 -1
- package/src/crypto/ISubtleCrypto.ts +0 -30
- package/src/crypto/ModernBrowserCrypto.ts +0 -69
- package/src/utils/BrowserStringUtils.ts +0 -143
package/src/crypto/CryptoOps.ts
CHANGED
|
@@ -9,15 +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";
|
|
20
|
-
import { BrowserStringUtils } from "../utils/BrowserStringUtils";
|
|
17
|
+
import * as BrowserCrypto from "./BrowserCrypto";
|
|
21
18
|
import {
|
|
22
19
|
createBrowserAuthError,
|
|
23
20
|
BrowserAuthErrorCodes,
|
|
@@ -36,8 +33,6 @@ export type CachedKeyPair = {
|
|
|
36
33
|
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
|
37
34
|
*/
|
|
38
35
|
export class CryptoOps implements ICrypto {
|
|
39
|
-
private browserCrypto: BrowserCrypto;
|
|
40
|
-
private pkceGenerator: PkceGenerator;
|
|
41
36
|
private logger: Logger;
|
|
42
37
|
|
|
43
38
|
/**
|
|
@@ -53,8 +48,7 @@ export class CryptoOps implements ICrypto {
|
|
|
53
48
|
constructor(logger: Logger, performanceClient?: IPerformanceClient) {
|
|
54
49
|
this.logger = logger;
|
|
55
50
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
56
|
-
|
|
57
|
-
this.pkceGenerator = new PkceGenerator(this.browserCrypto);
|
|
51
|
+
BrowserCrypto.validateCryptoAvailable(logger);
|
|
58
52
|
this.cache = new CryptoKeyStore(this.logger);
|
|
59
53
|
this.performanceClient = performanceClient;
|
|
60
54
|
}
|
|
@@ -64,7 +58,7 @@ export class CryptoOps implements ICrypto {
|
|
|
64
58
|
* @returns string (GUID)
|
|
65
59
|
*/
|
|
66
60
|
createNewGuid(): string {
|
|
67
|
-
return
|
|
61
|
+
return BrowserCrypto.createNewGuid();
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
/**
|
|
@@ -83,13 +77,6 @@ export class CryptoOps implements ICrypto {
|
|
|
83
77
|
return base64Decode(input);
|
|
84
78
|
}
|
|
85
79
|
|
|
86
|
-
/**
|
|
87
|
-
* Generates PKCE codes used in Authorization Code Flow.
|
|
88
|
-
*/
|
|
89
|
-
async generatePkceCodes(): Promise<PkceCodes> {
|
|
90
|
-
return this.pkceGenerator.generateCodes();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
80
|
/**
|
|
94
81
|
* Generates a keypair, stores it and returns a thumbprint
|
|
95
82
|
* @param request
|
|
@@ -104,13 +91,13 @@ export class CryptoOps implements ICrypto {
|
|
|
104
91
|
);
|
|
105
92
|
|
|
106
93
|
// Generate Keypair
|
|
107
|
-
const keyPair: CryptoKeyPair = await
|
|
94
|
+
const keyPair: CryptoKeyPair = await BrowserCrypto.generateKeyPair(
|
|
108
95
|
CryptoOps.EXTRACTABLE,
|
|
109
96
|
CryptoOps.POP_KEY_USAGES
|
|
110
97
|
);
|
|
111
98
|
|
|
112
99
|
// Generate Thumbprint for Public Key
|
|
113
|
-
const publicKeyJwk: JsonWebKey = await
|
|
100
|
+
const publicKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
|
|
114
101
|
keyPair.publicKey
|
|
115
102
|
);
|
|
116
103
|
|
|
@@ -121,16 +108,16 @@ export class CryptoOps implements ICrypto {
|
|
|
121
108
|
};
|
|
122
109
|
|
|
123
110
|
const publicJwkString: string =
|
|
124
|
-
|
|
111
|
+
getSortedObjectString(pubKeyThumprintObj);
|
|
125
112
|
const publicJwkHash = await this.hashString(publicJwkString);
|
|
126
113
|
|
|
127
114
|
// Generate Thumbprint for Private Key
|
|
128
|
-
const privateKeyJwk: JsonWebKey = await
|
|
115
|
+
const privateKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
|
|
129
116
|
keyPair.privateKey
|
|
130
117
|
);
|
|
131
118
|
// Re-import private key to make it unextractable
|
|
132
119
|
const unextractablePrivateKey: CryptoKey =
|
|
133
|
-
await
|
|
120
|
+
await BrowserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
|
|
134
121
|
|
|
135
122
|
// Store Keypair data in keystore
|
|
136
123
|
await this.cache.asymmetricKeys.setItem(publicJwkHash, {
|
|
@@ -189,11 +176,10 @@ export class CryptoOps implements ICrypto {
|
|
|
189
176
|
}
|
|
190
177
|
|
|
191
178
|
// Get public key as JWK
|
|
192
|
-
const publicKeyJwk = await
|
|
179
|
+
const publicKeyJwk = await BrowserCrypto.exportJwk(
|
|
193
180
|
cachedKeyPair.publicKey
|
|
194
181
|
);
|
|
195
|
-
const publicKeyJwkString =
|
|
196
|
-
BrowserStringUtils.getSortedObjectString(publicKeyJwk);
|
|
182
|
+
const publicKeyJwkString = getSortedObjectString(publicKeyJwk);
|
|
197
183
|
|
|
198
184
|
// Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
|
|
199
185
|
const encodedKeyIdThumbprint = urlEncode(JSON.stringify({ kid: kid }));
|
|
@@ -215,8 +201,9 @@ export class CryptoOps implements ICrypto {
|
|
|
215
201
|
const tokenString = `${encodedShrHeader}.${encodedPayload}`;
|
|
216
202
|
|
|
217
203
|
// Sign token
|
|
218
|
-
const
|
|
219
|
-
const
|
|
204
|
+
const encoder = new TextEncoder();
|
|
205
|
+
const tokenBuffer = encoder.encode(tokenString);
|
|
206
|
+
const signatureBuffer = await BrowserCrypto.sign(
|
|
220
207
|
cachedKeyPair.privateKey,
|
|
221
208
|
tokenBuffer
|
|
222
209
|
);
|
|
@@ -238,10 +225,14 @@ export class CryptoOps implements ICrypto {
|
|
|
238
225
|
* @param plainText
|
|
239
226
|
*/
|
|
240
227
|
async hashString(plainText: string): Promise<string> {
|
|
241
|
-
const hashBuffer: ArrayBuffer = await
|
|
228
|
+
const hashBuffer: ArrayBuffer = await BrowserCrypto.sha256Digest(
|
|
242
229
|
plainText
|
|
243
230
|
);
|
|
244
231
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
245
232
|
return urlEncodeArr(hashBytes);
|
|
246
233
|
}
|
|
247
234
|
}
|
|
235
|
+
|
|
236
|
+
function getSortedObjectString(obj: object): string {
|
|
237
|
+
return JSON.stringify(obj, Object.keys(obj).sort());
|
|
238
|
+
}
|
|
@@ -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";
|