【问题标题】:xamarin android oauth 403 error - disallowed_useragentxamarin android oauth 403 错误 - disallowed_useragent
【发布时间】:2017-05-24 11:32:23
【问题描述】:

我是 xamarin android 的新手。我正在尝试使用 Google 作为身份提供者在 xamarin android 中实现 OAuth。我已经在谷歌注册了我的应用程序,并获得了我在用户点击登录按钮时使用的客户端 ID 和客户端密码,如下所示。

void OnLoginClicked(object sender, EventArgs e)
    {
        var authenticator = new OAuth2Authenticator(
            Constants.ClientId,
            Constants.ClientSecret,
            Constants.Scope,
            new Uri(Constants.AuthorizeUrl),
            new Uri(Constants.RedirectUrl),
            new Uri(Constants.AccessTokenUrl));

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

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

它重定向到谷歌,但给出 403 错误为“disallowed_useragent”。 根据this,谷歌“不再允许在称为网络视图的嵌入式浏览器中向谷歌发出 OAuth 请求”

在浏览了一些论坛和 stackoverflow 问题后,我知道需要使用
chromecustomtabs

所以我有两个问题

  1. chromecustomtabs 是否有替代解决方案?

  2. 如果上面的答案是否定的,那么如果我理解正确,那么我需要在我的项目中添加以下代码。我的问题是 OnLoginClicked 函数需要做哪些修改?在这种情况下是否需要 OAuth2Authenticator?

我的代码:

var mgr = new CustomTabsActivityManager (this);
mgr.CustomTabsServiceConnected += delegate {
mgr.LaunchUrl ("http://xamarin.com");
};
mgr.BindService ();

任何建议/链接将不胜感激。谢谢。

【问题讨论】:

    标签: c# webview xamarin.android google-oauth


    【解决方案1】:

    请阅读此topicXamarin Auth 1.5.0 支持 CustomTabsIntent。

    【讨论】:

      【解决方案2】:

      这是对您部分问题的回答:

      OAuth2Authenticator 上有一个名为isUsingNativeUI 的参数。您必须将其设置为 true。这将导致 Xamarin.Auth 使用 Android 内部的 CustomTabs 服务而不是 web 视图。

      你的代码变成:

          var authenticator = new OAuth2Authenticator(
              Constants.ClientId,
              Constants.ClientSecret,
              Constants.Scope,
              new Uri(Constants.AuthorizeUrl),
              new Uri(Constants.RedirectUrl),
              new Uri(Constants.AccessTokenUrl),
              null,
              true); // <--  This is it isUsingNativeUI
      

      我希望它是默认值。

      【讨论】:

      • > 希望它是默认值。它会在未来。问题是 - 谷歌是唯一需要本机 ui 的提供者,可以设置其他一些提供者,但这不是强制性的。出于兼容性原因(向后兼容),默认为 false,并且会保留一段时间。
      猜你喜欢
      • 1970-01-01
      • 2019-12-12
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2023-03-12
      • 2022-10-30
      • 2017-08-10
      相关资源
      最近更新 更多