Skip to content

Android 403: Error: Disallowed Useragent #87

Open

Description

@tbohnen

When trying to run this on android, it seems that google has now disallowed web views, is there any other way to get this library to work on android?

screenshot from 2017-03-13 08-05-43

Activity

  1. maggialejandro commented on Mar 19, 2017

    @maggialejandro

    I started a project from scratch and I'm having the same issue.

    "react-native": "0.42.3",
    "react-native-oauth": "^2.1.16"

  2. auser commented on Mar 19, 2017

    @auser
    Contributor

    I'll check later today... see if I can't figure out what's happening

  3. SobolRR commented on Apr 4, 2017

    @SobolRR

    Any updates?

  4. timbielawski commented on Apr 5, 2017

    @timbielawski
    Contributor

    You can use this fork until the PR gets merged in
    https://github.com/timbielawski/react-native-oauth

  5. vanydeasy commented on Apr 30, 2017

    @vanydeasy

    I'm still having the same issue.

    react-native: 0.42.0
    react-native-oauth: 2.1.16

  6. Jazz747 commented on Jun 30, 2017

    @Jazz747

    Same, even after updating changes that @timbielawski made.

    react-native 45.1
    react-native-oauth 2.1.16

  7. DmitryMaksakov commented on Jul 4, 2017

    @DmitryMaksakov

    The same:

    react-native: 0.45.1,
    react-native-oauth: 2.1.16

  8. roshangm1 commented on Jul 7, 2017

    @roshangm1

    The changes of @timbielawski works perfectly. Don't forget to clean the project after making those changes.

    cd android
    ./gradlew clean
    
  9. HarshankArastu commented on Feb 22, 2018

    @HarshankArastu

    Any update on this issue?

  10. roshangm1 commented on Feb 22, 2018

    @roshangm1
  11. egiesem commented on Jun 18, 2018

    @egiesem
  12. marcioferlan commented on Sep 27, 2018

    @marcioferlan

    @HarshankArastu Try this fork which might fix this bug.
    https://github.com/roshangm1/react-native-oauth

    It solved the issue for me. When will this be merged?

  13. krisidmisso commented on Apr 15, 2019

    @krisidmisso

    @roshangm1 added the solution but its not merged yet. For the moment just modify the file in node_modules: node_modules/react-native-oauth/android/src/main/java/io/fullstack/oauth/OAuthManagerDialogFragment.java:

    ...
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    // add this line (112)
    mWebView.getSettings().setUserAgentString("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");
    ...
    
  14. daxaxelrod commented on May 17, 2019

    @daxaxelrod

    @krisidmisso your solution worked for me. Looks like it'll be merged into the repo soon

  15. krisidmisso commented on Sep 24, 2019

    @krisidmisso

    @roshangm1 added the solution but its not merged yet. For the moment just modify the file in node_modules: node_modules/react-native-oauth/android/src/main/java/io/fullstack/oauth/OAuthManagerDialogFragment.java:

    ...
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    // add this line (112)
    mWebView.getSettings().setUserAgentString("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");
    ...
    

    The above fix actually generates another issue. If you get a notification from google it will say that you have logged in from a Nexus device due to the user agent string Galaxy Nexus...

    Hopefully there will be another fix

  16. ericchan3721 commented on Jul 22, 2020

    @ericchan3721

    @roshangm1 added the solution but its not merged yet. For the moment just modify the file in node_modules: node_modules/react-native-oauth/android/src/main/java/io/fullstack/oauth/OAuthManagerDialogFragment.java:

    ...
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    // add this line (112)
    mWebView.getSettings().setUserAgentString("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");
    ...
    

    The above fix actually generates another issue. If you get a notification from google it will say that you have logged in from a Nexus device due to the user agent string Galaxy Nexus...

    Hopefully there will be another fix

    A quick and dirty fix for you is just simply remove the Galaxy Nexus... from the User-Agent string you set

    or you can use mWebView.getSettings().setUserAgentString(mWebView.getSettings().getUserAgentString()) to get the real UserAgent and set it back to the webview

    update on 12 Apr 2021:

    you can remove wv from the UserAgent
    mWebView.getSettings().setUserAgentString(mWebView.getSettings().getUserAgentString().replace("; wv", ""));

    Ref: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

    P.S. I have open the PR for this issue, however this library seems no longer supported by the original author, you may consider using other OAuth RN library.

  17. vaibhavgadekar commented on Dec 10, 2020

    @vaibhavgadekar

    Simple add userAgent={"chrome"}

    It's works for me 🤘

  18. saran2020 commented on Mar 17, 2021

    @saran2020

    I encountered this issue in Android (and not react). I first started with the solution

    web_view.settings.userAgentString = "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"
    

    it worked. However, if the user is not logged in, Google asks the user to login and when they ask the user to verify the login, sometimes on an already logged in device and they report incorrect device details.

    Eg: On using the above example I was said I tried logging in on an Android 4 device, even when I was on an Android 9 device. This could be confusing to users.

    So I tried seeing what's the default value in web_view.settings.userAgentString and found the value to be

    Mozilla/5.0 (Linux; Android 9; vivo 1904 Build/PPR1.180610.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.90 Mobile Safari/537.36
    

    I realised the problem is wv in the above string, so I just removed that and it worked fine.

    My end code looked something like this

    web_view.settings.userAgentString = settings.userAgentString.removeAll("; wv")
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions