@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
|
@@ -3,12 +3,21 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
AuthError,
|
|
8
|
+
InteractionRequiredAuthError,
|
|
9
|
+
InteractionRequiredAuthErrorCodes,
|
|
10
|
+
createInteractionRequiredAuthError,
|
|
11
|
+
} from "@azure/msal-common";
|
|
7
12
|
import {
|
|
8
13
|
createBrowserAuthError,
|
|
9
14
|
BrowserAuthErrorCodes,
|
|
10
15
|
} from "./BrowserAuthError";
|
|
11
16
|
|
|
17
|
+
import * as NativeAuthErrorCodes from "./NativeAuthErrorCodes";
|
|
18
|
+
import * as NativeStatusCodes from "../broker/nativeBroker/NativeStatusCodes";
|
|
19
|
+
export { NativeAuthErrorCodes };
|
|
20
|
+
|
|
12
21
|
export type OSError = {
|
|
13
22
|
error?: number;
|
|
14
23
|
protocol_error?: string;
|
|
@@ -19,123 +28,86 @@ export type OSError = {
|
|
|
19
28
|
|
|
20
29
|
const INVALID_METHOD_ERROR = -2147186943;
|
|
21
30
|
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
NO_NETWORK: "NO_NETWORK",
|
|
26
|
-
TRANSIENT_ERROR: "TRANSIENT_ERROR",
|
|
27
|
-
PERSISTENT_ERROR: "PERSISTENT_ERROR",
|
|
28
|
-
DISABLED: "DISABLED",
|
|
29
|
-
ACCOUNT_UNAVAILABLE: "ACCOUNT_UNAVAILABLE",
|
|
30
|
-
} as const;
|
|
31
|
-
export type NativeStatusCode =
|
|
32
|
-
(typeof NativeStatusCode)[keyof typeof NativeStatusCode];
|
|
33
|
-
|
|
34
|
-
export const NativeAuthErrorMessage = {
|
|
35
|
-
extensionError: {
|
|
36
|
-
code: "ContentError",
|
|
37
|
-
},
|
|
38
|
-
userSwitch: {
|
|
39
|
-
code: "user_switch",
|
|
40
|
-
desc: "User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
|
|
41
|
-
},
|
|
42
|
-
tokensNotFoundInCache: {
|
|
43
|
-
code: "tokens_not_found_in_internal_memory_cache",
|
|
44
|
-
desc: "Tokens not cached in MSAL JS internal memory, please make the WAM request",
|
|
45
|
-
},
|
|
31
|
+
export const NativeAuthErrorMessages = {
|
|
32
|
+
[NativeAuthErrorCodes.userSwitch]:
|
|
33
|
+
"User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
|
|
46
34
|
};
|
|
47
35
|
|
|
48
36
|
export class NativeAuthError extends AuthError {
|
|
49
37
|
ext: OSError | undefined;
|
|
50
38
|
|
|
51
|
-
constructor(errorCode: string, description
|
|
39
|
+
constructor(errorCode: string, description?: string, ext?: OSError) {
|
|
52
40
|
super(errorCode, description);
|
|
53
41
|
|
|
54
42
|
Object.setPrototypeOf(this, NativeAuthError.prototype);
|
|
55
43
|
this.name = "NativeAuthError";
|
|
56
44
|
this.ext = ext;
|
|
57
45
|
}
|
|
46
|
+
}
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
this.ext &&
|
|
74
|
-
this.ext.error &&
|
|
75
|
-
this.ext.error === INVALID_METHOD_ERROR
|
|
76
|
-
) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
switch (this.errorCode) {
|
|
81
|
-
case NativeAuthErrorMessage.extensionError.code:
|
|
82
|
-
return true;
|
|
83
|
-
default:
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
48
|
+
/**
|
|
49
|
+
* These errors should result in a fallback to the 'standard' browser based auth flow.
|
|
50
|
+
*/
|
|
51
|
+
export function isFatalNativeAuthError(error: NativeAuthError): boolean {
|
|
52
|
+
if (
|
|
53
|
+
error.ext &&
|
|
54
|
+
error.ext.status &&
|
|
55
|
+
(error.ext.status === NativeStatusCodes.PERSISTENT_ERROR ||
|
|
56
|
+
error.ext.status === NativeStatusCodes.DISABLED)
|
|
57
|
+
) {
|
|
58
|
+
return true;
|
|
86
59
|
}
|
|
87
60
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*/
|
|
95
|
-
static createError(
|
|
96
|
-
code: string,
|
|
97
|
-
description: string,
|
|
98
|
-
ext?: OSError
|
|
99
|
-
): AuthError {
|
|
100
|
-
if (ext && ext.status) {
|
|
101
|
-
switch (ext.status) {
|
|
102
|
-
case NativeStatusCode.ACCOUNT_UNAVAILABLE:
|
|
103
|
-
return InteractionRequiredAuthError.createNativeAccountUnavailableError();
|
|
104
|
-
case NativeStatusCode.USER_INTERACTION_REQUIRED:
|
|
105
|
-
return new InteractionRequiredAuthError(code, description);
|
|
106
|
-
case NativeStatusCode.USER_CANCEL:
|
|
107
|
-
return createBrowserAuthError(
|
|
108
|
-
BrowserAuthErrorCodes.userCancelled
|
|
109
|
-
);
|
|
110
|
-
case NativeStatusCode.NO_NETWORK:
|
|
111
|
-
return createBrowserAuthError(
|
|
112
|
-
BrowserAuthErrorCodes.noNetworkConnectivity
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return new NativeAuthError(code, description, ext);
|
|
61
|
+
if (
|
|
62
|
+
error.ext &&
|
|
63
|
+
error.ext.error &&
|
|
64
|
+
error.ext.error === INVALID_METHOD_ERROR
|
|
65
|
+
) {
|
|
66
|
+
return true;
|
|
118
67
|
}
|
|
119
68
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return new NativeAuthError(
|
|
126
|
-
NativeAuthErrorMessage.userSwitch.code,
|
|
127
|
-
NativeAuthErrorMessage.userSwitch.desc
|
|
128
|
-
);
|
|
69
|
+
switch (error.errorCode) {
|
|
70
|
+
case NativeAuthErrorCodes.contentError:
|
|
71
|
+
return true;
|
|
72
|
+
default:
|
|
73
|
+
return false;
|
|
129
74
|
}
|
|
75
|
+
}
|
|
130
76
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Create the appropriate error object based on the WAM status code.
|
|
79
|
+
* @param code
|
|
80
|
+
* @param description
|
|
81
|
+
* @param ext
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export function createNativeAuthError(
|
|
85
|
+
code: string,
|
|
86
|
+
description?: string,
|
|
87
|
+
ext?: OSError
|
|
88
|
+
): AuthError {
|
|
89
|
+
if (ext && ext.status) {
|
|
90
|
+
switch (ext.status) {
|
|
91
|
+
case NativeStatusCodes.ACCOUNT_UNAVAILABLE:
|
|
92
|
+
return createInteractionRequiredAuthError(
|
|
93
|
+
InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
|
|
94
|
+
);
|
|
95
|
+
case NativeStatusCodes.USER_INTERACTION_REQUIRED:
|
|
96
|
+
return new InteractionRequiredAuthError(code, description);
|
|
97
|
+
case NativeStatusCodes.USER_CANCEL:
|
|
98
|
+
return createBrowserAuthError(
|
|
99
|
+
BrowserAuthErrorCodes.userCancelled
|
|
100
|
+
);
|
|
101
|
+
case NativeStatusCodes.NO_NETWORK:
|
|
102
|
+
return createBrowserAuthError(
|
|
103
|
+
BrowserAuthErrorCodes.noNetworkConnectivity
|
|
104
|
+
);
|
|
105
|
+
}
|
|
140
106
|
}
|
|
107
|
+
|
|
108
|
+
return new NativeAuthError(
|
|
109
|
+
code,
|
|
110
|
+
NativeAuthErrorMessages[code] || description,
|
|
111
|
+
ext
|
|
112
|
+
);
|
|
141
113
|
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
EventPayload,
|
|
18
18
|
} from "./EventMessage";
|
|
19
19
|
import { EventType } from "./EventType";
|
|
20
|
+
import { createNewGuid } from "../crypto/BrowserCrypto";
|
|
20
21
|
|
|
21
22
|
export class EventHandler {
|
|
22
23
|
// Callback for subscribing to events
|
|
@@ -40,7 +41,7 @@ export class EventHandler {
|
|
|
40
41
|
*/
|
|
41
42
|
addEventCallback(callback: EventCallbackFunction): string | null {
|
|
42
43
|
if (typeof window !== "undefined") {
|
|
43
|
-
const callbackId =
|
|
44
|
+
const callbackId = createNewGuid();
|
|
44
45
|
this.eventCallbacks.set(callbackId, callback);
|
|
45
46
|
this.logger.verbose(
|
|
46
47
|
`Event callback registered with id: ${callbackId}`
|
package/src/index.ts
CHANGED
|
@@ -47,6 +47,7 @@ export {
|
|
|
47
47
|
} from "./error/BrowserAuthError";
|
|
48
48
|
export {
|
|
49
49
|
BrowserConfigurationAuthError,
|
|
50
|
+
BrowserConfigurationAuthErrorCodes,
|
|
50
51
|
BrowserConfigurationAuthErrorMessage,
|
|
51
52
|
} from "./error/BrowserConfigurationAuthError";
|
|
52
53
|
|
|
@@ -112,12 +113,16 @@ export {
|
|
|
112
113
|
IdTokenClaims,
|
|
113
114
|
// Error
|
|
114
115
|
AuthError,
|
|
116
|
+
AuthErrorCodes,
|
|
115
117
|
AuthErrorMessage,
|
|
116
118
|
ClientAuthError,
|
|
119
|
+
ClientAuthErrorCodes,
|
|
117
120
|
ClientAuthErrorMessage,
|
|
118
121
|
ClientConfigurationError,
|
|
122
|
+
ClientConfigurationErrorCodes,
|
|
119
123
|
ClientConfigurationErrorMessage,
|
|
120
124
|
InteractionRequiredAuthError,
|
|
125
|
+
InteractionRequiredAuthErrorCodes,
|
|
121
126
|
InteractionRequiredAuthErrorMessage,
|
|
122
127
|
ServerError,
|
|
123
128
|
// Network
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
UrlString,
|
|
15
15
|
ServerTelemetryManager,
|
|
16
16
|
ServerTelemetryRequest,
|
|
17
|
-
|
|
17
|
+
createClientConfigurationError,
|
|
18
|
+
ClientConfigurationErrorCodes,
|
|
18
19
|
Authority,
|
|
19
20
|
AuthorityOptions,
|
|
20
21
|
AuthorityFactory,
|
|
@@ -36,6 +37,7 @@ import { INavigationClient } from "../navigation/INavigationClient";
|
|
|
36
37
|
import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
|
|
37
38
|
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
38
39
|
import { ClearCacheRequest } from "../request/ClearCacheRequest";
|
|
40
|
+
import { createNewGuid } from "../crypto/BrowserCrypto";
|
|
39
41
|
|
|
40
42
|
export abstract class BaseInteractionClient {
|
|
41
43
|
protected config: BrowserConfiguration;
|
|
@@ -67,8 +69,7 @@ export abstract class BaseInteractionClient {
|
|
|
67
69
|
this.eventHandler = eventHandler;
|
|
68
70
|
this.navigationClient = navigationClient;
|
|
69
71
|
this.nativeMessageHandler = nativeMessageHandler;
|
|
70
|
-
this.correlationId =
|
|
71
|
-
correlationId || this.browserCrypto.createNewGuid();
|
|
72
|
+
this.correlationId = correlationId || createNewGuid();
|
|
72
73
|
this.logger = logger.clone(
|
|
73
74
|
BrowserConstants.MSAL_SKU,
|
|
74
75
|
version,
|
|
@@ -142,7 +143,6 @@ export abstract class BaseInteractionClient {
|
|
|
142
143
|
PerformanceEvents.InitializeBaseRequest,
|
|
143
144
|
request.correlationId
|
|
144
145
|
);
|
|
145
|
-
this.logger.verbose("Initializing BaseAuthRequest");
|
|
146
146
|
const authority = request.authority || this.config.auth.authority;
|
|
147
147
|
|
|
148
148
|
if (account) {
|
|
@@ -170,10 +170,14 @@ export abstract class BaseInteractionClient {
|
|
|
170
170
|
AuthenticationScheme.SSH
|
|
171
171
|
) {
|
|
172
172
|
if (!request.sshJwk) {
|
|
173
|
-
throw
|
|
173
|
+
throw createClientConfigurationError(
|
|
174
|
+
ClientConfigurationErrorCodes.missingSshJwk
|
|
175
|
+
);
|
|
174
176
|
}
|
|
175
177
|
if (!request.sshKid) {
|
|
176
|
-
throw
|
|
178
|
+
throw createClientConfigurationError(
|
|
179
|
+
ClientConfigurationErrorCodes.missingSshKid
|
|
180
|
+
);
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
this.logger.verbose(
|
|
@@ -227,7 +231,9 @@ export abstract class BaseInteractionClient {
|
|
|
227
231
|
);
|
|
228
232
|
|
|
229
233
|
if (!discoveredAuthority.isAlias(account.environment)) {
|
|
230
|
-
throw
|
|
234
|
+
throw createClientConfigurationError(
|
|
235
|
+
ClientConfigurationErrorCodes.authorityMismatch
|
|
236
|
+
);
|
|
231
237
|
}
|
|
232
238
|
}
|
|
233
239
|
|
|
@@ -22,13 +22,17 @@ import {
|
|
|
22
22
|
PerformanceEvents,
|
|
23
23
|
IdTokenEntity,
|
|
24
24
|
AccessTokenEntity,
|
|
25
|
-
ClientAuthError,
|
|
26
25
|
AuthError,
|
|
27
26
|
CommonSilentFlowRequest,
|
|
28
27
|
AccountInfo,
|
|
29
28
|
CacheRecord,
|
|
30
29
|
AADServerParamKeys,
|
|
31
30
|
TokenClaims,
|
|
31
|
+
createClientAuthError,
|
|
32
|
+
ClientAuthErrorCodes,
|
|
33
|
+
invokeAsync,
|
|
34
|
+
createAuthError,
|
|
35
|
+
AuthErrorCodes,
|
|
32
36
|
} from "@azure/msal-common";
|
|
33
37
|
import { BaseInteractionClient } from "./BaseInteractionClient";
|
|
34
38
|
import { BrowserConfiguration } from "../config/Configuration";
|
|
@@ -49,7 +53,12 @@ import {
|
|
|
49
53
|
NativeTokenRequest,
|
|
50
54
|
} from "../broker/nativeBroker/NativeRequest";
|
|
51
55
|
import { MATS, NativeResponse } from "../broker/nativeBroker/NativeResponse";
|
|
52
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
NativeAuthError,
|
|
58
|
+
NativeAuthErrorCodes,
|
|
59
|
+
createNativeAuthError,
|
|
60
|
+
isFatalNativeAuthError,
|
|
61
|
+
} from "../error/NativeAuthError";
|
|
53
62
|
import { RedirectRequest } from "../request/RedirectRequest";
|
|
54
63
|
import { NavigationOptions } from "../navigation/NavigationOptions";
|
|
55
64
|
import { INavigationClient } from "../navigation/INavigationClient";
|
|
@@ -122,6 +131,10 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
122
131
|
async acquireToken(
|
|
123
132
|
request: PopupRequest | SilentRequest | SsoSilentRequest
|
|
124
133
|
): Promise<AuthenticationResult> {
|
|
134
|
+
this.performanceClient.addQueueMeasurement(
|
|
135
|
+
PerformanceEvents.NativeInteractionClientAcquireToken,
|
|
136
|
+
request.correlationId
|
|
137
|
+
);
|
|
125
138
|
this.logger.trace("NativeInteractionClient - acquireToken called.");
|
|
126
139
|
|
|
127
140
|
// start the perf measurement
|
|
@@ -222,14 +235,14 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
222
235
|
this.logger.warning(
|
|
223
236
|
"NativeInteractionClient:acquireTokensFromCache - No nativeAccountId provided"
|
|
224
237
|
);
|
|
225
|
-
throw
|
|
238
|
+
throw createClientAuthError(ClientAuthErrorCodes.noAccountFound);
|
|
226
239
|
}
|
|
227
240
|
// fetch the account from browser cache
|
|
228
241
|
const account = this.browserStorage.getAccountInfoFilteredBy({
|
|
229
242
|
nativeAccountId,
|
|
230
243
|
});
|
|
231
244
|
if (!account) {
|
|
232
|
-
throw
|
|
245
|
+
throw createClientAuthError(ClientAuthErrorCodes.noAccountFound);
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
// leverage silent flow for cached tokens retrieval
|
|
@@ -271,7 +284,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
271
284
|
this.validateNativeResponse(response);
|
|
272
285
|
} catch (e) {
|
|
273
286
|
// Only throw fatal errors here to allow application to fallback to regular redirect. Otherwise proceed and the error will be thrown in handleRedirectPromise
|
|
274
|
-
if (e instanceof NativeAuthError && e
|
|
287
|
+
if (e instanceof NativeAuthError && isFatalNativeAuthError(e)) {
|
|
275
288
|
throw e;
|
|
276
289
|
}
|
|
277
290
|
}
|
|
@@ -384,7 +397,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
384
397
|
|
|
385
398
|
if (response.account.id !== request.accountId) {
|
|
386
399
|
// User switch in native broker prompt is not supported. All users must first sign in through web flow to ensure server state is in sync
|
|
387
|
-
throw
|
|
400
|
+
throw createNativeAuthError(NativeAuthErrorCodes.userSwitch);
|
|
388
401
|
}
|
|
389
402
|
|
|
390
403
|
// Get the preferred_cache domain for the given authority
|
|
@@ -510,7 +523,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
510
523
|
* PopTokenGenerator to query the full key for signing
|
|
511
524
|
*/
|
|
512
525
|
if (!request.keyId) {
|
|
513
|
-
throw
|
|
526
|
+
throw createClientAuthError(ClientAuthErrorCodes.keyIdMissing);
|
|
514
527
|
}
|
|
515
528
|
return await popTokenGenerator.signPopToken(
|
|
516
529
|
response.access_token,
|
|
@@ -719,7 +732,8 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
719
732
|
) {
|
|
720
733
|
return response as NativeResponse;
|
|
721
734
|
} else {
|
|
722
|
-
throw
|
|
735
|
+
throw createAuthError(
|
|
736
|
+
AuthErrorCodes.unexpectedError,
|
|
723
737
|
"Response missing expected properties."
|
|
724
738
|
);
|
|
725
739
|
}
|
|
@@ -859,9 +873,13 @@ export class NativeInteractionClient extends BaseInteractionClient {
|
|
|
859
873
|
};
|
|
860
874
|
|
|
861
875
|
const popTokenGenerator = new PopTokenGenerator(this.browserCrypto);
|
|
862
|
-
const reqCnfData = await
|
|
863
|
-
|
|
864
|
-
|
|
876
|
+
const reqCnfData = await invokeAsync(
|
|
877
|
+
popTokenGenerator.generateCnf.bind(popTokenGenerator),
|
|
878
|
+
PerformanceEvents.PopTokenGenerateCnf,
|
|
879
|
+
this.logger,
|
|
880
|
+
this.performanceClient,
|
|
881
|
+
this.correlationId
|
|
882
|
+
)(shrParameters, this.logger);
|
|
865
883
|
|
|
866
884
|
// to reduce the URL length, it is recommended to send the hash of the req_cnf instead of the whole string
|
|
867
885
|
validatedRequest.reqCnf = reqCnfData.reqCnfHash;
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Constants,
|
|
12
12
|
IPerformanceClient,
|
|
13
13
|
PerformanceEvents,
|
|
14
|
+
invokeAsync,
|
|
14
15
|
} from "@azure/msal-common";
|
|
15
16
|
import { StandardInteractionClient } from "./StandardInteractionClient";
|
|
16
17
|
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
|
|
@@ -65,8 +66,6 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
|
|
|
65
66
|
async acquireToken(
|
|
66
67
|
request: AuthorizationCodeRequest
|
|
67
68
|
): Promise<AuthenticationResult> {
|
|
68
|
-
this.logger.trace("SilentAuthCodeClient.acquireToken called");
|
|
69
|
-
|
|
70
69
|
// Auth code payload is required
|
|
71
70
|
if (!request.code) {
|
|
72
71
|
throw createBrowserAuthError(
|
|
@@ -75,15 +74,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
|
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
// Create silent request
|
|
78
|
-
|
|
77
|
+
const silentRequest: AuthorizationUrlRequest = await invokeAsync(
|
|
78
|
+
this.initializeAuthorizationRequest.bind(this),
|
|
79
79
|
PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
|
|
80
|
+
this.logger,
|
|
81
|
+
this.performanceClient,
|
|
80
82
|
request.correlationId
|
|
81
|
-
);
|
|
82
|
-
const silentRequest: AuthorizationUrlRequest =
|
|
83
|
-
await this.initializeAuthorizationRequest(
|
|
84
|
-
request,
|
|
85
|
-
InteractionType.Silent
|
|
86
|
-
);
|
|
83
|
+
)(request, InteractionType.Silent);
|
|
87
84
|
this.browserStorage.updateCacheEntries(
|
|
88
85
|
silentRequest.state,
|
|
89
86
|
silentRequest.nonce,
|
|
@@ -104,14 +101,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
|
|
|
104
101
|
};
|
|
105
102
|
|
|
106
103
|
// Initialize the client
|
|
107
|
-
|
|
104
|
+
const clientConfig = await invokeAsync(
|
|
105
|
+
this.getClientConfiguration.bind(this),
|
|
108
106
|
PerformanceEvents.StandardInteractionClientGetClientConfiguration,
|
|
107
|
+
this.logger,
|
|
108
|
+
this.performanceClient,
|
|
109
109
|
request.correlationId
|
|
110
|
-
);
|
|
111
|
-
const clientConfig = await this.getClientConfiguration(
|
|
112
|
-
serverTelemetryManager,
|
|
113
|
-
silentRequest.authority
|
|
114
|
-
);
|
|
110
|
+
)(serverTelemetryManager, silentRequest.authority);
|
|
115
111
|
const authClient: HybridSpaAuthorizationCodeClient =
|
|
116
112
|
new HybridSpaAuthorizationCodeClient(clientConfig);
|
|
117
113
|
this.logger.verbose("Auth code client created");
|
|
@@ -127,7 +123,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
|
|
|
127
123
|
);
|
|
128
124
|
|
|
129
125
|
// Handle auth code parameters from request
|
|
130
|
-
return
|
|
126
|
+
return invokeAsync(
|
|
127
|
+
silentHandler.handleCodeResponseFromServer.bind(silentHandler),
|
|
128
|
+
PerformanceEvents.HandleCodeResponseFromServer,
|
|
129
|
+
this.logger,
|
|
130
|
+
this.performanceClient,
|
|
131
|
+
request.correlationId
|
|
132
|
+
)(
|
|
131
133
|
{
|
|
132
134
|
code: request.code,
|
|
133
135
|
msgraph_host: request.msGraphHost,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
AccountInfo,
|
|
12
12
|
AzureCloudOptions,
|
|
13
13
|
PerformanceEvents,
|
|
14
|
-
|
|
14
|
+
invokeAsync,
|
|
15
15
|
} from "@azure/msal-common";
|
|
16
16
|
import { SilentRequest } from "../request/SilentRequest";
|
|
17
17
|
import { ApiId } from "../utils/BrowserConstants";
|
|
@@ -30,10 +30,6 @@ export class SilentCacheClient extends StandardInteractionClient {
|
|
|
30
30
|
async acquireToken(
|
|
31
31
|
silentRequest: CommonSilentFlowRequest
|
|
32
32
|
): Promise<AuthenticationResult> {
|
|
33
|
-
const acquireTokenMeasurement = this.performanceClient.startMeasurement(
|
|
34
|
-
PerformanceEvents.SilentCacheClientAcquireToken,
|
|
35
|
-
silentRequest.correlationId
|
|
36
|
-
);
|
|
37
33
|
// Telemetry manager only used to increment cacheHits here
|
|
38
34
|
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
|
39
35
|
ApiId.acquireTokenSilent_silentFlow
|
|
@@ -47,15 +43,18 @@ export class SilentCacheClient extends StandardInteractionClient {
|
|
|
47
43
|
this.logger.verbose("Silent auth client created");
|
|
48
44
|
|
|
49
45
|
try {
|
|
50
|
-
const
|
|
46
|
+
const response = await silentAuthClient.acquireCachedToken(
|
|
51
47
|
silentRequest
|
|
52
|
-
)
|
|
48
|
+
);
|
|
49
|
+
const authResponse = response[0] as AuthenticationResult;
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
this.performanceClient.addFields(
|
|
52
|
+
{
|
|
53
|
+
fromCache: true,
|
|
54
|
+
},
|
|
55
|
+
silentRequest.correlationId
|
|
56
|
+
);
|
|
57
|
+
return authResponse;
|
|
59
58
|
} catch (error) {
|
|
60
59
|
if (
|
|
61
60
|
error instanceof BrowserAuthError &&
|
|
@@ -65,14 +64,6 @@ export class SilentCacheClient extends StandardInteractionClient {
|
|
|
65
64
|
"Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair."
|
|
66
65
|
);
|
|
67
66
|
}
|
|
68
|
-
acquireTokenMeasurement.end({
|
|
69
|
-
errorCode:
|
|
70
|
-
(error instanceof AuthError && error.errorCode) ||
|
|
71
|
-
undefined,
|
|
72
|
-
subErrorCode:
|
|
73
|
-
(error instanceof AuthError && error.subError) || undefined,
|
|
74
|
-
success: false,
|
|
75
|
-
});
|
|
76
67
|
throw error;
|
|
77
68
|
}
|
|
78
69
|
}
|
|
@@ -98,15 +89,13 @@ export class SilentCacheClient extends StandardInteractionClient {
|
|
|
98
89
|
azureCloudOptions?: AzureCloudOptions
|
|
99
90
|
): Promise<SilentFlowClient> {
|
|
100
91
|
// Create auth module.
|
|
101
|
-
|
|
92
|
+
const clientConfig = await invokeAsync(
|
|
93
|
+
this.getClientConfiguration.bind(this),
|
|
102
94
|
PerformanceEvents.StandardInteractionClientGetClientConfiguration,
|
|
95
|
+
this.logger,
|
|
96
|
+
this.performanceClient,
|
|
103
97
|
this.correlationId
|
|
104
|
-
);
|
|
105
|
-
const clientConfig = await this.getClientConfiguration(
|
|
106
|
-
serverTelemetryManager,
|
|
107
|
-
authorityUrl,
|
|
108
|
-
azureCloudOptions
|
|
109
|
-
);
|
|
98
|
+
)(serverTelemetryManager, authorityUrl, azureCloudOptions);
|
|
110
99
|
return new SilentFlowClient(clientConfig, this.performanceClient);
|
|
111
100
|
}
|
|
112
101
|
|
|
@@ -119,13 +108,16 @@ export class SilentCacheClient extends StandardInteractionClient {
|
|
|
119
108
|
this.correlationId
|
|
120
109
|
);
|
|
121
110
|
|
|
122
|
-
|
|
111
|
+
const baseRequest = await invokeAsync(
|
|
112
|
+
this.initializeBaseRequest.bind(this),
|
|
123
113
|
PerformanceEvents.InitializeBaseRequest,
|
|
114
|
+
this.logger,
|
|
115
|
+
this.performanceClient,
|
|
124
116
|
this.correlationId
|
|
125
|
-
);
|
|
117
|
+
)(request, account);
|
|
126
118
|
return {
|
|
127
119
|
...request,
|
|
128
|
-
...
|
|
120
|
+
...baseRequest,
|
|
129
121
|
account: account,
|
|
130
122
|
forceRefresh: request.forceRefresh || false,
|
|
131
123
|
};
|
|
@@ -231,7 +231,7 @@ export class SilentIframeClient extends StandardInteractionClient {
|
|
|
231
231
|
// Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.
|
|
232
232
|
const hash = await invokeAsync(
|
|
233
233
|
silentHandler.monitorIframeForHash.bind(silentHandler),
|
|
234
|
-
PerformanceEvents.
|
|
234
|
+
PerformanceEvents.SilentHandlerMonitorIframeForHash,
|
|
235
235
|
this.logger,
|
|
236
236
|
this.performanceClient,
|
|
237
237
|
silentRequest.correlationId
|