Skip to content

[webview_flutter] Support for handling basic authentication requests (Platform Interface) #5362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.7.0

* Adds support for handling HTTP basic authentication requests. See `PlatformNavigationDelegate.setOnHttpAuthRequest`.
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.

## 2.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ typedef WebResourceErrorCallback = void Function(WebResourceError error);
/// url of the web view.
typedef UrlChangeCallback = void Function(UrlChange change);

/// Signature for callbacks that notify the host application of an
/// authentication request.
typedef HttpAuthRequestCallback = void Function(HttpAuthRequest request);

/// An interface defining navigation events that occur on the native platform.
///
/// The [PlatformWebViewController] is notifying this delegate on events that
Expand Down Expand Up @@ -132,4 +136,11 @@ abstract class PlatformNavigationDelegate extends PlatformInterface {
'setOnUrlChange is not implemented on the current platform.',
);
}

/// Invoked when the web view is requesting authentication.
Future<void> setOnHttpAuthRequest(HttpAuthRequestCallback onHttpAuthRequest) {
throw UnimplementedError(
'setOnHttpAuthRequest is not implemented on the current platform.',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'webview_platform.dart' show WebViewPlatform;
/// changes. Extending this class (using `extends`) ensures that the subclass
/// will get the default implementation, while platform implementations that
/// `implements` this interface will be broken by newly added
/// [PlatformWebViewCookieManager] methods.
/// [PlatformWebViewController] methods.
abstract class PlatformWebViewController extends PlatformInterface {
/// Creates a new [PlatformWebViewController]
factory PlatformWebViewController(
Expand Down Expand Up @@ -267,7 +267,7 @@ abstract class PlatformWebViewController extends PlatformInterface {
void Function(PlatformWebViewPermissionRequest request) onPermissionRequest,
) {
throw UnimplementedError(
'setOnPermissionRequest is not implemented on the current platform',
'setOnPlatformPermissionRequest is not implemented on the current platform',
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'webview_credential.dart';

/// Defines the parameters of a pending HTTP authentication request received by
/// the webview through a [HttpAuthRequestCallback].
///
/// Platform specific implementations can add additional fields by extending
/// this class and providing a factory method that takes the [HttpAuthRequest]
/// as a parameter.
///
/// This example demonstrates how to extend the [HttpAuthRequest] to provide
/// additional platform specific parameters.
///
/// When extending [HttpAuthRequest], additional parameters should always accept
/// `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// @immutable
/// class WKWebViewHttpAuthRequest extends HttpAuthRequest {
/// WKWebViewHttpAuthRequest._(
/// HttpAuthRequest authRequest,
/// this.extraData,
/// ) : super(
/// onProceed: authRequest.onProceed,
/// onCancel: authRequest.onCancel,
/// host: authRequest.host,
/// realm: authRequest.realm,
/// );
///
/// factory WKWebViewHttpAuthRequest.fromHttpAuthRequest(
/// HttpAuthRequest authRequest, {
/// String? extraData,
/// }) {
/// return WKWebViewHttpAuthRequest._(
/// authRequest,
/// extraData: extraData,
/// );
/// }
///
/// final String? extraData;
/// }
/// ```
@immutable
class HttpAuthRequest {
/// Creates a [HttpAuthRequest].
const HttpAuthRequest({
required this.onProceed,
required this.onCancel,
required this.host,
this.realm,
});

/// The callback to authenticate.
final void Function(WebViewCredential credential) onProceed;

/// The callback to cancel authentication.
final void Function() onCancel;

/// The host requiring authentication.
final String host;

/// The realm requiring authentication.
final String? realm;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'http_auth_request.dart';
export 'http_response_error.dart';
export 'javascript_console_message.dart';
export 'javascript_log_level.dart';
Expand All @@ -18,3 +19,4 @@ export 'platform_webview_widget_creation_params.dart';
export 'url_change.dart';
export 'web_resource_error.dart';
export 'webview_cookie.dart';
export 'webview_credential.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';

import '../types/http_auth_request.dart';

/// Defines the response parameters of a pending [HttpAuthRequest] received by
/// the webview.
@immutable
class WebViewCredential {
/// Creates a [WebViewCredential].
const WebViewCredential({
required this.user,
required this.password,
});

/// The user name.
final String user;

/// The password.
final String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.6.0
version: 2.7.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ void main() {
throwsUnimplementedError,
);
});

test(
'Default implementation of setOnHttpAuthRequest should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
ExtendsPlatformNavigationDelegate(
const PlatformNavigationDelegateCreationParams());

expect(
() => callbackDelegate.setOnHttpAuthRequest((HttpAuthRequest request) {}),
throwsUnimplementedError,
);
});
}

class MockWebViewPlatformWithMixin extends MockWebViewPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,15 @@ class MockPlatformNavigationDelegate extends _i1.Mock
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
@override
_i4.Future<void> setOnHttpAuthRequest(
_i3.HttpAuthRequestCallback? onHttpAuthRequest) =>
(super.noSuchMethod(
Invocation.method(
#setOnHttpAuthRequest,
[onHttpAuthRequest],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
}