3

Currently I am developing Xamarin Forms application and I added Google Authentication. Here is my code from PCL:

var authenticator = new OAuth2Authenticator(
    clientId,
    null,
    Constants.Scope,
    new Uri(Constants.AuthorizeUrl),
    new Uri(redirectUri),
    new Uri(Constants.AccessTokenUrl),

    null,
    true);

authenticator.Completed += this.OnAuthCompleted;
authenticator.Error += this.OnAuthError;

AuthenticationState.Authenticator = authenticator;

var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);

I am using latest version of Xamarin.Auth, which is 1.5.0.3 This is what I receive: Screenshot

I went through many articles and code examples, but looks like maybe google updated their authentication once again. Link 1, Link 2, Link 3, Link 4. Event on official page for Xamarin.Forms example is invalid and not working Link 5.

I checked several code examples, but again no success, Sample 1 and multiple samples here. I download source and tried to use it, expecting that it's working, but they're failing as well.

Do you have solution for this issue or any article, which is up to date and you know it's working. As well code sample would be brilliant.

Thanks in advance!

  • That looks look a Genymotion emulator, does it have Chrome installed via the Play store? – SushiHangover Aug 18 '17 at 07:25
  • I haven't installed anything extra to genymotion. http://prntscr.com/g9ye5c http://prntscr.com/g9yei5 It has by default google, but I can try install not chrome. –  Aug 18 '17 at 07:37

1 Answers1

3

On Android, Google requires that Chrome Custom Tabs be used now instead of a WebView due to security reasons.

If you are running an emulator (or device) that does not have Chrome installed (preinstalled from the OEM or via the Play Store), then Xamarin.Auth will default back to using a WebView. This would be accepted by Google in certain parts of the world (i.e. China where Chrome might not be pre-installed by the device OEMs), otherwise Google will reject WebView clients via the disallowed_useragent error.

If you are running a GenyMotion emulator, install Chrome via the Play Store. If you do not have the Play Store installed, install the GApps (via http://opengapps.org)

SushiHangover
  • 73,120
  • 10
  • 106
  • 165