在 Azure B2C + 离子电容器 InAppBrowser 谷歌登录上获取 403 disallowed_useragent

2023-12-23

当我尝试单击 Azure B2C 登录页面上的 google 登录时,它会将我重定向到另一个页面,并显示错误 403 disallowed_useragent。

这是我到目前为止所尝试的:

添加 尝试添加overrideUserAgent如在文档 https://capacitorjs.com/docs/basics/configuring-your-app提到。 将这一行添加到 Capacitor.config.json 的根部

 "overrideUserAgent": "Mozilla/5.0 Google"

我还尝试添加 UserAgentplugin https://ionicframework.com/docs/native/user-agent我在应用程序组件中添加这一行来设置用户代理

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

最后我还在 config.xml 中添加了这一行

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

当我调试 inAppBrowser 控制台日志时,这些解决方案中的任何一个都有效,我在请求标头中看到此结果

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

任何帮助将不胜感激。


我通过添加来解决它overrideUserAgent像这样的电容器.config.json

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

该对象已添加到文件的根目录中。

问题是,当我们运行时,Cordova 首选项会添加到电容器首选项中cap init命令,之后要添加 Cordova 首选项,我们应该像上面那样使用电容器.config.json 中的 Cordova 对象。https://capacitorjs.com/docs/cordova/migration-from-cordova-to-capacitor#cordova-plugin-preferences https://capacitorjs.com/docs/cordova/migrating-from-cordova-to-capacitor#cordova-plugin-preferences

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Azure B2C + 离子电容器 InAppBrowser 谷歌登录上获取 403 disallowed_useragent 的相关文章

随机推荐