Skip to content

[webview_flutter] Support for handling basic authentication requests#4140

Closed
andreisas06 wants to merge 31 commits intoflutter:mainfrom
andreisas06:webview-auth-request
Closed

[webview_flutter] Support for handling basic authentication requests#4140
andreisas06 wants to merge 31 commits intoflutter:mainfrom
andreisas06:webview-auth-request

Conversation

@andreisas06
Copy link
Contributor

Description

This pull request introduces the handling of HTTP Basic Authentication in our WebView implementation. Specifically, it includes the following changes:

  1. Added setHttpAuthCredentials() function: This function allows developers to programmatically set credentials (username and password) for a given host and realm.
  2. Implemented onReceivedHttpAuthRequest() callback: This callback is invoked when the WebView encounters a website that requires HTTP Basic Authentication. The host and realm information from the authentication request is utilized to match and use the stored credentials.

Issues fixed by PR:

Closes flutter/flutter#83556

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@andreisas06
Copy link
Contributor Author

@bparrishMines should I proceed with the PR containing only the platform interface package?

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs an implementation for webview_flutter_wkwebview. Using https://developer.apple.com/documentation/webkit/wknavigationdelegate/3601237-webview?language=objc I believe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
/// Signature for callbacks that report basic auth events by the native web view
/// Signature for callbacks that report basic auth events by the native web view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
/// Sets the auth credentials for basic authentication and can be used on onReceiveHttpAuthRequest with NavigationDelegate.
/// Sets the auth credentials for basic authentication and can be used with
/// [PlatformNavigationDelegate.onReceiveHttpAuthRequest].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FlutterAPI should pass back the HttpAuthHandler instead of adding a setAuthCredentials method. Mainly because the HttpAuthHandler has multiple methods that could be used. e.g. cancel and useHttpAuthUsernamePassword.

@andreisas06
Copy link
Contributor Author

Hey @bparrishMines , @JeroenWeener will be taking over for the IOS implementation of this PR.

@JeroenWeener JeroenWeener force-pushed the webview-auth-request branch from 38311df to 3fb8d80 Compare June 23, 2023 10:11
@bparrishMines bparrishMines requested a review from cyanglaz as a code owner July 6, 2023 10:15
@stuartmorgan-g stuartmorgan-g changed the title [webview_flutter_android] Support for handling basic authentication requests [webview_flutter] Support for handling basic authentication requests Jul 17, 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is an error, don't we also need to call completionHandler in production?

@mvanbeusekom
Copy link
Contributor

Hi @stuartmorgan,

This PR is ready for review, we are keeping it up to date until then.

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review the implementations, but I'm happy with the overall structure. Once @bparrishMines has done another full review of the PR it should be ready to break up.

if (WebViewPlatform.instance is WebKitWebViewPlatform) {
params = WebKitWebViewControllerCreationParams(
allowsInlineMediaPlayback: true,
mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad merge, or was this intentionally removed?

/// The callback to proceed with, or cancel an auth request.
///
/// If `credential` is `null`, the request will be canceled.
final void Function(WebViewCredential? credential) onAuthenticate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the outcome of #4140 (comment) was that we were going to go back to onProceed and onCancel? I'll defer to @bparrishMines on the exact callback structure though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I think we should separate this into onCancel and onProceed again. And then iOS can add its additional method.

@bparrishMines
Copy link
Contributor

I went ahead and added the changes mentioned in #4140 (comment) and updated the PR with the pigeon upgrade from #5271

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I think this is ready to be split into separate PRs. @andreisas06 @mvanbeusekom let me know if you would like to do this or have me finish this part.

@JeroenWeener
Copy link
Contributor

Hi @bparrishMines, thank you for the changes and the review.

Could you tell me how you usually deal with splitting PRs? I find myself a bit lost when trying to separate the platform interface changes from the other changes.

@stuartmorgan-g
Copy link
Collaborator

stuartmorgan-g commented Nov 10, 2023

Could you tell me how you usually deal with splitting PRs? I find myself a bit lost when trying to separate the platform interface changes from the other changes.

FWIW my workflow is:

  • Make a new local branch from the combo PR branch (e.g., git checkout -t webview-auth-request -b webview-auth-request-interface)
  • Merge in main so it's up to date
  • Revert the other packages to the state on main (git checkout main -- packages/webview_flutter/webview_flutter packages/webview_flutter/webview_flutter_android packages/webview_flutter/webview_flutter_wkwebview; git commit)

That should given you a branch that is exactly the platform interface subset of this PR. (I prefer this to trying to apply a patch file to a new clean branch because I find that more error-prone.)

@JeroenWeener
Copy link
Contributor

Thanks @stuartmorgan, learned something new today 👍

@JeroenWeener
Copy link
Contributor

@bparrishMines the platform interface PR is up! You can find it here: #5362.

@JeroenWeener
Copy link
Contributor

Thank @stuartmorgan and @bparrishMines for merging the related PRs. The final PR that exposes the iOS and Android implementations can be found here: #5727.

@andreisas06 could you close this PR?

@jmagman
Copy link
Member

jmagman commented Jan 31, 2024

@bparrishMines and @stuartmorgan can this be closed in favor of #5727 (review) and friends? Seems like this is zombied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webview_flutter] There is no callback for "Basic Authentication" on navigating to a URI

7 participants