Karen
Karen

Reputation: 131

How to avoid 403 disallowed_useragent error in a web app from 3rd party native app

I would like to let my users login with Google on my react web app (secured with Auth0), even if they come from a native app. I did add a social connection for oauth in auth0 dashboard and it's working fine on desktop. But the security policy of Google from 2017 forbids to use Oauth request inside a webview, so users coming from a native app and trying to signin with Google, get the following error 403: disallowed_userAgent

Steps to reproduce :

  1. Send a msg in LinkedIn containing this link stackoverflow.com (or any other link that redirects to a website with a Google sign-in)
  2. From the native LinkedIn app, click on the link and login via Google sso (login or sign up, no matter)
  3. Click the connect button of Google sign-in and see the error arise

And this is reproductible on Facebook, Messenger, Twitter native apps.

Any secured website that want to use Google sign-in must encounter this issue when users navigate from a social native app.

The solutions I've found so far are:

Any other idea? Maybe another service than Auth0 handle this issue better?

I tried to:

Upvotes: 11

Views: 16759

Answers (1)

Karen
Karen

Reputation: 131

It is not possible to let users login with Google SSO when they're browsing through native app. If you do so, you'll have the 403 disallowed_userAgent error.

But I found way to disable Google SSO when user is browsing through native app so that the error cannot arise, using Auth0. To do so, create 2 applications in your tenant in auth0 and redirect to the right one within your own web app. Authorize Google SSO only on one of the two applications.

The code below redirect a user browsing through Iphone to the application where SSO is disabled so that user won’t have the error pop (since this error occur only on iphones in my case). Look at user agent to make it match to your case.

if (navigator.userAgent.match(/iPhone/i)) {
    return process.env.REACT_APP_AUTH0_MOBILE_CLIENT_ID; // Google SSO is disabled
  } else {
    return process.env.REACT_APP_AUTH0_CLIENT_ID; // Google SSO is enabled
}

Upvotes: 2

Related Questions