在Auth0 Lock for Android中获得403不允许的用户代理

Nar*_*vva 2 android google-oauth google-oauth2 auth0 auth0-delegated-admin

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

它之前的工作很好,但现在我面对403不允许的用户,而点击谷歌.

当我在谷歌搜索时,我发现这一点:谷歌自4月20日起决定阻止从嵌入式网页浏览访问以达到安全目的,这就是为什么用谷歌登录Auth0失败的原因.

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
       }
   };
Run Code Online (Sandbox Code Playgroud)

表现:

<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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

Nab*_*ari 7

由于谷歌阻止来自 a 的请求WebView,我们需要在发出请求之前自己设置一个用户代理。

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

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

webView.getSettings().setUserAgentString(System.getProperty("http.agent"));
Run Code Online (Sandbox Code Playgroud)

  • @ManojPerumarath“HTTP 标头 User-Agent 是一个请求标头,它允许使用特征字符串,该字符串允许网络协议对等方识别 Web 服务器的操作系统和浏览器 [src:https://www.geeksforgeeks.org/http-标头-用户-代理/]”。据我所知,HTTPS 也使用 HTTP 标头。因此,使用“http.agent”应该没问题,因为它只是检索所需系统属性的关键。 (2认同)

OSh*_*fer 6

正如你所说,谷歌决定阻止嵌入式访问WebView.同样的事情发生在我身上,我只是自己把用户代理.它看起来像这样:

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);
}
Run Code Online (Sandbox Code Playgroud)


小智 5

它为我工作:

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);
}
Run Code Online (Sandbox Code Playgroud)