Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
517e9d4
Implement http basic auth
JeroenWeener Aug 10, 2023
967879b
Apply feedback
JeroenWeener Aug 28, 2023
c8624c0
Create HttpAuthHandlerTest.java
JeroenWeener Aug 29, 2023
4f3574d
Format java files
JeroenWeener Aug 29, 2023
1e7f785
Regenerate build_runner files
JeroenWeener Aug 29, 2023
131bc56
Implement feedback
JeroenWeener Sep 11, 2023
bc01be4
Remove redundant key in `Info.plist`
JeroenWeener Sep 11, 2023
67aa00e
Update example apps
JeroenWeener Sep 11, 2023
32496d0
Implement http basic auth
JeroenWeener Aug 10, 2023
aeb8708
Apply feedback
JeroenWeener Aug 28, 2023
fffc4c7
Create HttpAuthHandlerTest.java
JeroenWeener Aug 29, 2023
b455040
Format java files
JeroenWeener Aug 29, 2023
2aa9bfe
Regenerate build_runner files
JeroenWeener Aug 29, 2023
db286ba
Implement feedback
JeroenWeener Sep 11, 2023
467feb3
Remove redundant key in `Info.plist`
JeroenWeener Sep 11, 2023
dad8ae6
Update example apps
JeroenWeener Sep 11, 2023
6f3d802
Merge branch 'webview-auth-request' of https://github.com/andreisas06…
JeroenWeener Nov 1, 2023
0fef591
Add platform interface dev dependency to example
JeroenWeener Nov 1, 2023
b2a4fbb
Merge branch 'main' into webview-auth-request
JeroenWeener Nov 1, 2023
ce35d9b
Update packages/webview_flutter/webview_flutter_platform_interface/li…
bparrishMines Nov 8, 2023
fc32898
Merge branch 'main' of github.com:flutter/packages into webview-auth-…
bparrishMines Nov 8, 2023
4673e65
Merge branch 'webview-auth-request' of github.com:andreisas06/package…
bparrishMines Nov 8, 2023
580521a
Fix some lints, errros and call on errors
bparrishMines Nov 8, 2023
d1f305b
fix lints
bparrishMines Nov 8, 2023
a3f74be
fix tests
bparrishMines Nov 8, 2023
ed3798f
add onProceed and onCancel back
bparrishMines Nov 8, 2023
154c1f8
dont require realm to be nonnull
bparrishMines Nov 8, 2023
a0b5c4d
Merge remote-tracking branch 'upstream/main' into webview-auth-reques…
JeroenWeener Nov 14, 2023
9ac132e
Separate platform interface changes
JeroenWeener Nov 14, 2023
9df4152
Delete HttpAuthHandlerFlutterApiImpl.java
JeroenWeener Nov 14, 2023
a387bb6
Delete HttpAuthHandlerHostApiImpl.java
JeroenWeener Nov 14, 2023
1e01f79
Delete HttpAuthHandlerTest.java
JeroenWeener Nov 14, 2023
389e9ae
Delete FWFURLAuthenticationChallengeHostApiTests.m
JeroenWeener Nov 14, 2023
3e1a41b
Delete FWFURLCredentialHostApiTests.m
JeroenWeener Nov 14, 2023
bfb86aa
Delete FWFURLProtectionSpaceHostApiTests.m
JeroenWeener Nov 14, 2023
7bd194a
Delete FWFURLAuthenticationChallengeHostApi.h
JeroenWeener Nov 14, 2023
34bfa51
Delete FWFURLAuthenticationChallengeHostApi.m
JeroenWeener Nov 14, 2023
290e816
Delete FWFURLCredentialHostApi.h
JeroenWeener Nov 14, 2023
01b22d3
Delete FWFURLCredentialHostApi.m
JeroenWeener Nov 14, 2023
e1c0908
Delete FWFURLProtectionSpaceHostApi.h
JeroenWeener Nov 14, 2023
5cac2e3
Delete FWFURLProtectionSpaceHostApi.m
JeroenWeener Nov 14, 2023
5f741ff
Update packages/webview_flutter/webview_flutter_platform_interface/li…
JeroenWeener Nov 17, 2023
e8737fc
Update packages/webview_flutter/webview_flutter_platform_interface/li…
JeroenWeener Nov 17, 2023
3b0c25f
Fix typos
JeroenWeener Nov 17, 2023
06993a9
Update packages/webview_flutter/webview_flutter_platform_interface/li…
JeroenWeener Nov 17, 2023
b4f3ba2
Merge branch 'webview-auth-request-platform-interface' of https://git…
JeroenWeener Nov 17, 2023
38a0319
Revert bump to `plugin_platform_interface` version
JeroenWeener Nov 20, 2023
cc4b4e0
Merge remote-tracking branch 'upstream/main' into webview-auth-reques…
JeroenWeener Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply feedback
  • Loading branch information
