c# - 谷歌登录页面不会在秋季关闭 - xamarin
问题描述
这种方法工作正常,但唯一的问题是用户输入谷歌电子邮件和密码后,它不会回到HomePage
应用程序中。用户必须手动点击关闭按钮,然后才能HomePage
进入应用程序内部
我在网上找到了类似的代码,它们似乎都有相同的东西。不知道我错过了什么
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
安卓项目
[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();
}
}
解决方案
推荐阅读
- angular - *ngFor 生成的 div 列表:第一个元素偶尔将其 id 从 1 更改为“2”或“3”
- opencv - opencv反向透视变换?
- typescript - 在调用 getter 之前,无法等待使用 Typescript 在 Vue 中设置值
- database - 跨多个服务共享数据库的微服务
- javascript - 类型 '' 上不存在属性 '' - 尽管有接口
- python - Plotly go.Indicator:改变值颜色
- c - 如何将 char 变量保存到 char* 结构中?
- python - 为什么Django无法正常运行?
- python - 通过 Python 将文件上传到 DropBox
- arrays - 如何自定义 WP 标签云数组,使其以“_”开头并正常继续