Share via


AdalException : authentication_ui_failed with ADAL and Xamarin Forms Android

Recently I was helping a client with an Azure Active Directory integrated project ( ADAL not MSAL for some various reasons ) . All was going well and good as I plugged away with the various integration pieces.   We are targeting Xamarin Forms on this project.   Luckily there was a great blog post by Mayur at https://blog.xamarin.com/put-adal-xamarin-forms/ .

Typically I will start with UWP as a 'sanity check' to make sure things are working right. I provisioned up my Xamarin UWP project and had it running smoothly, no problems. My IOS project also also worked smoothly, authenticating against my test O365 environment like a champ.

Next up was my Android project.  I followed the steps Mayur suggested and gave the program a run. Oooo. Nasty messages! Yuk.

If we peek hard you can see the error message "Authentication_ui_failed: The browser based authentication dialog failed to complete" show up.

Various activities were tried including adjusting manifest capability request and other such things. No luck.

Turns out the fix was the adjust the TLS from Default to a specific TLS Implementation.  You can adjust this by navigating into your Android project properties and navigating  Android Options > Advanced > SSL/TLS Implementation from "Default" to Managed TLS 1.1 OR Native TLS 1.2+

Who knew? I sure didn't. And after a mere, well, quite a number of hours digging this out, I'm sharing it with you. Hopefully the SEO gods will bless you and you find this post when hunting for the error.

Interesting to note, and I'll try and find out why, this only occurs before the value of SSL/TLS Implementation is changed for the first time. Once you change from "Default" to one of the other values, even if you go back to Default, the error will not occur.  Time to dig out some of the deep Xamarin brains out for an answer.

Tested on physical hardware and HAXM Android 7.1 Emulator image several times. To test it you need to build the Android Xamarin Forms project up from scratch. Mayur's instructions are great for this at [ https://blog.xamarin.com/put-adal-xamarin-forms/ ].

In the spirit of sharing I've posted a new ADALForForms sample until Mayur gets his repository updated. My sample can be found at [ https://github.com/jhealy/xammutts/tree/master/ADALForForms ]. The xammutts repo I posted is .NET Standard with Android, IOS, and UWP support. Mayur had WP, IOS, and Android. Note since we are targeting .NET Standard with the UWP, the UWP run is limited to Fall Creator's Update ( build 16299 ) and later. FCU introduces .NET Standard to UWP.   Windows Phone is left as an exercise to the coder.

Partial exception dump for SEO purposes below.


 AcquireTokenHandlerBase.cs: === Token Acquisition started:
