Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing users to get 403 disallowed_useragent Google error in react-native app

I've developed a react-native app which uses Auth0 to authenticate users.

I am getting a 403 disallowed_useragent error when some users try to authenticate using Google from my react-native app, using webAuth. As I searched, this is related to the browser app installed in the user device.

I can reproduce this issue using an Android 11 emulator disabling the Chrome browser, so the OS uses the WebView Browser Tester. If I let Chrome browser enabled, everything works OK.

So my question is: Is there a way to check if the browser installed in the user device supports Google Auth? So I can tell the user to update/install his browser if necessary.

I am using the official SDK react-native-auth0 v2.9.0 and react-native v0.66.0

like image 920
José Persichini Avatar asked Oct 29 '25 07:10

José Persichini


1 Answers

A work around consist of modifying the useragent definition used to request the authentication to goolgle api,

When using the mobile webview, the useragent may contain at the end of the browser version component string definition the string "wv" abbreviation of WebView, google is not allowing anymore for a security reason webview browser to perform an authentication on their platform.

the solution is to remove the string ; wv from the useragent version definition string component, by a simple string replace operation : useragent.replace("; wv)", ")")

    <WebView
        source={{uri}}
        style={{flex: 1}}
        userAgent={
           'Mozilla/5.0 (Linux; Android 12; Pixel a5 Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.130 Mobile Safari/537.36'
        }
    />

so, then instead of :

Mozilla/5.0 (Linux; Android 12; Pixel a5 Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.130 Mobile Safari/537.36

use :

Mozilla/5.0 (Linux; Android 12; Pixel a5 Build/SP1A.210812.016) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.130 Mobile Safari/537.36

best wishes.

like image 99
do7 Avatar answered Oct 31 '25 21:10

do7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!