pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.26k stars 1.6k forks source link

Google Sign In disallowed user agent in InAppWebView #1112

Closed jiayih1212 closed 9 months ago

jiayih1212 commented 2 years ago

Environment

Technology Version
Flutter version 2.5.3
Plugin version ^5.3.2
Android version
iOS version
Xcode version

Device information:

Description

The google login is being prohibited in InAppWebView plugin, it keep promoptiing Error: 403: disallowed_useragent. I have tried to add the user agent field "random", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36"

Expected behavior: Proceed with google login with no problem with InAppWebView plugin

Current behavior: Unable to proceed google login and showing Error 403: disallowed user agent

Steps to reproduce

Use google login in InAppWebView

InAppWebView( initialUrlRequest:widget.initialUrlRequest, shouldOverrideUrlLoading: widget.shouldOverrideUrlLoading, initialOptions: InAppWebViewGroupOptions( crossPlatform: InAppWebViewOptions( userAgent: 'random' ), ), onLoadStart: (InAppWebViewController controller, Uri? url) async{ if(widget.onLoadStart != null) { widget.onLoadStart!.call(controller, url); } }, ),

Images

image

Stacktrace/Logcat

github-actions[bot] commented 2 years ago

👋 @jiayih1212

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

mostafiz9900 commented 2 years ago

initialOptions: InAppWebViewGroupOptions( crossPlatform: InAppWebViewOptions( // debuggingEnabled: true, userAgent: 'random', javaScriptEnabled: true, useShouldOverrideUrlLoading: true, useOnLoadResource: true, cacheEnabled: true, )),

juskek commented 2 years ago

@mostafiz9900 it worked, thank you!! would you happen to have to know why the settings work?

pichillilorenzo commented 2 years ago

I just tested Google Sign In with the latest version 5.4.3+4 on Android Emulator API Level 31 and a real device and I can login without any problem. I didn't set a custom user agent, just using the default one.

This is the code I used:

import 'dart:async';
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (defaultTargetPlatform == TargetPlatform.android) {
    await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
  }

  runApp(const MaterialApp(
      home: MyApp()
  ));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {

  final GlobalKey webViewKey = GlobalKey();

  InAppWebViewController? webViewController;
  InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
    android: AndroidInAppWebViewOptions(
      useHybridComposition: true,
    ));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text("InAppWebView TEST")),
        body: SafeArea(
            child: Column(children: <Widget>[
              Expanded(
                child: Stack(
                  children: [
                    InAppWebView(
                      key: webViewKey,
                      initialUrlRequest: URLRequest(
                          url: Uri.parse('https://accounts.google.com/servicelogin')),
                      initialOptions: options,
                      onWebViewCreated: (controller) {
                        webViewController = controller;
                      },
                      onLoadStart: (controller, url) {
                        log("onLoadStart $url");
                      },
                      onLoadStop: (controller, url) {
                        log("onLoadStop $url");
                      },
                    ),
                  ],
                ),
              ),
            ]))
    );
  }
}
juskek commented 2 years ago

I was using InAppBrowser when I ran into the problem

vorte commented 1 year ago

I got the same error but fixed it by setting the user-agent as suggested by @mostafiz9900. 👍

Maybe InAppWebview should always set a default user-agent insted of setting it to empty string?

Environment:

flutter 3.7.2 flutter_inappwebview 5.7.2+3 Android 12

VocsyJay commented 1 year ago

I am Using flutter_inappwebview: ^5.7.2+3 flutter sdk: 3.10.5

Any of the above solutions didn't work I am got stuck

Logoutbye commented 1 year ago

i have been around this issue got many orders cancelled please provide solutions for this (facebook and google both doesnot work)

PUAJINGYI commented 1 year ago

I faced the same issue here. I had tried the solution above, but both cannot for me `InAppWebView( initialUrlRequest: URLRequest(url: Uri.parse(uri.toString())), initialOptions: InAppWebViewGroupOptions( crossPlatform: InAppWebViewOptions( // debuggingEnabled: true, userAgent: 'random', javaScriptEnabled: true, useShouldOverrideUrlLoading: true, useOnLoadResource: true, cacheEnabled: true, )), // InAppWebViewGroupOptions( // android: AndroidInAppWebViewOptions( // useHybridComposition: true, // )), onWebViewCreated: (controller) { webViewController = controller; }, onLoadStart: (controller, url) { // Handle page load start, if needed }, onLoadStop: (controller, url) { // Handle page load stop, if needed }, onProgressChanged: (controller, progress) { // Handle loading progress here, if needed }, shouldOverrideUrlLoading: (controller, navigationAction) async { final url = navigationAction.request.url;

      if (url?.toString().startsWith('http://localhost') ?? false) {
        // Close the WebView when the redirect is detected
        Navigator.pop(context);
        return NavigationActionPolicy.CANCEL;
      }

      return NavigationActionPolicy.ALLOW;
    },
  );`

flutter_inappwebview: ^5.7.2+3 flutter SDK: '>=2.19.4 <3.0.0'

any other suggestion?

Mr-Programmar commented 11 months ago

I just Fixed this issue, very easy to fix it honestly! please give me a like if your issue is resolved. I am using "flutter_inappwebview: ^5.7.2+3" this package. just add this inside your userAgent and applicationNameForUserAgent properties.

(1)userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", (2)applicationNameForUserAgent: "your app name", Screenshot_1 Screenshot_2

Logoutbye commented 11 months ago

hello there brother hope you are doing well i want to ask i have tried but it could not sorted it out can you please give me any example project in working condition that would be great help thanks in advance

On Mon, Nov 20, 2023 at 1:53 AM ASAD WASEEM @.***> wrote:

I just Fixed this issue, very easy to fix it honestly! please give me a like if your issue is resolved. I am using "flutter_inappwebview: ^5.7.2+3" this package. just add this inside your userAgent and applicationNameForUserAgent properties.

(1)userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", (2)applicationNameForUserAgent: "your app name", [image: Screenshot_1] https://user-images.githubusercontent.com/105446618/284089583-ec659b9e-b022-41f3-8b60-78abf5d30e4f.png [image: Screenshot_2] https://user-images.githubusercontent.com/105446618/284089586-8b75968f-249d-427e-8cec-57ad469c978e.png

— Reply to this email directly, view it on GitHub https://github.com/pichillilorenzo/flutter_inappwebview/issues/1112#issuecomment-1817974176, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVZQKBLIRPDK26H6DF465ZDYFJWSZAVCNFSM5QIFERZKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRG44TONBRG43A . You are receiving this because you commented.Message ID: @.***>

MostafaRamadan1 commented 10 months ago

Any updates, nothing works for the solution above for version ^6.0.0-beta.31

BenasPaulikas commented 9 months ago

Any updates, nothing works for the solution above for version ^6.0.0-beta.31

Any luck? Mine is flutter_inappwebview: ~^6.0.0-beta.21~^6.0.0 By faking userAgent I can work-around this. But that's not a solution.

pichillilorenzo commented 9 months ago

The problem is exactly about the default user agent of the WebView, so it is the right solution. It depends on the server and how they treat WebView default user-agent. There is no “official” API to allow Google sign-in or whatever, that’s simply how it works and doesn’t depend on the WebView itself.

BenasPaulikas commented 9 months ago

@pichillilorenzo thank you for insight.I will try to implement more native way for social auth. instead of relying on social auth inside webview.

github-actions[bot] commented 2 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.