【问题标题】:getting 403 disallowed user agent in Auth0 Lock for Android在 Android 的 Auth0 Lock 中获取 403 不允许的用户代理
【发布时间】:2017-10-13 20:08:51
【问题描述】:

在我的 android 应用程序中集成了 Auth0 登录。 对于这个集成,我正在关注这个 https://auth0.com/docs/libraries/lock-android

它以前工作正常,但现在我在点击 google 时面临 403 不允许的用户。

当我在谷歌搜索时,我发现了这个: 自 4 月 20 日起,Google 出于安全目的决定阻止来自嵌入式 Web 视图的访问,这就是 Auth0 使用 google 登录失败的原因。

iOS 人员使用以下方法解决了同样的问题:

但在android中没有找到这个

如何解决这个问题。 任何人对此有想法。

我的一段代码:

compile 'com.auth0.android:lock:2.+'

Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain));
            mLock = Lock.newBuilder(auth0, mCallback)
                    //Add parameters to the builder
                    .closable(true)
                    .build(this);
            startActivity(mLock.newIntent(this));

private LockCallback callback = new AuthenticationCallback() {
       @Override
       public void onAuthentication(Credentials credentials) {
          //Authenticated
       }

       @Override
       public void onCanceled() {
          //User pressed back
       }

       @Override
       public void onError(LockException error) {
          //Exception occurred
       }
   };

清单:

<activity
  android:name="com.auth0.android.lock.LockActivity"
  android:label="@string/app_name"
  android:launchMode="singleTask"
  android:screenOrientation="portrait"
  android:theme="@style/MyLock.Theme">
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />

      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />

      <data
        android:host="quikdeal1.auth0.com"
        android:pathPrefix="/android/{YOUR_APP_PACKAGE_NAME}/callback"
        android:scheme="https" />
    </intent-filter>
</activity>

【问题讨论】:

    标签: android google-oauth auth0 auth0-delegated-admin


    【解决方案1】:

    正如你所说,谷歌决定阻止来自嵌入式WebViews 的访问。 我也发生了同样的事情,我只是自己放置了用户代理。 它看起来像这样:

    public static final String USER_AGENT_FAKE = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        webView.getSettings().setUserAgentString(USER_AGENT_FAKE);
    }
    

    【讨论】:

    • 嘿,谢谢伙计。但我的代码和平是 Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain)); mLock = Lock.newBuilder(auth0, mCallback) //给builder添加参数 .closable(true) .build(this); startActivity(mLock.newIntent(this));我的源代码中没有 webview 变量
    • 对不起,我不知道这个库...尝试找到一种手动设置用户代理的方法。
    【解决方案2】:

    Google 阻止网络浏览使用其 OAuth。 Reference link

    您需要通过本机代码进行 OAuth。或使用 Webview 的替代方法

    【讨论】:

      【解决方案3】:

      它对我有用:

      private WebView mWebView;
      
      public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19";
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mWebView.getSettings().setUserAgentString(USER_AGENT);
      }
      

      【讨论】:

      • 这个答案是正确的,但是当使用这个 USER_AGENT 时,Youtube 视频无法播放。
      • 您需要为 api 21 及以上版本设置不同的用户代理。在 android 部分查看 webview developer.chrome.com/multidevice/user-agent
      【解决方案4】:

      由于 Google 会阻止来自 WebView 的请求,因此我们需要在发出请求之前自行设置用户代理。

      使用其他答案中给出的硬编码假用户代理有一个缺点。 Gmail 向用户发送电子邮件,告知他们的帐户已从特定设备(不是他们的设备,可能会引起怀疑)登录。

      使用系统的默认用户代理对我有用。

      webView.getSettings().setUserAgentString(System.getProperty("http.agent"));
      

      【讨论】:

      • http.agent 是什么意思?应该是 https.agent 吗?你能详细说明一下吗
      • @ManojPerumarath "HTTP 标头 User-Agent 是一个请求标头,它允许一个特征字符串,允许网络协议对等方识别 Web 服务器的操作系统和浏览器 [src: geeksforgeeks.org/http-headers-user-agent ] ”。据我所知,HTTPS 也使用 HTTP 标头。因此,使用http.agent 应该没问题,因为它只是检索所需系统属性的关键。
      【解决方案5】:

      正如@OShiffer 所提到的,您需要添加一个假用户代理,但现在它已经过时了,您必须改用新的。使用这个

      public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-J105H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Mobile Safari/537.36";
      

      【讨论】:

      • 成功了。但是打开对话框中没有用户的帐户。用户已输入邮箱和密码。
      • 我也有这个问题。
      猜你喜欢
      • 1970-01-01
      • 2017-06-02
      • 2017-03-08
      • 1970-01-01
      • 2017-04-11
      • 2019-09-11
      • 2019-03-13
      • 2019-04-02
      • 2018-06-01
      相关资源
      最近更新 更多