Skip to content

Commit d12266d

Browse files
authored
Merge pull request #1535 from AzureAD/jarias/jit-troubleshooting-legacy-flow
JIT troubleshooting in legacy auth flow
2 parents ebefa86 + 3b68bd0 commit d12266d

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

IdentityCore/src/MSIDConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ extern NSString * _Nonnull const MSID_BROWSER_RESPONSE_SWITCH_BROWSER_RESUME;
213213

214214
extern NSString * _Nonnull const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY;
215215
extern NSString * _Nonnull const MSID_FLIGHT_SUPPORT_DUNA_CBA;
216+
extern NSString * _Nonnull const MSID_FLIGHT_DISABLE_JIT_TROUBLESHOOTING_LEGACY_AUTH;
216217
extern NSString * _Nonnull const MSID_FLIGHT_CLIENT_SFRT_STATUS;
217218
extern NSString * _Nonnull const MSID_FLIGHT_DISABLE_PREFERRED_IDENTITY_CBA;
218219

IdentityCore/src/MSIDConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
NSString *const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY = @"use_v2_web_response_factory";
8787
NSString *const MSID_FLIGHT_SUPPORT_DUNA_CBA = @"support_duna_cba_v2";
88+
NSString *const MSID_FLIGHT_DISABLE_JIT_TROUBLESHOOTING_LEGACY_AUTH = @"disable_jit_remediation_legacy_auth";
8889
NSString *const MSID_FLIGHT_CLIENT_SFRT_STATUS = @"sfrt_v2";
8990
NSString *const MSID_FLIGHT_DISABLE_PREFERRED_IDENTITY_CBA = @"dis_pre_iden_cba";
9091

IdentityCore/src/webview/embeddedWebview/MSIDAADOAuthEmbeddedWebviewController.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#import "MSIDWorkPlaceJoinConstants.h"
3030
#import "MSIDPKeyAuthHandler.h"
3131
#import "MSIDWorkPlaceJoinUtil.h"
32+
#import "MSIDWebAuthNUtil.h"
33+
#import "MSIDFlightManager.h"
34+
#import "MSIDConstants.h"
3235

3336
#if !MSID_EXCLUDE_WEBKIT
3437

@@ -67,6 +70,28 @@ - (BOOL)decidePolicyAADForNavigationAction:(WKNavigationAction *)navigationActio
6770
BOOL isBrokerUrl = [@"msauth" caseInsensitiveCompare:requestURL.scheme] == NSOrderedSame;
6871
BOOL isBrowserUrl = [@"browser" caseInsensitiveCompare:requestURL.scheme] == NSOrderedSame;
6972

73+
if (![MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_DISABLE_JIT_TROUBLESHOOTING_LEGACY_AUTH])
74+
{
75+
// When not running in SSO extension, the CA block page will return with "https" scheme instead of "browser"
76+
if (requestURL && ![MSIDWebAuthNUtil amIRunningInExtension] &&
77+
self.externalDecidePolicyForBrowserAction &&
78+
[@"https" caseInsensitiveCompare:requestURL.scheme] == NSOrderedSame)
79+
{
80+
// Create new URL replacing 'https' scheme with 'browser' scheme
81+
NSURL *legacyFlowUrl = [NSURL URLWithString:[NSString stringWithFormat:@"browser%@", [requestURL.absoluteString substringFromIndex:5]]];
82+
NSURLRequest *challengeResponse = self.externalDecidePolicyForBrowserAction(self, legacyFlowUrl);
83+
84+
if (challengeResponse)
85+
{
86+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, self.context, @"Found AAD policy for navigation using https url and externalDecidePolicyForBrowserAction in legacy auth flow.");
87+
decisionHandler(WKNavigationActionPolicyCancel);
88+
[self loadRequest:challengeResponse];
89+
90+
return YES;
91+
}
92+
}
93+
}
94+
7095
if (isBrokerUrl || isBrowserUrl)
7196
{
7297
// Let external code decide if browser url is allowed to continue

IdentityCore/tests/MSIDAADOAuthEmbeddedWebviewControllerTests.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import <XCTest/XCTest.h>
2727
#import "MSIDAADOAuthEmbeddedWebviewController.h"
2828
#import "MSIDWKNavigationActionMock.h"
29+
#import "MSIDWebAuthNUtil.h"
2930

3031
#if !MSID_EXCLUDE_WEBKIT
3132

@@ -195,6 +196,67 @@ - (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserAc
195196
XCTAssertTrue(result);
196197
}
197198

199+
- (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserActionLegacyFlow_shouldCancelActionAndReturnYesAndCallExternalMethod
200+
{
201+
[MSIDWebAuthNUtil setAmIRunningInExtension:NO];
202+
203+
MSIDAADOAuthEmbeddedWebviewController *webVC = [[MSIDAADOAuthEmbeddedWebviewController alloc]
204+
initWithStartURL:[NSURL URLWithString:@"https://contoso.com/oauth/authorize"]
205+
endURL:[NSURL URLWithString:@"endurl://host"]
206+
webview:nil
207+
customHeaders:nil
208+
platfromParams:nil
209+
context:nil];
210+
211+
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"https://www.web-cp.com/check"]];
212+
MSIDWKNavigationActionMock *action = [[MSIDWKNavigationActionMock alloc] initWithRequest:request];
213+
214+
XCTestExpectation *expectationExternalDecisionHandler = [self expectationWithDescription:@"external decision handler"];
215+
XCTestExpectation *expectationDecisionHandler = [self expectationWithDescription:@"decision handler"];
216+
217+
webVC.externalDecidePolicyForBrowserAction = ^NSURLRequest *(MSIDOAuth2EmbeddedWebviewController *webView, NSURL *url) {
218+
219+
XCTAssertNotNil(webView);
220+
XCTAssertEqualObjects([url absoluteString], @"browser://www.web-cp.com/check");
221+
[expectationExternalDecisionHandler fulfill];
222+
223+
return [[NSURLRequest alloc] initWithURL:url];
224+
};
225+
226+
227+
BOOL result = [webVC decidePolicyAADForNavigationAction:action decisionHandler:^(WKNavigationActionPolicy decision) {
228+
229+
XCTAssertEqual(decision, WKNavigationActionPolicyCancel);
230+
[expectationDecisionHandler fulfill];
231+
}];
232+
233+
[self waitForExpectationsWithTimeout:1.0 handler:nil];
234+
235+
XCTAssertTrue(result);
236+
}
237+
238+
- (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserActionLegacyFlowNonHttps_shouldCancelActionAndReturnNoAndCallExternalMethod
239+
{
240+
[MSIDWebAuthNUtil setAmIRunningInExtension:NO];
241+
242+
MSIDAADOAuthEmbeddedWebviewController *webVC = [[MSIDAADOAuthEmbeddedWebviewController alloc]
243+
initWithStartURL:[NSURL URLWithString:@"https://contoso.com/oauth/authorize"]
244+
endURL:[NSURL URLWithString:@"endurl://host"]
245+
webview:nil
246+
customHeaders:nil
247+
platfromParams:nil
248+
context:nil];
249+
250+
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://www.web-cp.com/check"]];
251+
MSIDWKNavigationActionMock *action = [[MSIDWKNavigationActionMock alloc] initWithRequest:request];
252+
253+
BOOL result = [webVC decidePolicyAADForNavigationAction:action decisionHandler:^(WKNavigationActionPolicy decision) {
254+
XCTAssertEqual(decision, WKNavigationActionPolicyCancel);
255+
}];
256+
257+
XCTAssertFalse(result);
258+
}
259+
198260
@end
199261

200262
#endif

0 commit comments

Comments
 (0)