xamarin / Xamarin.Auth

Xamarin.Auth
Apache License 2.0
541 stars 351 forks source link

Cancelling Twitter login causes 401 and crashes Xamarin Forms App #304

Closed specialtrevor closed 6 years ago

specialtrevor commented 6 years ago

Xamarin.Auth Issue

Using Xamarin.Auth for login with Twitter.

Version

private void Twitter_Clicked(object sender, EventArgs e)
{
            var auth = new OAuth1Authenticator(
                                consumerKey: Constants.TwitterConsumerKey,
                                consumerSecret: Constants.TwitterConsumerSecret,
                                requestTokenUrl: new Uri(Constants.TwitterRequestTokenUrl),
                                authorizeUrl: new Uri(Constants.TwitterAuthorizeUrl),
                                accessTokenUrl: new Uri(Constants.TwitterAccessTokenUrl),
                                callbackUrl: new Uri(Constants.TwitterCallbackUrl),
                                isUsingNativeUI: false)
            {
                AllowCancel = true,
                ShowErrors = false
            };
            auth.Completed += OnOAuthCompleted;
            auth.Error += OnOAuthError;

            var presenter = new OAuthLoginPresenter();
            presenter.Login(auth);
}

Steps to reproduce

  1. Trigger above code
  2. On Twitter screen click 'Cancel'
  3. Then click 'Return to ' button

Note: it errors before it hits any callback. I can't seem to trap it.

Platform:

Expected behaviour

Exception should not be thrown. If instead of hitting Cancel you use phone back button it fires an Error event which is picked up in OnAuthError(). I think it should do the same.

Actual behaviour

Exception raised, see Stack Trace below.

Stack Trace

06-26 15:10:42.156 I/MonoDroid( 6789): UNHANDLED EXCEPTION:
06-26 15:10:42.177 I/MonoDroid( 6789): System.AggregateException: One or more errors occurred. ---> System.Net.WebException: The remote server returned an error: (401) Authorization Required.
06-26 15:10:42.177 I/MonoDroid( 6789):   at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00052] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1031 
06-26 15:10:42.177 I/MonoDroid( 6789):   at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 
06-26 15:10:42.178 I/MonoDroid( 6789):    --- End of inner exception stack trace ---
06-26 15:10:42.178 I/MonoDroid( 6789):   at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2164 
06-26 15:10:42.178 I/MonoDroid( 6789):   at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562 
06-26 15:10:42.178 I/MonoDroid( 6789):   at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532 
06-26 15:10:42.178 I/MonoDroid( 6789):   at Xamarin.Auth.OAuth1Authenticator.GetAccessTokenAsync () [0x00071] in <7c8b52626aea4529928c6992480c7d50>:0 
06-26 15:10:42.178 I/MonoDroid( 6789):   at Xamarin.Auth.OAuth1Authenticator.OnPageLoaded (System.Uri url) [0x00050] in <7c8b52626aea4529928c6992480c7d50>:0 
06-26 15:10:42.178 I/MonoDroid( 6789):   at Xamarin.Auth.WebAuthenticatorActivity+Client.OnPageFinished (Android.Webkit.WebView view, System.String url) [0x00017] in <7c8b52626aea4529928c6992480c7d50>:0 
06-26 15:10:42.178 I/MonoDroid( 6789):   at Android.Webkit.WebViewClient.n_OnPageFinished_Landroid_webkit_WebView_Ljava_lang_String_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_view, System.IntPtr native_url) [0x00018] in /Users/builder/data/lanes/5945/342b2ce9/source/monodroid/external/xamarin-android/src/Mono.Android/obj/Release/android-27/mcw/Android.Webkit.WebViewClient.cs:202 
06-26 15:10:42.178 I/MonoDroid( 6789):   at (wrapper dynamic-method) System.Object.586ccde1-6287-4d21-bedc-c32695000fdb(intptr,intptr,intptr,intptr)
06-26 15:10:42.178 I/MonoDroid( 6789): ---> (Inner Exception #0) System.Net.WebException: The remote server returned an error: (401) Authorization Required.
06-26 15:10:42.178 I/MonoDroid( 6789):   at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00052] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1031 
06-26 15:10:42.178 I/MonoDroid( 6789):   at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 <---
jaydeepkumar commented 6 years ago

have same issues do you have any idea about remove this error

newky2k commented 6 years ago

@specialtrevor @jaydeepkumar could you please provide a small sample project that reproduces this issue so we can investigate

newky2k commented 6 years ago

no reponse for two weeks, closing

specialtrevor commented 6 years ago

Please re-open. I've already given a lot of information above. When I get chance to write a new app to show it I will, but 2 weeks at the end of summer isn't a very long time to have to wait for a response.

DeanZhuo commented 3 years ago

Please re-open, many people still having this issues