Xamarin Forms Google Authenticateion, Error: disallowed_useragent

蹲街弑〆低调 提交于 2019-12-23 16:08:22

问题


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!


回答1:


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

  • Modernizing OAuth interactions in Native Apps for Better Usability and Security

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)



来源:https://stackoverflow.com/questions/45750554/xamarin-forms-google-authenticateion-error-disallowed-useragent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!