AzureAD / azure-activedirectory-library-for-objc

The ADAL SDK for Objective C gives you the ability to add support for Work Accounts to your iOS and macOS applications with just a few lines of additional code. This SDK gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support.
MIT License
177 stars 113 forks source link

ADAL Objective-C crash when calling Acquire Token #1566

Closed mjcheetham closed 3 years ago

mjcheetham commented 3 years ago

A customer of Git Credential Manager Core on macOS is finding that our Objective-C authentication helper which uses ADAL Objective-C to call acquireTokenWithResource crashes.

See the original issue: https://github.com/microsoft/Git-Credential-Manager-Core/issues/264

ADAL Version: 4.0.0 macOS Version: 11.1 (20C69)

The crashing thread has the following call-stack, which seems to include only ADAL/MSID and WebKit:

Thread 3 Crashed:: Dispatch queue: com.apple.root.default-qos
0 com.apple.WebKit 0x00007fff3c5bf7b3 WTFCrashWithInfo(int, char const*, char const*, int) + 19
1 com.apple.WebKit 0x00007fff3c75de03 WebKit::runInitializationCode(void*) + 73
2 libc++.1.dylib 0x00007fff20304e6a std::__1::__call_once(unsigned long volatile&, void*, void ()(void)) + 139
3 com.apple.WebKit 0x00007fff3c56363e WebKit::InitializeWebKit2() + 58
4 com.apple.WebKit 0x00007fff3c824687 -[WKWebViewConfiguration init] + 63
5 Microsoft.Authentication.Helper 0x00000001004f2634 __37+[MSIDWebviewUIController initialize]_block_invoke + 24
6 libdispatch.dylib 0x00007fff201c47c7 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff201c596b dispatch_once_callout + 20
8 Microsoft.Authentication.Helper 0x00000001004f261a +[MSIDWebviewUIController initialize] + 35
9 libobjc.A.dylib 0x00007fff2021bba5 CALLING_SOME+initialize_METHOD + 17
10 libobjc.A.dylib 0x00007fff2021c52e initializeNonMetaClass + 726
11 libobjc.A.dylib 0x00007fff2021c2b4 initializeNonMetaClass + 92
12 libobjc.A.dylib 0x00007fff2021c2b4 initializeNonMetaClass + 92
13 libobjc.A.dylib 0x00007fff2021d5b0 initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt&, bool) + 232
14 libobjc.A.dylib 0x00007fff2020d2b2 lookUpImpOrForward + 1126
15 libobjc.A.dylib 0x00007fff2020c89b _objc_msgSend_uncached + 75
16 Microsoft.Authentication.Helper 0x00000001004b8595 -[MSIDAADWebviewFactory embeddedWebviewSessionFromConfiguration:customWebview:context:] + 226
17 Microsoft.Authentication.Helper 0x00000001004f0f83 +[MSIDWebviewAuthorization startEmbeddedWebviewAuthWithConfiguration:oauth2Factory:webview:context:completionHandler:] + 169
18 Microsoft.Authentication.Helper 0x00000001004a9b60 +[ADWebAuthController(Internal) startWithRequest:promptBehavior:context:completion:] + 1109
19 Microsoft.Authentication.Helper 0x0000000100497694 -[ADAuthenticationRequest(WebRequest) requestCode:] + 421
20 Microsoft.Authentication.Helper 0x00000001004949a2 -[ADAuthenticationRequest(AcquireToken) requestTokenImpl:] + 348
21 Microsoft.Authentication.Helper 0x0000000100494610 -[ADAuthenticationRequest(AcquireToken) requestToken:] + 526
22 Microsoft.Authentication.Helper 0x0000000100494088 -[ADAuthenticationRequest(AcquireToken) validatedAcquireToken:] + 142
23 Microsoft.Authentication.Helper 0x0000000100493cbb __70-[ADAuthenticationRequest(AcquireToken) acquireToken:completionBlock:]_block_invoke.160 + 414
24 Microsoft.Authentication.Helper 0x000000010049ab23 __74-[ADAuthorityValidation checkAuthority:validateAuthority:completionBlock:]_block_invoke + 137
25 libdispatch.dylib 0x00007fff201c35dd _dispatch_call_block_and_release + 12
26 libdispatch.dylib 0x00007fff201c47c7 _dispatch_client_callout + 8
27 libdispatch.dylib 0x00007fff201c6e1c _dispatch_queue_override_invoke + 777
28 libdispatch.dylib 0x00007fff201d3857 _dispatch_root_queue_drain + 326
29 libdispatch.dylib 0x00007fff201d3fb8 _dispatch_worker_thread2 + 92
30 libsystem_pthread.dylib 0x00007fff2036c453 _pthread_wqthread + 244
31 libsystem_pthread.dylib 0x00007fff2036b467 start_wqthread + 15
antrix1989 commented 3 years ago

Thanks @mjcheetham, I will take a look.

antrix1989 commented 3 years ago

@mjcheetham looks like you are trying to present a web view on a background thread. Make sure you are always calling acquireTokenWithResource:... on the main thread.