Xamarin.Auth Google Presenter not closing

IU am using Xamarin.Auth in a Xamarin.Forms app. Everything works perfectly except that the presenter does not close. It simply moves to the background.

I have a LoginVIewModel (MVVM) in my shared project whcih creates the OAuth2Authenticator and the Intercept Activity in the Android app.

In my In GoogleAuthInterceptor Activity in the create I have

protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);      

        // Convert Android.Net.Url to Uri
        var uri = new Uri(Intent.Data.ToString());

        // Send the URI to the Authenticator for continuation
        App.OAuth2Authenticator?.OnPageLoading(uri);

        Finish();
}

I show the presenter as follows:

var loginUI = App.OAuth2Authenticator.GetUI(Forms.Context);
Forms.Context.StartActivity(loginUI);           

I have also tried using:

var oAuthLoginPresenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
oAuthLoginPresenter.Login(App.OAuth2Authenticator);

The presenter shows fine using wither way, user approves and I am redirected back to my App and the completed event on the OAuth2Authenticator is called where I can use the account to get the user information as required

private async void OAuth2Authenticator_Completed(object sender, AuthenticatorCompletedEventArgs e)
    {
        try
        {

            // dismiss presenter???

            if(e.IsAuthenticated)
            {
                App.Account = e.Account;

                var oAuthUser = await GetUserDetails();     

                // Add account to store
                AccountStore.Create().Save(App.Account, App.APP_NAME_KEY);

                // Set the App User for this session
                App.User = oAuthUser ;

            }
        }
        catch(Exception ex)
        {
            throw;
        }
    }

At this stage if I click the application button on my phone I have see the presenter is still in the background. How can I shut it down in the view model once the completed is called or is there some other way I should be doing it?

Thanks,

Posts

  • LoanBurgerLoanBurger NZMember ✭✭

    I have managed t suppress the CustomTabsConfiguration message by setting the closing message to null; CustomTabsConfiguration.CustomTabsClosingMessage = null; But this does not solve the presenter issue.

  • LoanBurgerLoanBurger NZMember ✭✭

    @moljac

    More on this: I can now confirm this works as expected as long as Google Chrome is the default browser on the phone. If I use the native Samsung browser on my Galaxy S8+ then the browser remains open in the background.

Sign In or Register to comment.