6

I am using Xamarin.Form to write a Android app. I have successfully implemented the OAuth and I can sign in and get the user information using OAuth2Authenticator.

When the user clicks signup/Login I show the OAuthLoginPresenter as follows:

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

This works great and the user sees the login page.

When the user clicks Allow the completed Event on the OAuth2Authenticator instance fires as expected and the user is once again back looking at the app.

However this is where my problem is - I get a notification:

If CustomTabs Login Screen does not close automatically close CustomTabs by Navigating back to the app.

Thing is though I am back at the app. If I look at all my open apps I can see the login screen is still running in the back ground so that presenter has not closed.

In my intercept Activity which gets the redirect looks like this:

[Activity(Label = "GoogleAuthInterceptor")]
[IntentFilter
(
    actions: new[] { Intent.ActionView },
    Categories = new[]
    {
            Intent.CategoryDefault,
            Intent.CategoryBrowsable
    },
    DataSchemes = new[]
    {
        // First part of the redirect url (Package name)
        "com.myapp.platform"
    },
    DataPaths = new[]
    {
        // Second part of the redirect url (Path)
        "/oauth2redirect"
    }
)]

public class GoogleAuthInterceptor: Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here
        Android.Net.Uri uri_android = Intent.Data;

        // Convert Android Url to C#/netxf/BCL System.Uri
        Uri uri_netfx = new Uri(uri_android.ToString());

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

        Finish();
    }
}

Am I missing a step in here to close that presenter? Any other ideas please?

UPDATE:

I have now found that using Chrome as the default browser works fine and presenter is closed. But if I use a Samsung browser as my default browser - it does not close.

So I need a way to close it manually.

TResponse
  • 3,940
  • 7
  • 43
  • 63
  • 2
    Can't see any problem with your code, if that notification doesn't effect the OAuth flow, would you mind directly set `CustomTabsConfiguration.CustomTabsClosingMessage = null;`? – Grace Feng Oct 16 '17 at 06:33
  • 1
    Hey there, I will try that thank you. The flow issue is that the presenter stays open in the background. so even though the user has clicked Allow and is returned to the app if I click to switch between apps I can still see the presenter running in the background. I have posted the question on Xamarin forums as well. Maybe a bug.. – TResponse Oct 16 '17 at 20:04
  • @GraceFeng-MSFT Thanks the message has now gone. But as per my above comment the presenter continues to run. – TResponse Oct 16 '17 at 21:25
  • 1
    I have a slightly different problem, after successful authenticaltion, I see the https://www.google.com. How do I hide this screen and show another screen instead? – Casperonian Mar 24 '18 at 09:15
  • @Casperonian I have the same problem. Did you manage to fix this? – Gilles Apr 13 '18 at 12:48

1 Answers1

1

Just set property to null when initializing Xamarin.Auth in your main activity:

//don't show warning message when closing account selection page
CustomTabsConfiguration.CustomTabsClosingMessage = null;
antferr
  • 100
  • 1
  • 10
  • I have tried that. It does not work. The Auth view moves to the background but is not actually closed when using any browser other than Chrome. - Chrome works as expected. – TResponse May 15 '18 at 09:15