Getting 403 disallowed_useragent on Azure B2C + Ionic Capacitor InAppBrowser google login

Viewed 1386

When I try to click the google login on Azure B2C login page it redirect me to to another page with the error 403 disallowed_useragent.

This is what I tried so far:

Add Try to add the overrideUserAgent as in the documentation mention. Adding this line at the root of the capacitor.config.json

 "overrideUserAgent": "Mozilla/5.0 Google"

I also try to add the UserAgent plugin I add this line in my app component to set the user agent

this.userAgent.set('Mozilla/5.0 Google')
        .then((res: any) => console.log('UserAgent test' + res))
        .catch((error: any) => console.error(error));

And at the end I also add in the config.xml this line

<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />

Any of those solutions work when I debug the inAppBrowser console log I see this result in the request header

user-agent: Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86 Build/RPB1.200504.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.44 Mobile Safari/537.36

Any help will be appreciated.

1 Answers

I solve it by adding the overrideUserAgent to the capacitor.config.json like this

  "cordova": {
    "preferences": {
      "OverrideUserAgent": "Mozilla/5.0 Google"
    }
  },

This object was added to the root of the file.

The problem is that Cordova preferences are added to capacitor preferences when we run cap init command, After that to add Cordova preferences we should use Cordova object inside capacitor.config.json as I did above. https://capacitorjs.com/docs/cordova/migrating-from-cordova-to-capacitor#cordova-plugin-preferences

Related