JeroenWeener committed Oct 26, 2023
commit 967879b412e337db90f0a6d63ec943366f431b5d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

Future<void> main() async {
Expand Down Expand Up @@ -777,7 +778,7 @@ Future<void> main() async {
unawaited(
controller.setNavigationDelegate(
NavigationDelegate(
onHttpBasicAuthRequest: (HttpBasicAuthRequest request) =>
onHttpAuthRequest: (HttpAuthRequest request) =>
authRequested.complete(),
),
),
Expand All @@ -798,8 +799,9 @@ Future<void> main() async {
unawaited(
controller.setNavigationDelegate(
NavigationDelegate(
onHttpBasicAuthRequest: (HttpBasicAuthRequest request) =>
request.onProceed('user', 'pass'),
onHttpAuthRequest: (HttpAuthRequest request) => request.onProceed(
const WebViewCredential(user: 'user', password: 'password'),
),
onPageFinished: (_) => pageFinished.complete(),
),
),
Expand Down
15 changes: 9 additions & 6 deletions packages/webview_flutter/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:webview_flutter/webview_flutter.dart';
// #docregion platform_imports
// Import for Android features.
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
// Import for iOS features.
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
// #enddocregion platform_imports
Expand Down Expand Up @@ -172,9 +173,9 @@ Page resource error:
onUrlChange: (UrlChange change) {
debugPrint('url change to ${change.url}');
},
onHttpBasicAuthRequest: (HttpBasicAuthRequest request) {
onHttpAuthRequest: (HttpAuthRequest request) {
debugPrint(
'HTTP basic auth request with host ${request.host} and realm ${request.realm}');
'HTTP basic auth request with host ${request.host} and realm ${request.realm ?? '-'}');
openDialog(request);
},
),
Expand Down Expand Up @@ -231,7 +232,7 @@ Page resource error:
);
}

Future<void> openDialog(HttpBasicAuthRequest httpRequest) async {
Future<void> openDialog(HttpAuthRequest httpRequest) async {
final TextEditingController usernameTextController =
TextEditingController();
final TextEditingController passwordTextController =
Expand All @@ -242,7 +243,7 @@ Page resource error:
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${httpRequest.host}: ${httpRequest.realm}'),
title: Text('${httpRequest.host}: ${httpRequest.realm ?? '-'}'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -272,8 +273,10 @@ Page resource error:
TextButton(
onPressed: () {
httpRequest.onProceed(
usernameTextController.text,
passwordTextController.text,
WebViewCredential(
user: usernameTextController.text,
password: passwordTextController.text,
),
);
Navigator.of(context).pop();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
webview_flutter_platform_interface: ^2.3.0

flutter:
uses-material-design: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class FakeNavigationDelegate extends PlatformNavigationDelegate {
Future<void> setOnUrlChange(UrlChangeCallback onUrlChange) async {}

@override
Future<void> setOnHttpBasicAuthRequest(
Future<void> setOnHttpAuthRequest(
HttpAuthRequestCallback handler,
) async {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NavigationDelegate {
void Function(int progress)? onProgress,
void Function(WebResourceError error)? onWebResourceError,
void Function(UrlChange change)? onUrlChange,
void Function(HttpBasicAuthRequest request)? onHttpBasicAuthRequest,
void Function(HttpAuthRequest request)? onHttpAuthRequest,
}) : this.fromPlatformCreationParams(
const PlatformNavigationDelegateCreationParams(),
onNavigationRequest: onNavigationRequest,
Expand All @@ -57,7 +57,7 @@ class NavigationDelegate {
onProgress: onProgress,
onWebResourceError: onWebResourceError,
onUrlChange: onUrlChange,
onHttpBasicAuthRequest: onHttpBasicAuthRequest,
onHttpAuthRequest: onHttpAuthRequest,
);

/// Constructs a [NavigationDelegate] from creation params for a specific
Expand Down Expand Up @@ -100,7 +100,7 @@ class NavigationDelegate {
void Function(int progress)? onProgress,
void Function(WebResourceError error)? onWebResourceError,
void Function(UrlChange change)? onUrlChange,
void Function(HttpBasicAuthRequest request)? onHttpBasicAuthRequest,
void Function(HttpAuthRequest request)? onHttpAuthRequest,
}) : this.fromPlatform(
PlatformNavigationDelegate(params),
onNavigationRequest: onNavigationRequest,
Expand All @@ -109,7 +109,7 @@ class NavigationDelegate {
onProgress: onProgress,
onWebResourceError: onWebResourceError,
onUrlChange: onUrlChange,
onHttpBasicAuthRequest: onHttpBasicAuthRequest,
onHttpAuthRequest: onHttpAuthRequest,
);

/// Constructs a [NavigationDelegate] from a specific platform implementation.
Expand All @@ -123,7 +123,7 @@ class NavigationDelegate {
this.onProgress,
this.onWebResourceError,
void Function(UrlChange change)? onUrlChange,
this.onHttpBasicAuthRequest,
this.onHttpAuthRequest,
}) {
if (onNavigationRequest != null) {
platform.setOnNavigationRequest(onNavigationRequest!);
Expand All @@ -143,8 +143,8 @@ class NavigationDelegate {
if (onUrlChange != null) {
platform.setOnUrlChange(onUrlChange);
}
if (onHttpBasicAuthRequest != null) {
platform.setOnHttpBasicAuthRequest(onHttpBasicAuthRequest!);
if (onHttpAuthRequest != null) {
platform.setOnHttpAuthRequest(onHttpAuthRequest!);
}
}

Expand Down Expand Up @@ -175,6 +175,6 @@ class NavigationDelegate {
/// Invoked when a resource loading error occurred.
final WebResourceErrorCallback? onWebResourceError;

/// Invoked when a resource required HTTP basic authentication.
final HttpAuthRequestCallback? onHttpBasicAuthRequest;
/// Invoked when a resource required HTTP authentication.
final HttpAuthRequestCallback? onHttpAuthRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library webview_flutter;

export 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'
show
HttpBasicAuthRequest,
HttpAuthRequest,
JavaScriptConsoleMessage,
JavaScriptLogLevel,
JavaScriptMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ void main() {
verify(delegate.platform.setOnUrlChange(onUrlChange));
});

test('onHttpBasicAuthRequest', () {
test('onHttpAuthRequest', () {
WebViewPlatform.instance = TestWebViewPlatform();

void onHttpBasicAuthRequest(HttpBasicAuthRequest request) {}
void onHttpAuthRequest(HttpAuthRequest request) {}

final NavigationDelegate delegate = NavigationDelegate(
onHttpBasicAuthRequest: onHttpBasicAuthRequest,
onHttpAuthRequest: onHttpAuthRequest,
);

verify(
delegate.platform.setOnHttpBasicAuthRequest(onHttpBasicAuthRequest));
verify(delegate.platform.setOnHttpAuthRequest(onHttpAuthRequest));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 3.13.0

* Adds support for `PlatformNavigationDelegate.setOnReceiveHttpBasicAuthRequest`.
* Adds support for `PlatformNavigationDelegate.setOnReceiveHttpAuthRequest`.

## 3.12.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void doUpdateVisitedHistory(
flutterApi.doUpdateVisitedHistory(this, view, url, isReload, reply -> {});
}

// Handles an HTTP Basic Authentication request.
// Handles an HTTP authentication request.
//
// This callback is invoked when the WebView encounters a website requiring HTTP authentication.
// [host] and [realm] are provided for matching against stored credentials, if any.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,8 @@ Future<void> main() async {
PlatformNavigationDelegate(
const PlatformNavigationDelegateCreationParams(),
);
await navigationDelegate.setOnHttpBasicAuthRequest(
(HttpBasicAuthRequest request) => authRequested.complete());
await navigationDelegate.setOnHttpAuthRequest(
(HttpAuthRequest request) => authRequested.complete());
await controller.setPlatformNavigationDelegate(navigationDelegate);

// Clear cache so that the auth request is always received and we don't get
Expand Down Expand Up @@ -1177,12 +1177,14 @@ Future<void> main() async {
const PlatformNavigationDelegateCreationParams(),
);
await navigationDelegate.setOnPageFinished((_) => pageFinished.complete());
await navigationDelegate.setOnHttpBasicAuthRequest(
(HttpBasicAuthRequest request) => request.onProceed('user', 'pass'),
await navigationDelegate.setOnHttpAuthRequest(
(HttpAuthRequest request) => request.onProceed(
const WebViewCredential(user: 'user', password: 'password'),
),
);
await controller.setPlatformNavigationDelegate(navigationDelegate);

// Clear cache so that the auth request is always received and we don't get
// Clear cache so that the auth request is always received and we do not get
// a cached response.
await controller.clearCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ Page resource error:
..setOnUrlChange((UrlChange change) {
debugPrint('url change to ${change.url}');
})
..setOnHttpBasicAuthRequest((HttpBasicAuthRequest request) {
..setOnHttpAuthRequest((HttpAuthRequest request) {
debugPrint(
'HTTP basic auth request with host ${request.host} and realm ${request.realm}');
'HTTP basic auth request with host ${request.host} and realm ${request.realm ?? '-'}');
openDialog(request);
}),
)
Expand Down Expand Up @@ -227,7 +227,7 @@ Page resource error:
);
}

Future<void> openDialog(HttpBasicAuthRequest httpRequest) async {
Future<void> openDialog(HttpAuthRequest httpRequest) async {
final TextEditingController usernameTextController =
TextEditingController();
final TextEditingController passwordTextController =
Expand All @@ -237,7 +237,7 @@ Page resource error:
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${httpRequest.host}: ${httpRequest.realm}'),
title: Text('${httpRequest.host}: ${httpRequest.realm ?? '-'}'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expand All @@ -256,8 +256,10 @@ Page resource error:
TextButton(
onPressed: () {
httpRequest.onProceed(
usernameTextController.text,
passwordTextController.text,
WebViewCredential(
user: usernameTextController.text,
password: passwordTextController.text,
),
);
Navigator.of(context).pop();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart' show BinaryMessenger;

import 'package:flutter/widgets.dart' show WidgetsFlutterBinding;
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

import 'android_webview.g.dart';
import 'android_webview_api_impls.dart';
Expand Down Expand Up @@ -939,7 +940,7 @@ class WebViewClient extends JavaObject {
final void Function(WebView webView, String url, bool isReload)?
doUpdateVisitedHistory;

/// This callback is only called for requests that require HTTP basic authentication.
/// This callback is only called for requests that require HTTP authentication.
final void Function(
WebView webView,
HttpAuthHandler handler,
Expand Down Expand Up @@ -1508,7 +1509,7 @@ class CustomViewCallback extends JavaObject {
}
}

/// Represents a request for HTTP basic authentication.
/// Represents a request for HTTP authentication.
///
/// Instances of this class are created by the [WebView] and passed to
/// [WebViewClient.onReceivedHttpAuthRequest]. The host application must call
Expand All @@ -1532,7 +1533,16 @@ class HttpAuthHandler extends JavaObject {

/// Instructs the WebView to proceed with the authentication with the provided
/// credentials.
Future<void> proceed(String username, String password) {
return api.proceedFromInstance(this, username, password);
Future<void> proceed(WebViewCredential credential) {
return api.proceedFromInstance(this, credential);
}

/// Gets whether the credentials stored for the current host are suitable for
/// use.
///
/// Credentials are not suitable if they have previously been rejected by the
/// server for the current request.
Future<bool> useHttpAuthUsernamePassword() {
return api.useHttpAuthUsernamePasswordFromInstance(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:ui';

import 'package:flutter/services.dart' show BinaryMessenger, Uint8List;
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'
show WebViewCredential;

import 'android_webview.dart';
import 'android_webview.g.dart';
Expand Down Expand Up @@ -1449,13 +1451,21 @@ class HttpAuthHandlerHostApiImpl extends HttpAuthHandlerHostApi {
/// Helper method to convert instance ids to objects.
Future<void> proceedFromInstance(
HttpAuthHandler instance,
String username,
String password,
WebViewCredential credential,
) {
return proceed(
_instanceManager.getIdentifier(instance)!,
username,
password,
credential.user,
credential.password,
);
}

/// Helper method to convert instance ids to objects.
Future<bool> useHttpAuthUsernamePasswordFromInstance(
HttpAuthHandler instance,
) {
return useHttpAuthUsernamePassword(
_instanceManager.getIdentifier(instance)!,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,11 +1274,11 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate {
String host,
String realm,
) {
final void Function(HttpBasicAuthRequest)? callback =
final void Function(HttpAuthRequest)? callback =
weakThis.target?._onHttpAuthRequest;
if (callback != null) {
callback(
HttpBasicAuthRequest(
HttpAuthRequest(
onProceed: httpAuthHandler.proceed,
onCancel: httpAuthHandler.cancel,
host: host,
Expand Down Expand Up @@ -1432,7 +1432,7 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate {
}

@override
Future<void> setOnHttpBasicAuthRequest(
Future<void> setOnHttpAuthRequest(
HttpAuthRequestCallback onHttpAuthRequest,
) async {
_onHttpAuthRequest = onHttpAuthRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ void main() {

String? callbackHost;
String? callbackRealm;
androidNavigationDelegate
.setOnHttpBasicAuthRequest((HttpBasicAuthRequest request) {
androidNavigationDelegate.setOnHttpAuthRequest((HttpAuthRequest request) {
callbackHost = request.host;
callbackRealm = request.realm;
});
Expand Down
Loading