@azure/msal-browser 3.3.0 → 3.5.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.mjs +1 -1
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +3 -4
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.d.ts.map +1 -1
- package/dist/app/PublicClientNext.mjs +4 -6
- package/dist/app/PublicClientNext.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +26 -26
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.mjs +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.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +5 -5
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/controllers/ControllerFactory.d.ts +2 -8
- package/dist/controllers/ControllerFactory.d.ts.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +21 -38
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +1 -2
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.mjs +1 -1
- package/dist/controllers/StandardController.d.ts +4 -4
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +50 -51
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
- package/dist/crypto/BrowserCrypto.mjs +1 -1
- package/dist/crypto/CryptoOps.d.ts +2 -2
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +4 -3
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.mjs +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.mjs +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
- package/dist/error/NativeAuthError.mjs +1 -1
- package/dist/error/NativeAuthErrorCodes.mjs +1 -1
- package/dist/error/NestedAppAuthError.mjs +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/interaction_client/BaseInteractionClient.d.ts +0 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +2 -3
- 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 +4 -4
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts +1 -12
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +28 -111
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts +3 -3
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +59 -50
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +3 -5
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +9 -23
- 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 +2 -12
- package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts +1 -6
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +2 -24
- package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
- package/dist/interaction_handler/InteractionHandler.d.ts +6 -13
- package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +30 -61
- package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts +14 -7
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +30 -15
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts +2 -2
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +13 -7
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/naa/BridgeError.mjs +1 -1
- package/dist/naa/BridgeProxy.mjs +1 -1
- package/dist/naa/BridgeStatusCode.mjs +1 -1
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +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/operatingcontext/UnknownOperatingContext.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/response/ResponseHandler.d.ts +8 -0
- package/dist/response/ResponseHandler.d.ts.map +1 -0
- package/dist/response/ResponseHandler.mjs +46 -0
- package/dist/response/ResponseHandler.mjs.map +1 -0
- 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 +7 -14
- package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +17 -30
- package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
- package/dist/utils/BrowserUtils.mjs +1 -1
- package/lib/msal-browser.cjs +18434 -61
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +3037 -3733
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +68 -66
- package/package.json +2 -2
- package/src/app/PublicClientApplication.ts +4 -3
- package/src/app/PublicClientNext.ts +7 -5
- package/src/cache/BrowserCacheManager.ts +29 -50
- package/src/cache/TokenCache.ts +5 -4
- package/src/controllers/ControllerFactory.ts +30 -49
- package/src/controllers/IController.ts +0 -6
- package/src/controllers/StandardController.ts +70 -85
- package/src/crypto/CryptoOps.ts +5 -3
- package/src/index.ts +1 -0
- package/src/interaction_client/BaseInteractionClient.ts +1 -2
- package/src/interaction_client/NativeInteractionClient.ts +4 -3
- package/src/interaction_client/PopupClient.ts +72 -196
- package/src/interaction_client/RedirectClient.ts +111 -100
- package/src/interaction_client/SilentAuthCodeClient.ts +1 -12
- package/src/interaction_client/SilentIframeClient.ts +17 -44
- package/src/interaction_client/SilentRefreshClient.ts +5 -19
- package/src/interaction_client/StandardInteractionClient.ts +2 -48
- package/src/interaction_handler/InteractionHandler.ts +39 -112
- package/src/interaction_handler/RedirectHandler.ts +52 -30
- package/src/interaction_handler/SilentHandler.ts +12 -5
- package/src/packageMetadata.ts +1 -1
- package/src/response/ResponseHandler.ts +73 -0
- package/src/utils/BrowserProtocolUtils.ts +17 -36
|
@@ -7,17 +7,14 @@ import {
|
|
|
7
7
|
AuthorizationCodePayload,
|
|
8
8
|
CommonAuthorizationCodeRequest,
|
|
9
9
|
AuthorizationCodeClient,
|
|
10
|
-
AuthorityFactory,
|
|
11
|
-
Authority,
|
|
12
|
-
INetworkModule,
|
|
13
10
|
CcsCredential,
|
|
14
11
|
Logger,
|
|
15
12
|
ServerError,
|
|
16
13
|
IPerformanceClient,
|
|
17
14
|
PerformanceEvents,
|
|
18
15
|
invokeAsync,
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
CcsCredentialType,
|
|
17
|
+
ServerAuthorizationCodeResponse,
|
|
21
18
|
} from "@azure/msal-common";
|
|
22
19
|
|
|
23
20
|
import { BrowserCacheManager } from "../cache/BrowserCacheManager";
|
|
@@ -25,10 +22,8 @@ import {
|
|
|
25
22
|
createBrowserAuthError,
|
|
26
23
|
BrowserAuthErrorCodes,
|
|
27
24
|
} from "../error/BrowserAuthError";
|
|
28
|
-
import { TemporaryCacheKeys } from "../utils/BrowserConstants";
|
|
29
25
|
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
30
|
-
|
|
31
|
-
export type InteractionParams = {};
|
|
26
|
+
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
|
|
32
27
|
|
|
33
28
|
/**
|
|
34
29
|
* Abstract class which defines operations for a browser interaction handling class.
|
|
@@ -58,36 +53,20 @@ export class InteractionHandler {
|
|
|
58
53
|
* Function to handle response parameters from hash.
|
|
59
54
|
* @param locationHash
|
|
60
55
|
*/
|
|
61
|
-
async
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
authority: Authority,
|
|
65
|
-
networkModule: INetworkModule
|
|
56
|
+
async handleCodeResponse(
|
|
57
|
+
response: ServerAuthorizationCodeResponse,
|
|
58
|
+
request: AuthorizationUrlRequest
|
|
66
59
|
): Promise<AuthenticationResult> {
|
|
67
60
|
this.performanceClient.addQueueMeasurement(
|
|
68
|
-
PerformanceEvents.
|
|
69
|
-
|
|
61
|
+
PerformanceEvents.HandleCodeResponse,
|
|
62
|
+
request.correlationId
|
|
70
63
|
);
|
|
71
|
-
// Check that location hash isn't empty.
|
|
72
|
-
if (!locationHash) {
|
|
73
|
-
throw createBrowserAuthError(BrowserAuthErrorCodes.hashEmptyError);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Handle code response.
|
|
77
|
-
const stateKey = this.browserStorage.generateStateKey(state);
|
|
78
|
-
const requestState = this.browserStorage.getTemporaryCache(stateKey);
|
|
79
|
-
if (!requestState) {
|
|
80
|
-
throw createClientAuthError(
|
|
81
|
-
ClientAuthErrorCodes.stateNotFound,
|
|
82
|
-
"Cached State"
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
64
|
|
|
86
65
|
let authCodeResponse;
|
|
87
66
|
try {
|
|
88
67
|
authCodeResponse = this.authModule.handleFragmentResponse(
|
|
89
|
-
|
|
90
|
-
|
|
68
|
+
response,
|
|
69
|
+
request.state
|
|
91
70
|
);
|
|
92
71
|
} catch (e) {
|
|
93
72
|
if (
|
|
@@ -108,8 +87,8 @@ export class InteractionHandler {
|
|
|
108
87
|
PerformanceEvents.HandleCodeResponseFromServer,
|
|
109
88
|
this.logger,
|
|
110
89
|
this.performanceClient,
|
|
111
|
-
|
|
112
|
-
)(authCodeResponse,
|
|
90
|
+
request.correlationId
|
|
91
|
+
)(authCodeResponse, request);
|
|
113
92
|
}
|
|
114
93
|
|
|
115
94
|
/**
|
|
@@ -122,65 +101,46 @@ export class InteractionHandler {
|
|
|
122
101
|
*/
|
|
123
102
|
async handleCodeResponseFromServer(
|
|
124
103
|
authCodeResponse: AuthorizationCodePayload,
|
|
125
|
-
|
|
126
|
-
authority: Authority,
|
|
127
|
-
networkModule: INetworkModule,
|
|
104
|
+
request: AuthorizationUrlRequest,
|
|
128
105
|
validateNonce: boolean = true
|
|
129
106
|
): Promise<AuthenticationResult> {
|
|
130
107
|
this.performanceClient.addQueueMeasurement(
|
|
131
108
|
PerformanceEvents.HandleCodeResponseFromServer,
|
|
132
|
-
|
|
109
|
+
request.correlationId
|
|
133
110
|
);
|
|
134
111
|
this.logger.trace(
|
|
135
112
|
"InteractionHandler.handleCodeResponseFromServer called"
|
|
136
113
|
);
|
|
137
114
|
|
|
138
|
-
// Handle code response.
|
|
139
|
-
const stateKey = this.browserStorage.generateStateKey(state);
|
|
140
|
-
const requestState = this.browserStorage.getTemporaryCache(stateKey);
|
|
141
|
-
if (!requestState) {
|
|
142
|
-
throw createClientAuthError(
|
|
143
|
-
ClientAuthErrorCodes.stateNotFound,
|
|
144
|
-
"Cached State"
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Get cached items
|
|
149
|
-
const nonceKey = this.browserStorage.generateNonceKey(requestState);
|
|
150
|
-
const cachedNonce = this.browserStorage.getTemporaryCache(nonceKey);
|
|
151
|
-
|
|
152
115
|
// Assign code to request
|
|
153
116
|
this.authCodeRequest.code = authCodeResponse.code;
|
|
154
117
|
|
|
155
118
|
// Check for new cloud instance
|
|
156
119
|
if (authCodeResponse.cloud_instance_host_name) {
|
|
157
120
|
await invokeAsync(
|
|
158
|
-
this.
|
|
121
|
+
this.authModule.updateAuthority.bind(this.authModule),
|
|
159
122
|
PerformanceEvents.UpdateTokenEndpointAuthority,
|
|
160
123
|
this.logger,
|
|
161
124
|
this.performanceClient,
|
|
162
|
-
|
|
163
|
-
)(
|
|
164
|
-
authCodeResponse.cloud_instance_host_name,
|
|
165
|
-
authority,
|
|
166
|
-
networkModule
|
|
167
|
-
);
|
|
125
|
+
request.correlationId
|
|
126
|
+
)(authCodeResponse.cloud_instance_host_name, request.correlationId);
|
|
168
127
|
}
|
|
169
128
|
|
|
170
129
|
// Nonce validation not needed when redirect not involved (e.g. hybrid spa, renewing token via rt)
|
|
171
130
|
if (validateNonce) {
|
|
172
|
-
|
|
131
|
+
// TODO: Assigning "response nonce" to "request nonce" is confusing. Refactor the function doing validation to accept request nonce directly
|
|
132
|
+
authCodeResponse.nonce = request.nonce || undefined;
|
|
173
133
|
}
|
|
174
134
|
|
|
175
|
-
authCodeResponse.state =
|
|
135
|
+
authCodeResponse.state = request.state;
|
|
176
136
|
|
|
177
137
|
// Add CCS parameters if available
|
|
178
138
|
if (authCodeResponse.client_info) {
|
|
179
139
|
this.authCodeRequest.clientInfo = authCodeResponse.client_info;
|
|
180
140
|
} else {
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
this.authCodeRequest.ccsCredential =
|
|
141
|
+
const ccsCred = this.createCcsCredentials(request);
|
|
142
|
+
if (ccsCred) {
|
|
143
|
+
this.authCodeRequest.ccsCredential = ccsCred;
|
|
184
144
|
}
|
|
185
145
|
}
|
|
186
146
|
|
|
@@ -190,62 +150,29 @@ export class InteractionHandler {
|
|
|
190
150
|
PerformanceEvents.AuthClientAcquireToken,
|
|
191
151
|
this.logger,
|
|
192
152
|
this.performanceClient,
|
|
193
|
-
|
|
153
|
+
request.correlationId
|
|
194
154
|
)(this.authCodeRequest, authCodeResponse)) as AuthenticationResult;
|
|
195
|
-
this.browserStorage.cleanRequestByState(state);
|
|
196
155
|
return tokenResponse;
|
|
197
156
|
}
|
|
198
157
|
|
|
199
158
|
/**
|
|
200
|
-
*
|
|
201
|
-
* @param cloudInstanceHostname
|
|
202
|
-
* @param authority
|
|
203
|
-
* @param networkModule
|
|
204
|
-
*/
|
|
205
|
-
protected async updateTokenEndpointAuthority(
|
|
206
|
-
cloudInstanceHostname: string,
|
|
207
|
-
authority: Authority,
|
|
208
|
-
networkModule: INetworkModule
|
|
209
|
-
): Promise<void> {
|
|
210
|
-
this.performanceClient.addQueueMeasurement(
|
|
211
|
-
PerformanceEvents.UpdateTokenEndpointAuthority,
|
|
212
|
-
this.authCodeRequest.correlationId
|
|
213
|
-
);
|
|
214
|
-
const cloudInstanceAuthorityUri = `https://${cloudInstanceHostname}/${authority.tenant}/`;
|
|
215
|
-
const cloudInstanceAuthority =
|
|
216
|
-
await AuthorityFactory.createDiscoveredInstance(
|
|
217
|
-
cloudInstanceAuthorityUri,
|
|
218
|
-
networkModule,
|
|
219
|
-
this.browserStorage,
|
|
220
|
-
authority.options,
|
|
221
|
-
this.logger,
|
|
222
|
-
this.performanceClient,
|
|
223
|
-
this.authCodeRequest.correlationId
|
|
224
|
-
);
|
|
225
|
-
this.authModule.updateAuthority(cloudInstanceAuthority);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Looks up ccs creds in the cache
|
|
159
|
+
* Build ccs creds if available
|
|
230
160
|
*/
|
|
231
|
-
protected
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.authModule.logger.errorPii(
|
|
245
|
-
`Cache credential could not be parsed: ${cachedCcsCred}`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
161
|
+
protected createCcsCredentials(
|
|
162
|
+
request: AuthorizationUrlRequest
|
|
163
|
+
): CcsCredential | null {
|
|
164
|
+
if (request.account) {
|
|
165
|
+
return {
|
|
166
|
+
credential: request.account.homeAccountId,
|
|
167
|
+
type: CcsCredentialType.HOME_ACCOUNT_ID,
|
|
168
|
+
};
|
|
169
|
+
} else if (request.loginHint) {
|
|
170
|
+
return {
|
|
171
|
+
credential: request.loginHint,
|
|
172
|
+
type: CcsCredentialType.UPN,
|
|
173
|
+
};
|
|
248
174
|
}
|
|
175
|
+
|
|
249
176
|
return null;
|
|
250
177
|
}
|
|
251
178
|
}
|
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
import {
|
|
7
7
|
AuthorizationCodeClient,
|
|
8
8
|
CommonAuthorizationCodeRequest,
|
|
9
|
-
ICrypto,
|
|
10
|
-
Authority,
|
|
11
|
-
INetworkModule,
|
|
12
9
|
Logger,
|
|
13
10
|
ServerError,
|
|
14
11
|
IPerformanceClient,
|
|
15
12
|
createClientAuthError,
|
|
16
13
|
ClientAuthErrorCodes,
|
|
14
|
+
CcsCredential,
|
|
15
|
+
invokeAsync,
|
|
16
|
+
PerformanceEvents,
|
|
17
|
+
ServerAuthorizationCodeResponse,
|
|
17
18
|
} from "@azure/msal-common";
|
|
18
19
|
import {
|
|
19
20
|
createBrowserAuthError,
|
|
@@ -21,37 +22,36 @@ import {
|
|
|
21
22
|
} from "../error/BrowserAuthError";
|
|
22
23
|
import { ApiId, TemporaryCacheKeys } from "../utils/BrowserConstants";
|
|
23
24
|
import { BrowserCacheManager } from "../cache/BrowserCacheManager";
|
|
24
|
-
import { InteractionHandler, InteractionParams } from "./InteractionHandler";
|
|
25
25
|
import { INavigationClient } from "../navigation/INavigationClient";
|
|
26
26
|
import { NavigationOptions } from "../navigation/NavigationOptions";
|
|
27
27
|
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
28
28
|
|
|
29
|
-
export type RedirectParams =
|
|
29
|
+
export type RedirectParams = {
|
|
30
30
|
navigationClient: INavigationClient;
|
|
31
31
|
redirectTimeout: number;
|
|
32
32
|
redirectStartPage: string;
|
|
33
33
|
onRedirectNavigate?: (url: string) => void | boolean;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export class RedirectHandler
|
|
37
|
-
|
|
36
|
+
export class RedirectHandler {
|
|
37
|
+
authModule: AuthorizationCodeClient;
|
|
38
|
+
browserStorage: BrowserCacheManager;
|
|
39
|
+
authCodeRequest: CommonAuthorizationCodeRequest;
|
|
40
|
+
logger: Logger;
|
|
41
|
+
performanceClient: IPerformanceClient;
|
|
38
42
|
|
|
39
43
|
constructor(
|
|
40
44
|
authCodeModule: AuthorizationCodeClient,
|
|
41
45
|
storageImpl: BrowserCacheManager,
|
|
42
46
|
authCodeRequest: CommonAuthorizationCodeRequest,
|
|
43
47
|
logger: Logger,
|
|
44
|
-
browserCrypto: ICrypto,
|
|
45
48
|
performanceClient: IPerformanceClient
|
|
46
49
|
) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
performanceClient
|
|
53
|
-
);
|
|
54
|
-
this.browserCrypto = browserCrypto;
|
|
50
|
+
this.authModule = authCodeModule;
|
|
51
|
+
this.browserStorage = storageImpl;
|
|
52
|
+
this.authCodeRequest = authCodeRequest;
|
|
53
|
+
this.logger = logger;
|
|
54
|
+
this.performanceClient = performanceClient;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -142,19 +142,12 @@ export class RedirectHandler extends InteractionHandler {
|
|
|
142
142
|
* Handle authorization code response in the window.
|
|
143
143
|
* @param hash
|
|
144
144
|
*/
|
|
145
|
-
async
|
|
146
|
-
|
|
147
|
-
state: string
|
|
148
|
-
authority: Authority,
|
|
149
|
-
networkModule: INetworkModule
|
|
145
|
+
async handleCodeResponse(
|
|
146
|
+
response: ServerAuthorizationCodeResponse,
|
|
147
|
+
state: string
|
|
150
148
|
): Promise<AuthenticationResult> {
|
|
151
149
|
this.logger.verbose("RedirectHandler.handleCodeResponse called");
|
|
152
150
|
|
|
153
|
-
// Check that location hash isn't empty.
|
|
154
|
-
if (!locationHash) {
|
|
155
|
-
throw createBrowserAuthError(BrowserAuthErrorCodes.hashEmptyError);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
151
|
// Interaction is completed - remove interaction status.
|
|
159
152
|
this.browserStorage.setInteractionInProgress(false);
|
|
160
153
|
|
|
@@ -171,7 +164,7 @@ export class RedirectHandler extends InteractionHandler {
|
|
|
171
164
|
let authCodeResponse;
|
|
172
165
|
try {
|
|
173
166
|
authCodeResponse = this.authModule.handleFragmentResponse(
|
|
174
|
-
|
|
167
|
+
response,
|
|
175
168
|
requestState
|
|
176
169
|
);
|
|
177
170
|
} catch (e) {
|
|
@@ -197,10 +190,15 @@ export class RedirectHandler extends InteractionHandler {
|
|
|
197
190
|
|
|
198
191
|
// Check for new cloud instance
|
|
199
192
|
if (authCodeResponse.cloud_instance_host_name) {
|
|
200
|
-
await
|
|
193
|
+
await invokeAsync(
|
|
194
|
+
this.authModule.updateAuthority.bind(this.authModule),
|
|
195
|
+
PerformanceEvents.UpdateTokenEndpointAuthority,
|
|
196
|
+
this.logger,
|
|
197
|
+
this.performanceClient,
|
|
198
|
+
this.authCodeRequest.correlationId
|
|
199
|
+
)(
|
|
201
200
|
authCodeResponse.cloud_instance_host_name,
|
|
202
|
-
|
|
203
|
-
networkModule
|
|
201
|
+
this.authCodeRequest.correlationId
|
|
204
202
|
);
|
|
205
203
|
}
|
|
206
204
|
|
|
@@ -226,4 +224,28 @@ export class RedirectHandler extends InteractionHandler {
|
|
|
226
224
|
this.browserStorage.cleanRequestByState(state);
|
|
227
225
|
return tokenResponse;
|
|
228
226
|
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Looks up ccs creds in the cache
|
|
230
|
+
*/
|
|
231
|
+
protected checkCcsCredentials(): CcsCredential | null {
|
|
232
|
+
// Look up ccs credential in temp cache
|
|
233
|
+
const cachedCcsCred = this.browserStorage.getTemporaryCache(
|
|
234
|
+
TemporaryCacheKeys.CCS_CREDENTIAL,
|
|
235
|
+
true
|
|
236
|
+
);
|
|
237
|
+
if (cachedCcsCred) {
|
|
238
|
+
try {
|
|
239
|
+
return JSON.parse(cachedCcsCred) as CcsCredential;
|
|
240
|
+
} catch (e) {
|
|
241
|
+
this.authModule.logger.error(
|
|
242
|
+
"Cache credential could not be parsed"
|
|
243
|
+
);
|
|
244
|
+
this.authModule.logger.errorPii(
|
|
245
|
+
`Cache credential could not be parsed: ${cachedCcsCred}`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
229
251
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
PerformanceEvents,
|
|
10
10
|
invokeAsync,
|
|
11
11
|
invoke,
|
|
12
|
+
ServerResponseType,
|
|
12
13
|
} from "@azure/msal-common";
|
|
13
14
|
import {
|
|
14
15
|
createBrowserAuthError,
|
|
@@ -67,7 +68,8 @@ export async function monitorIframeForHash(
|
|
|
67
68
|
pollIntervalMilliseconds: number,
|
|
68
69
|
performanceClient: IPerformanceClient,
|
|
69
70
|
logger: Logger,
|
|
70
|
-
correlationId: string
|
|
71
|
+
correlationId: string,
|
|
72
|
+
responseType: ServerResponseType
|
|
71
73
|
): Promise<string> {
|
|
72
74
|
performanceClient.addQueueMeasurement(
|
|
73
75
|
PerformanceEvents.SilentHandlerMonitorIframeForHash,
|
|
@@ -110,12 +112,17 @@ export async function monitorIframeForHash(
|
|
|
110
112
|
return;
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
let responseString = "";
|
|
116
|
+
if (contentWindow) {
|
|
117
|
+
if (responseType === ServerResponseType.QUERY) {
|
|
118
|
+
responseString = contentWindow.location.search;
|
|
119
|
+
} else {
|
|
120
|
+
responseString = contentWindow.location.hash;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
116
123
|
window.clearTimeout(timeoutId);
|
|
117
124
|
window.clearInterval(intervalId);
|
|
118
|
-
resolve(
|
|
125
|
+
resolve(responseString);
|
|
119
126
|
}, pollIntervalMilliseconds);
|
|
120
127
|
}).finally(() => {
|
|
121
128
|
invoke(
|
package/src/packageMetadata.ts
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ICrypto,
|
|
8
|
+
Logger,
|
|
9
|
+
ServerAuthorizationCodeResponse,
|
|
10
|
+
UrlUtils,
|
|
11
|
+
} from "@azure/msal-common";
|
|
12
|
+
import {
|
|
13
|
+
BrowserAuthErrorCodes,
|
|
14
|
+
createBrowserAuthError,
|
|
15
|
+
} from "../error/BrowserAuthError";
|
|
16
|
+
import { extractBrowserRequestState } from "../utils/BrowserProtocolUtils";
|
|
17
|
+
import { InteractionType } from "../utils/BrowserConstants";
|
|
18
|
+
|
|
19
|
+
export function deserializeResponse(
|
|
20
|
+
responseString: string,
|
|
21
|
+
responseLocation: string,
|
|
22
|
+
logger: Logger
|
|
23
|
+
): ServerAuthorizationCodeResponse {
|
|
24
|
+
// Deserialize hash fragment response parameters.
|
|
25
|
+
const serverParams = UrlUtils.getDeserializedResponse(responseString);
|
|
26
|
+
if (!serverParams) {
|
|
27
|
+
if (!UrlUtils.stripLeadingHashOrQuery(responseString)) {
|
|
28
|
+
// Hash or Query string is empty
|
|
29
|
+
logger.error(
|
|
30
|
+
`The request has returned to the redirectUri but a ${responseLocation} is not present. It's likely that the ${responseLocation} has been removed or the page has been redirected by code running on the redirectUri page.`
|
|
31
|
+
);
|
|
32
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.hashEmptyError);
|
|
33
|
+
} else {
|
|
34
|
+
logger.error(
|
|
35
|
+
`A ${responseLocation} is present in the iframe but it does not contain known properties. It's likely that the ${responseLocation} has been replaced by code running on the redirectUri page.`
|
|
36
|
+
);
|
|
37
|
+
logger.errorPii(
|
|
38
|
+
`The ${responseLocation} detected is: ${responseString}`
|
|
39
|
+
);
|
|
40
|
+
throw createBrowserAuthError(
|
|
41
|
+
BrowserAuthErrorCodes.hashDoesNotContainKnownProperties
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return serverParams;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the interaction type that the response object belongs to
|
|
50
|
+
*/
|
|
51
|
+
export function validateInteractionType(
|
|
52
|
+
response: ServerAuthorizationCodeResponse,
|
|
53
|
+
browserCrypto: ICrypto,
|
|
54
|
+
interactionType: InteractionType
|
|
55
|
+
): void {
|
|
56
|
+
if (!response.state) {
|
|
57
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.noStateInHash);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const platformStateObj = extractBrowserRequestState(
|
|
61
|
+
browserCrypto,
|
|
62
|
+
response.state
|
|
63
|
+
);
|
|
64
|
+
if (!platformStateObj) {
|
|
65
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.unableToParseState);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (platformStateObj.interactionType !== interactionType) {
|
|
69
|
+
throw createBrowserAuthError(
|
|
70
|
+
BrowserAuthErrorCodes.stateInteractionTypeMismatch
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -8,8 +8,6 @@ import {
|
|
|
8
8
|
ICrypto,
|
|
9
9
|
RequestStateObject,
|
|
10
10
|
ProtocolUtils,
|
|
11
|
-
ServerAuthorizationCodeResponse,
|
|
12
|
-
UrlString,
|
|
13
11
|
createClientAuthError,
|
|
14
12
|
ClientAuthErrorCodes,
|
|
15
13
|
} from "@azure/msal-common";
|
|
@@ -18,41 +16,24 @@ export type BrowserStateObject = {
|
|
|
18
16
|
interactionType: InteractionType;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const requestStateObj: RequestStateObject =
|
|
37
|
-
ProtocolUtils.parseRequestState(browserCrypto, state);
|
|
38
|
-
return requestStateObj.libraryState.meta as BrowserStateObject;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw createClientAuthError(ClientAuthErrorCodes.invalidState);
|
|
41
|
-
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts the BrowserStateObject from the state string.
|
|
21
|
+
* @param browserCrypto
|
|
22
|
+
* @param state
|
|
23
|
+
*/
|
|
24
|
+
export function extractBrowserRequestState(
|
|
25
|
+
browserCrypto: ICrypto,
|
|
26
|
+
state: string
|
|
27
|
+
): BrowserStateObject | null {
|
|
28
|
+
if (!state) {
|
|
29
|
+
return null;
|
|
42
30
|
}
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
): ServerAuthorizationCodeResponse {
|
|
51
|
-
if (!locationHash) {
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const hashUrlString = new UrlString(locationHash);
|
|
56
|
-
return UrlString.getDeserializedHash(hashUrlString.getHash());
|
|
32
|
+
try {
|
|
33
|
+
const requestStateObj: RequestStateObject =
|
|
34
|
+
ProtocolUtils.parseRequestState(browserCrypto, state);
|
|
35
|
+
return requestStateObj.libraryState.meta as BrowserStateObject;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw createClientAuthError(ClientAuthErrorCodes.invalidState);
|
|
57
38
|
}
|
|
58
39
|
}
|