flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

onReceivedHttpAuthRequest not working for Web Authentication(Works for Mobile).

Open mehulsharma15 opened this issue 1 month ago • 1 comments

Environment

Technology Version
Flutter version 3.21.1
Plugin version 6.0.0
Android version 33.0.0
iOS version 17.2
macOS version Sonoma 14.0
Xcode version 15.2
Google Chrome version 125.0.6422.76
MAC Chip

I have configured basic authentication on my server via nginx that require username and password before loading my server. I used below cade snippet to handle it in flutter, for IOS app my authentication works fine and authorise user automatically(don't have to give username and password explicitly) but for web automatic authentication doesn't work and a pop up comes up asking the username and password screenshot attached Screenshot 2024-05-24 at 4 46 24 PM

I want automatic authentication where user don't have to provide username and password and my code handles it for IOS, Android and Web. currently it is working for IOS but not for web.

This issue can be reproduced by integrating a nginx server and configure basic authentication in it.

Code snippet:- ``` // InAppWebView Widget url = 'my.server.url.com' InAppWebView( initialUrlRequest: URLRequest( url: WebUri(url), ), onWebViewCreated: (controller) { //adding js handler to cancel action only for web if (!kIsWeb) { controller.addJavaScriptHandler( handlerName: 'close', callback: (args) { Navigator.push( context, MaterialPageRoute( builder: (context) => SomeScreen(); ) }); //handler to show some successful cancellation message controller.addJavaScriptHandler( handlerName: 'cancel', callback: (isCancelled) { if (isCancelled[0]) { showSuccessPopUP("Cancelled", context, 3); } else { showErrorPopUp("Failed to Cancel", context, 3); } }); } }, onReceivedHttpAuthRequest: (controller, challenge) async { return HttpAuthResponse( username: 'username', password: 'password', action: HttpAuthResponseAction.PROCEED, ); }, )


In the above code you can see that i am using <onReceivedHttpAuthRequest> to authenticate and authorise user and 'url' is my server domain name(for IOS it works fine).

mehulsharma15 avatar May 24 '24 11:05 mehulsharma15