xamarin / Xamarin.Auth

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

Unable to show OAuth Login from Xamarin.Forms modal Page #425

Open less0 opened 4 years ago

less0 commented 4 years ago

Xamarin.Auth Issue

Version

Steps to reproduce

  1. Open a Xamarin.Forms modal page
  2. Create an OAuth2Authenticator
  3. Create an OAuthLoginPresenter
  4. Call OAuthLoginPresenter.Login from the modal page

I've attached a MCVE that reproduces the issue:

ModalAuthTest.zip

Platform:

(I am using the Visual Studio 16.4 P2 because debugging failed with 16.3, but the issue occurred when using 16.3 with Xamarin.iOS 13.2 and mono 6.0, too)

Expected behaviour

The application should show the OAuth login page to authenticate the user with the app.

Actual behaviour

The web view is not shown and a warning is displayed on the debug output

Warning: Attempt to present <SFSafariViewController: 0x10aa65600> on <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x10725f950> whose view is not in the window hierarchy!
monkeypro commented 4 years ago

I have the same problem! Any solution or work around?

Midnayt commented 4 years ago

Same issue! `Warning: Attempt to present <UINavigationController: 0x7f9da004b200> on <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x7f9d96d017e0> whose view is not in the window hierarchy! [unspecified] container_system_group_path_for_identifier: error = (container_error_t)53 WF: === Starting WebFilter logging for process ClassifappNew.iOS WF: _WebFilterIsActive returning: NO [ProcessSuspension] 0x122495720 - ProcessAssertion::processAssertionWasInvalidated() [ProcessSuspension] 0x1224956c0 - ProcessAssertion::processAssertionWasInvalidated()`

Any progress on fixing this issue???

vsotomayor commented 4 years ago

My application is not showing the OAuth login page to authenticate the user with the app either. Any solution or work around?

AlexSchuetz commented 4 years ago

I experienced a similar problem, but with another warning. The problem originated in the Presenter choosing the wrong ViewController. Fortunately I was able to inject my own Presenter:

public class MyPresenter
{
        UIKit.UIViewController rootViewController;

        public void Login(Authenticator authenticator)
        {
            authenticator.Completed += AuthenticatorCompleted;

            rootViewController = GetCurrentUIController();
            rootViewController.PresentViewController(authenticator.GetUI(), true, null);
        }

        void AuthenticatorCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            rootViewController?.DismissViewController(true, null);
            ((Authenticator)sender).Completed -= AuthenticatorCompleted;
            // always think of the GC ;)
            rootViewController = null;
        }

        private UIViewController GetCurrentUIController()
        {
            UIViewController viewController;
            var window = UIApplication.SharedApplication.KeyWindow;
            if (window == null)
            {
                throw new InvalidOperationException("There's no current active window");
            }

            viewController = window.RootViewController;

            while (viewController.PresentedViewController != null)
            {
                viewController = viewController.PresentedViewController;
            }

            return viewController;
        }
}

and in AppDelegate I changed:

//global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init();
global::Xamarin.Auth.Presenters.OAuthLoginPresenter.PlatformLogin = (authenticator) =>
{
        var oauthLogin = new MyPresenter();
        oauthLogin.Login(authenticator);
};

Currently I still have a error dialog popping up (cannot open URL), but authentication works. I will post an update as soon as I got rid of the error dialog.

UPDATE The "Cannot open URL"-error dialog was due to a configuration error (wrong URL scheme in info.plist).

andygikling commented 3 years ago

Bump. I'm stuck on the same thing. What's crazy is this used to work, from what I can tell, in earlier versions of iOS (before iOS 14.x).

I have a code base which was tested and working with Xamarin.Auth 1.6.x on iOS 12 and this wasn't an issue. Now I try to run the code on newer phones and it doesn't work.

@AlexSchuetz I've tried your solution with no luck. Can you please give us some more information about how to work around this? My browser never appears to do the login.

AlexSchuetz commented 3 years ago

@andygikling I am sorry. I recently moved away from Xamarin.Auth since it hasn't seen updates for 2 years now. This means, that it still uses the old android-support packages and not the new androidx ones.

I first started my own fork of this and removed the old android-support dependencies. But finally I dropped this and implemented it on my own. There were too many issues, too many usages of deprecated apis and the code was very complex and filled with features that are unneccessary for my usecases.

Xamarin.Essentials now has a Webauthenticator you could use as replacement to some degree. But probably you'd have to implement your used flow on top. I decided not to use Xamarin.Essetials Webauthenticator for now as it has IMHO still some issues. I.e. if you use it on iOS you will always see a confirmation-dialog first asking you if you agree to authenticate against the given server (not only on first authentication).

vsotomayor commented 3 years ago

Thank you for the info!

Sent from my iPhone

On Apr 28, 2021, at 2:09 AM, Alexander Schuetz @.***> wrote:

 @andygikling I am sorry. I recently moved away from Xamarin.Auth since it hasn't seen updates for 2 years now. This means, that it still uses the old android-support packages and not the new androidx ones.

I first started my own fork of this and removed the old android-support dependencies. But finally I dropped this and implemented it on my own. There were too many issues, too many usages of deprecated apis and the code was very complex and filled with features that are unneccessary for my usecases.

Xamarin.Essentials now has a Webauthenticator you could use as replacement to some degree. But probably you'd have to implement your used flow on top. I decided not to use Xamarin.Essetials Webauthenticator for now as it has IMHO still some issues. I.e. if you use it on iOS you will always see a confirmation-dialog first asking you if you agree to authenticate against the given server (not only on first authentication).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

andygikling commented 3 years ago

Yes @AlexSchuetz thank you for the insight. I might have to step back and rethink this a bit here.