目前我正在开发Xamarin Forms应用程序,我添加了Google身份验证 . 这是我在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);
我正在使用 Xamarin.Auth
的最新版本,这是 1.5.0.3
这是我收到的:Screenshot
我浏览了很多文章和代码示例,但看起来可能谷歌再次更新了他们的身份验证 . Link 1,Link 2,Link 3,Link 4 . Xamarin.Forms示例的官方页面上的事件无效且无效Link 5 .
我检查了几个代码示例,但是再次没有成功,Sample 1和多个样本here . 我下载源代码并尝试使用它,期待它也失败了.2927817_也失败了 .
你有解决这个问题或任何文章的解决方案,这是最新的,你知道它的工作 . 代码示例也很棒 .
提前致谢!
1 回答
在Android上,由于安全原因,Google要求现在使用
Chrome Custom Tabs
而不是WebView
.如果您运行的是未安装Chrome的模拟器(或设备)(从OEM或通过Play商店预安装),则
Xamarin.Auth
将默认返回使用WebView
. Google将在世界某些地区(即中国可能无法通过设备OEM预安装Chrome)接受此操作,否则Google将通过disallowed_useragent
错误拒绝WebView
客户端 .如果您运行的是GenyMotion模拟器,请通过Play商店安装Chrome . 如果您没有安装Play商店,请安装GApps(通过http://opengapps.org)