Search code examples
fluttergoogle-oauth

Flutter Webview Google OAuth


I have a Flutter app that's leveraging a Webview. The location of this Webview is an external site that supports Google auth, which is failing due to a 403 disalowed_useragent. I know that Google no longer supports OAuth requests using embedded browsers, but does anyone know of a workaround?

class CheckOutExternalPage extends StatefulWidget {
  final String url;

  CheckOutExternalPage({Key key, this.url}) : super(key: key);

  @override
  _CheckOutExternalPageState createState() => _CheckOutExternalPageState();
}

class _CheckOutExternalPageState extends State<CheckOutExternalPage> {
  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      geolocationEnabled: true,
      withZoom: true,
      withLocalStorage: true,
      withJavascript: true,
      supportMultipleWindows: true,
      url: widget.url,
      appBar: new AppBar(
        title: const Text('Check Out'),
      ),
    );
  }
}

Solution

  • Read Api at https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebView/userAgent.html

    so you have to use something like

    String useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36";
    

    and then webview.userAgent=useragent ;