react-native-oauth icon indicating copy to clipboard operation
react-native-oauth copied to clipboard

Android 403: Error: Disallowed Useragent

Open tbohnen opened this issue 7 years ago • 18 comments

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

tbohnen avatar Mar 13 '17 06:03 tbohnen

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

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

maggialejandro avatar Mar 19 '17 19:03 maggialejandro

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

auser avatar Mar 19 '17 20:03 auser

Any updates?

SobolRR avatar Apr 04 '17 12:04 SobolRR

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

timbielawski avatar Apr 05 '17 15:04 timbielawski

I'm still having the same issue.

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

vanydeasy avatar Apr 30 '17 09:04 vanydeasy

Same, even after updating changes that @timbielawski made.

react-native 45.1 react-native-oauth 2.1.16

Jazz747 avatar Jun 30 '17 06:06 Jazz747

The same:

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

DmitryMaksakov avatar Jul 04 '17 07:07 DmitryMaksakov

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

cd android
./gradlew clean

roshangm1 avatar Jul 07 '17 10:07 roshangm1

Any update on this issue?

HarshankArastu avatar Feb 22 '18 06:02 HarshankArastu

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

roshangm1 avatar Feb 22 '18 09:02 roshangm1

solved https://www.youtube.com/watch?v=vFSgIdtEl2k

egiesem avatar Jun 18 '18 14:06 egiesem

@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?

marcioferlan avatar Sep 27 '18 01:09 marcioferlan

@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");
...

krisidmisso avatar Apr 15 '19 18:04 krisidmisso

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

daxaxelrod avatar May 17 '19 02:05 daxaxelrod

@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

krisidmisso avatar Sep 24 '19 15:09 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

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.

ericchan3721 avatar Jul 22 '20 03:07 ericchan3721

Simple add userAgent={"chrome"}

It's works for me 🤘

vaibhavgadekar avatar Dec 10 '20 15:12 vaibhavgadekar

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")

saran2020 avatar Mar 17 '21 15:03 saran2020