Skip to content

Commit 4dfd66f

Browse files
authored
Merge pull request #723 from AzureAD/oldalton/fixed_ntlm_prompt_keywindow
Fixed NTLM crash when app has no keywindow
2 parents e8a64ad + f4719a8 commit 4dfd66f

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

IdentityCore/src/webview/embeddedWebview/challangeHandlers/MSIDNTLMHandler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ + (BOOL)handleChallenge:(NSURLAuthenticationChallenge *)challenge
5353
MSID_LOG_INFO(nil, @"Attempting to handle NTLM challenge");
5454
MSID_LOG_INFO_PII(nil, @"Attempting to handle NTLM challenge host: %@", challenge.protectionSpace.host);
5555

56-
[MSIDNTLMUIPrompt presentPrompt:^(NSString *username, NSString *password, BOOL cancel)
56+
[MSIDNTLMUIPrompt presentPromptWithWebView:webview completion:^(NSString *username, NSString *password, BOOL cancel)
5757
{
5858
if (cancel)
5959
{

IdentityCore/src/webview/embeddedWebview/ui/MSIDNTLMUIPrompt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323

2424
#import <Foundation/Foundation.h>
2525

26+
@class WKWebView;
27+
2628
@interface MSIDNTLMUIPrompt : NSObject
2729

28-
+ (void)presentPrompt:(void (^)(NSString *username, NSString *password, BOOL cancel))completionHandler;
30+
+ (void)presentPromptWithWebView:(WKWebView *)webview completion:(void (^)(NSString *username, NSString *password, BOOL cancel))completionHandler;
2931
+ (void)dismissPrompt;
3032

3133
@end

IdentityCore/src/webview/embeddedWebview/ui/ios/MSIDNTLMUIPrompt.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "MSIDAppExtensionUtil.h"
2626
#import "UIApplication+MSIDExtensions.h"
2727
#import "MSIDMainThreadUtil.h"
28+
#import <WebKit/WebKit.h>
2829

2930
@implementation MSIDNTLMUIPrompt
3031

@@ -42,9 +43,8 @@ + (void)dismissPrompt
4243
}];
4344
}
4445

45-
+ (void)presentPrompt:(void (^)(NSString *username, NSString *password, BOOL cancel))block
46+
+ (void)presentPromptWithWebView:(__unused WKWebView *)webview completion:(void (^)(NSString *username, NSString *password, BOOL cancel))block
4647
{
47-
4848
if ([MSIDAppExtensionUtil isExecutingInAppExtension])
4949
{
5050
block(nil, nil, YES);

IdentityCore/src/webview/embeddedWebview/ui/mac/MSIDNTLMUIPrompt.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "MSIDNTLMUIPrompt.h"
2626
#import "MSIDCredentialCollectionController.h"
2727
#import "MSIDMainThreadUtil.h"
28+
#import <WebKit/WebKit.h>
2829

2930
@interface MSIDNTLMUIPrompt ()
3031

@@ -46,7 +47,7 @@ + (void)dismissPrompt
4647
}];
4748
}
4849

49-
+ (void)presentPrompt:(void (^)(NSString *username, NSString *password, BOOL cancel))completionHandler
50+
+ (void)presentPromptWithWebView:(WKWebView *)webview completion:(void (^)(NSString *username, NSString *password, BOOL cancel))completionHandler
5051
{
5152
[MSIDMainThreadUtil executeOnMainThreadIfNeeded:^{
5253
NSAlert *alert = [NSAlert new];
@@ -62,7 +63,9 @@ + (void)presentPrompt:(void (^)(NSString *username, NSString *password, BOOL can
6263

6364
[[alert window] setInitialFirstResponder:view.usernameField];
6465

65-
[alert beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSModalResponse returnCode)
66+
NSWindow *window = webview.window ? webview.window : [NSApp keyWindow];
67+
68+
[alert beginSheetModalForWindow:window completionHandler:^(NSModalResponse returnCode)
6669
{
6770
// The first button being added is "Login" button
6871
if (returnCode == NSAlertFirstButtonReturn)

IdentityCore/tests/MSIDLoggerTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ - (void)setUp
4343

4444
- (void)testLog_whenLogLevelNothingMessageValid_shouldNotThrow
4545
{
46+
[self keyValueObservingExpectationForObject:[MSIDTestLogger sharedLogger] keyPath:@"callbackInvoked" expectedValue:@1];
4647
XCTAssertNoThrow([[MSIDLogger sharedLogger] logLevel:MSIDLogLevelNothing context:nil correlationId:nil isPII:NO format:@"Message"]);
48+
[self waitForExpectationsWithTimeout:1 handler:nil];
4749
}
4850

4951
- (void)testLog_whenLogLevelErrorMessageNil_shouldNotThrow

0 commit comments

Comments
 (0)