Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.Auth - Multiple authentication error popups causing app crash

Sumit_PaulSumit_Paul Member ✭✭
edited October 20 in Xamarin.Forms

I am using Xamarin.Auth and OAuth2Authenticator for login. At times, I am receiving infinite authentication error popups. From the app center crashlytics, I am receiving the following exception message: Java.Lang.RuntimeException: Could not read input channel file descriptors from parcel.

JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Dialog.Show ()
ActivityEx.ShowError (Android.App.Activity activity, System.String title, System.String message)
ActivityEx.ShowError (Android.App.Activity activity, System.String title, System.Exception exception)
WebAuthenticatorActivity.<OnCreate>b__4_1 (System.Object s, Xamarin.Auth.AuthenticatorErrorEventArgs e)
Authenticator+<>c__DisplayClass32_0.<RaiseErrorEvent>b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.49(intptr,intptr)
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
android.view.InputChannel.nativeReadFromParcel(Native Method)
android.view.InputChannel.readFromParcel InputChannel.java:148
android.view.IWindowSession$Stub$Proxy.addToDisplay IWindowSession.java:804
android.view.ViewRootImpl.setView ViewRootImpl.java:737
android.view.WindowManagerGlobal.addView WindowManagerGlobal.java:359
android.view.WindowManagerImpl.addView WindowManagerImpl.java:94
android.app.Dialog.show Dialog.java:330
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run RunnableImplementor.java:30
android.app.Activity.runOnUiThread Activity.java:6201
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run RunnableImplementor.java:30
android.os.Handler.handleCallback Handler.java:790
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:164
android.app.ActivityThread.main ActivityThread.java:6528
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:438
com.android.internal.os.ZygoteInit.main ZygoteInit.java:807

I am assuming that the above app crash is taking place because of the infinite popups. Need some help regarding this.

Code snippet for Authentication error:

private async void AuthenticationError(object sender, AuthenticatorErrorEventArgs e)
    {
            var authenticator = sender as OAuth2Authenticator;
            if (authenticator != null)
            {
                authenticator.Completed -= async (_sender, _e) => await AuthenticationCompleted(_sender, _e);
                authenticator.Error -= AuthenticationError;
            }

    }

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Cancel the authenticator should be able to solve the problem .

       public async void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
            //-------------------------------------------------------
            {
                var authenticator = sender as OAuth2Authenticator;
                if (authenticator != null)
                {
                    authenticator.Completed -= OnAuthComplete;
                    authenticator.Error -= OnAuthError;
                }
    
                authenticator.OnCancelled(); //calm down
    
                Debug.WriteLine("External Authentication error: " + e.Message);
                await CloseExternalLoginPage(); // basically PopModalAsync
            }
    
    

    Check https://forums.xamarin.com/discussion/comment/294208/#Comment_294208 .

Sign In or Register to comment.