12-31 12:19:55.341 I/        ( 4651):   Authority: https://login.microsoftonline.com/M365x947151.onmicrosoft.com/
12-31 12:19:55.341 I/        ( 4651):  Resource: https://graph.windows.net
12-31 12:19:55.341 I/        ( 4651):    ClientId: 8f580ff3-2ab3-469b-bd43-158c581757da
12-31 12:19:55.341 I/        ( 4651):     CacheType: null
12-31 12:19:55.341 I/        ( 4651):    Authentication Target: User
12-31 12:19:55.341 I/        ( 4651):    
12-31 12:19:55.463 V/        ( 4651): 2017-12-31T17:19:55.4308620Z: 1663fe86-17e1-4842-b23e-ca25a43dde8d - AcquireTokenHandlerBase.cs: Loading from cache.
12-31 12:19:55.481 V/        ( 4651): 2017-12-31T17:19:55.4809390Z: 1663fe86-17e1-4842-b23e-ca25a43dde8d - TokenCache.cs: Looking up cache for a token...
12-31 12:19:55.537 I/        ( 4651): 2017-12-31T17:19:55.5378480Z: 1663fe86-17e1-4842-b23e-ca25a43dde8d - TokenCache.cs: No matching token was found in the cache
12-31 12:19:55.729 D/Mono    ( 4651): DllImport attempting to load: '/system/lib64/liblog.so'.
12-31 12:19:55.730 D/Mono    ( 4651): DllImport loaded library '/system/lib64/liblog.so'.
12-31 12:19:55.730 D/Mono    ( 4651): DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so').
12-31 12:19:55.730 D/Mono    ( 4651): Searching for '__android_log_print'.
12-31 12:19:55.730 D/Mono    ( 4651): Probing '__android_log_print'.
12-31 12:19:55.730 D/Mono    ( 4651): Found as '__android_log_print'.
12-31 12:19:55.736 W/monodroid( 4651): JNIEnv.FindClass(Type) caught unexpected exception: Java.Lang.ClassNotFoundException: md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity ---> Java.Lang.ClassNotFoundException: Didn't find class "md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity" on path: DexPathList[[zip file "/data/app/com.devfish.xamarin.ADALForForms-1/base.apk"],nativeLibraryDirectories=[/data/app/com.devfish.xamarin.ADALForForms-1/lib/x86_64, /system/fake-libs64, /data/app/com.devfish.xamarin.ADALForForms-1/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]
12-31 12:19:55.736 W/monodroid( 4651):    --- End of inner exception stack trace ---
12-31 12:19:55.736 W/monodroid( 4651):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00017] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   at Android.Runtime.JNIEnv.FindClass (System.String classname) [0x0003d] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00015] in :0 
12-31 12:19:55.736 W/monodroid( 4651):   --- End of managed Java.Lang.ClassNotFoundException stack trace ---
12-31 12:19:55.736 W/monodroid( 4651): java.lang.ClassNotFoundException: md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity
12-31 12:19:55.736 W/monodroid( 4651):     at java.lang.Class.classForName(Native Method)
12-31 12:19:55.736 W/monodroid( 4651):    at java.lang.Class.forName(Class.java:400)
12-31 12:19:55.736 W/monodroid( 4651):    at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.n_onClick(Native Method)
12-31 12:19:55.737 W/monodroid( 4651):    at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.onClick(ButtonRenderer_ButtonClickListener.java:30)
12-31 12:19:55.737 W/monodroid( 4651):     at android.view.View.performClick(View.java:5637)
12-31 12:19:55.737 W/monodroid( 4651):     at android.view.View$PerformClick.run(View.java:22429)
12-31 12:19:55.737 W/monodroid( 4651):    at android.os.Handler.handleCallback(Handler.java:751)
12-31 12:19:55.737 W/monodroid( 4651):    at android.os.Handler.dispatchMessage(Handler.java:95)
12-31 12:19:55.737 W/monodroid( 4651):    at android.os.Looper.loop(Looper.java:154)
12-31 12:19:55.737 W/monodroid( 4651):    at android.app.ActivityThread.main(ActivityThread.java:6119)
12-31 12:19:55.737 W/monodroid( 4651):  at java.lang.reflect.Method.invoke(Native Method)
12-31 12:19:55.737 W/monodroid( 4651):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
12-31 12:19:55.737 W/monodroid( 4651):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
12-31 12:19:55.737 W/monodroid( 4651): Caused by: java.lang.ClassNotFoundException: Didn't find class "md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity" on path: DexPathList[[zip file "/data/app/com.devfish.xamarin.ADALForForms-1/base.apk"],nativeLibraryDirectories=[/data/app/com.devfish.xamarin.ADALForForms-1/lib/x86_64, /system/fake-libs64, /data/app/com.devfish.xamarin.ADALForForms-1/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]
12-31 12:19:55.737 W/monodroid( 4651):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-31 12:19:55.737 W/monodroid( 4651):     at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
12-31 12:19:55.737 W/monodroid( 4651):  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
12-31 12:19:55.737 W/monodroid( 4651):  ... 13 more
12-31 12:19:55.737 W/monodroid( 4651): 
12-31 12:19:55.859 E/        ( 4651): 2017-12-31T17:19:55.8588900Z: 1663fe86-17e1-4842-b23e-ca25a43dde8d - AcquireTokenHandlerBase.cs: Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: authentication_ui_failed: The browser based authentication dialog failed to complete ---> Java.Lang.ClassNotFoundException: md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity ---> Java.Lang.ClassNotFoundException: Didn't find class "md5673452a39546f0a71deda1ad064ecc65.AuthenticationAgentActivity" on path: DexPathList[[zip file "/data/app/com.devfish.xamarin.ADALForForms-1/base.apk"],nativeLibraryDirectories=[/data/app/com.devfish.xamarin.ADALForForms-1/lib/x86_64, /system/fake-libs64, /data/app/com.devfish.xamarin.ADALForForms-1/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]
12-31 12:19:55.859 E/        ( 4651):    --- End of inner exception stack trace ---