xamarin / Xamarin.Auth

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

UWP Exception on Auth_Error #400

Open bmarchionni opened 5 years ago

bmarchionni commented 5 years ago

Xamarin.Auth Issue

IF BUG, INCLUDE THIS PART:

Version

Steps to reproduce

  1. Authenticate using a WebAuthenticator page that has a cancel button.
  2. When the user clicks the Cancel button Authenticator.Error fires and triggers an unhandleable exception from Xamarin.Auth.UniversalWindowsPlatform/WebAuthenticatorPage.Events.xaml.cs line 101

Platform:

Expected behaviour

The Authenticator.Error should be raised but no exception should be throw.

Actual behaviour

An exception is thrown that can't be caught

I believe we just need to change Xamarin.Auth.UniversalWindowsPlatform/WebAuthenticatorPage.Events.xaml.cs line 101 from

private void auth_Error(object sender, AuthenticatorErrorEventArgs e) { throw new Xamarin.Auth.AuthException("Auth Error"); }

to

private void auth_Error(object sender, AuthenticatorErrorEventArgs e) { System.Diagnostics.Debug.WriteLine("Auth Error" + e.Message); }

luka454 commented 5 years ago

I can confirm this behavior. On each error, including canceling authentication (navigating back), the uncatchable exception is thrown and cause the application to crash.

This behavior is different from Android and iOS, where exception is not thrown and you can handle errors on your own.

Workaround

  1. Copy WebAuthetnicatorPage (with .cs and xaml) to your UWP project and remove throwing the exception
  2. Copy OAuthLoginPresenter to you UWP project and change pageType to your WebAuthenticatorPage: System.Type pageType = typeof(WebAuthenticatorPage); (line 23).
  3. Setup you OAuthLoginPresenter to be used. To do that remove default initialization AuthenticationConfiguration.Init() from UWP project and register your OAuthLoginPresenter with following code:
Xamarin.Auth.Presenters.OAuthLoginPresenter.PlatformLogin = (authenticator) =>
{
     var presenter = new OAuthLoginPresenter(); // Your OAuthLoginPresenter
     presenter.Login(authenticator);
};
MGohil commented 4 years ago

@luka454

I am getting the following exception on successful Authentication credentials entered into web page.

Xamarin.Auth.AuthException: Auth Error at Xamarin.Auth.WebAuthenticatorPage.auth_Error(Object sender, AuthenticatorErrorEventArgs e) at Xamarin.Auth.Authenticator.<>cDisplayClass30_0.b0() at Plugin.Threading.UIThreadRunInvoker.<>cDisplayClass0_0.b0()

Tried the above Workaround, but no debug point hit on added classes.

NOTE :

  1. I didn't find AuthenticationConfiguration.Init() in my code.
  2. I added following code inside my UWP project's OnLaunchedmethod.
Xamarin.Auth.Presenters.OAuthLoginPresenter.PlatformLogin = (authenticator) =>
{
    var presenter = new UWPOAuthLoginPresenter(); // Your OAuthLoginPresenter
    presenter.Login(authenticator);
};
  1. The authentication was working few days ago. This error suddenly started poping in.
  2. However, Android and iOS is working fine.

Thanks.

ValonK commented 4 years ago

We currently have the same issue :( is there any workaround ?