Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 403: Error: Disallowed Useragent #87

Open
tbohnen opened this issue Mar 13, 2017 · 18 comments · May be fixed by #228
Open

Android 403: Error: Disallowed Useragent #87

tbohnen opened this issue Mar 13, 2017 · 18 comments · May be fixed by #228

Comments

@tbohnen
Copy link

tbohnen commented Mar 13, 2017

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

@maggialejandro
Copy link

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

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

@auser
Copy link
Contributor

auser commented Mar 19, 2017

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

@SobolRR
Copy link

SobolRR commented Apr 4, 2017

Any updates?

@timbielawski
Copy link
Contributor

timbielawski commented Apr 5, 2017

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

@vanydeasy
Copy link

I'm still having the same issue.

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

@Jazz747
Copy link

Jazz747 commented Jun 30, 2017

Same, even after updating changes that @timbielawski made.

react-native 45.1
react-native-oauth 2.1.16

@DmitryMaksakov
Copy link

The same:

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

@roshangm1
Copy link

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

cd android
./gradlew clean

@HarshankArastu
Copy link

Any update on this issue?

@roshangm1
Copy link

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

@egiesem
Copy link

egiesem commented Jun 18, 2018

@marcioferlan
Copy link

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

@krisidmisso
Copy link

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

@daxaxelrod
Copy link

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

@krisidmisso
Copy link

@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

@ericchan3721
Copy link

ericchan3721 commented Jul 22, 2020

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

@vaibhavgadekar
Copy link

Simple add userAgent={"chrome"}

It's works for me 🤘

@saran2020
Copy link

saran2020 commented Mar 17, 2021

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
Labels
None yet
Projects
None yet