0

this method works fine but only issue is that after user enter google email & password, it doesn't go back to HomePage in app. user has to manually tap on close button and than it goes to HomePage inside app

i found similar code online and they all seem to have the same thing. not sure what i am missing

async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
    var authenticator = sender as OAuth2Authenticator;
    if (authenticator != null)
    {
        authenticator.Completed -= OnAuthCompleted;
        authenticator.Error -= OnAuthError;
    }

    User user = null;
    if (e.IsAuthenticated)
    {
        var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
        var response = await request.GetResponseAsync();
        if (response != null)
        {
            string userJson = await response.GetResponseTextAsync();
            user = JsonConvert.DeserializeObject<User>(userJson);
        }

        if (user != null)
        {
             store.Delete(account, Constants.AppName);
            var route = $"{ nameof(HomePage)}";
            await Shell.Current.GoToAsync(route);
        }

        await store.SaveAsync(account = e.Account, Constants.AppName);
    }
}//end of method

android project

[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "com.googleusercontent.apps.59233251-abcd" },
DataPath = "/oauth2redirect")]
public class CustomUrlSchemeInterceptorActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

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

        // Load redirectUrl page
        AuthenticationState.Authenticator.OnPageLoading(uri);

        Finish();
    }
}
Star Gates
  • 123
  • 4
  • anything or how to debug this? onlything i could find online was `store.Delete(account, Constants.AppName);` but doesnt work – Star Gates Jun 26 '21 at 21:39
  • 1
    Find one thread about [Xamarin.Auth Google not auto close when done login](https://stackoverflow.com/questions/47938171/xamarin-auth-google-not-auto-close-when-done-login), you can take a look. – Cherry Bu - MSFT Jun 28 '21 at 03:09

0 Answers0