【问题标题】:Xamarin.Forms WebAuthenticator and GoogleXamarin.Forms WebAuthenticator 和 Google
【发布时间】:2020-11-22 10:53:33
【问题描述】:

我现在一直在尝试从 Xamarin.Forms 中的谷歌用户那里检索谷歌日历信息。

我使用 Xamarin.Auth 开始了我的旅程,但我无法解决登录后我的 Android 应用程序中的 CustomTab 不会关闭的问题。多年来似乎一直是一个持续存在的问题,并且有几个人提出了黑客来解决这个问题。此时我放弃了 Xamarin.Auth

所以我尝试使用 Xamarin.Forms Web Authenticator 来检索日历信息。该文档没有提到如何通过 Google 进行身份验证,所以我尝试了这个

var authResult = await WebAuthenticator.AuthenticateAsync(
                new Uri("https://accounts.google.com/o/oauth2/auth"), // auth url
                new Uri("packageNameOfMyApp://");        // redirect url

我收到无效请求错误

如何选择 AuthenticateAsync 的第一个参数才能正确通过 Google 进行身份验证? 在通过Google Developer Console 配置我的应用程序登录后,我是否必须以某种方式对从我的应用程序中获得的 ClientId 进行编码?

【问题讨论】:

  • 尝试使用https://accounts.google.com/o/oauth2/v2/auth作为第一个参数。
  • 我仍然收到相同的错误消息(错误 400 无效请求)
  • 如果我用浏览器点击这个端点,实际上也是如此
  • 问题应该是重定向url引起的。
  • 如果我遵循 Web Authenticator 文档,重定向 url 应该是应用程序名称(我假设清单文件中列出的包名称)后跟 :// 我尝试更改此 url 但我仍然我得到同样的错误。我按照文档中的建议实现了 WebAuthenticatorCallbackActivity 类

标签: xamarin.forms google-authentication xamarin.essentials


【解决方案1】:

无法将 WebAuthenticator 与 Google 一起使用。 Google 需要网络浏览器进行身份验证,并且不允许您的应用自行进行身份验证。出于同样的原因,在应用中使用 WebView 导航到 Google 身份验证站点的方法将失败

【讨论】:

    【解决方案2】:

    不确定您是否仍在寻找解决方案,但这个视频https://www.youtube.com/watch?v=g8oh-dvfW1k&ab_channel=XamarinGuy 给了我一些可靠的信息。

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2022-06-15
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2023-01-10
      相关资源
      最近更新 更多