Skip to content
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

[webview_flutter] Support for handling basic authentication requests #4140

Closed
wants to merge 31 commits into from

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.

@@ -30,6 +30,9 @@ typedef WebResourceErrorCallback = void Function(WebResourceError error);
/// url of the web view.
typedef UrlChangeCallback = void Function(UrlChange change);

/// 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
/// 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.

@@ -261,6 +261,13 @@ abstract class PlatformWebViewController extends PlatformInterface {
'setUserAgent is not implemented on the current platform');
}

/// Sets the auth credentials for basic authentication and can be used on onReceiveHttpAuthRequest with NavigationDelegate.
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].

@@ -95,6 +98,13 @@ public void doUpdateVisitedHistory(
flutterApi.doUpdateVisitedHistory(this, view, url, isReload, reply -> {});
}

@Override
public void onReceivedHttpAuthRequest(
@NonNull WebView view, HttpAuthHandler handler, String host, String realm) {
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.

@stuartmorgan stuartmorgan changed the title [webview_flutter_android] Support for handling basic authentication requests [webview_flutter] Support for handling basic authentication requests Jul 17, 2023
: nil;

completionHandler(disposition, credential);
}
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?

@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?

ChopinDavid pushed a commit to wwt/flutter-packages that referenced this pull request Dec 28, 2023
…(iOS) (flutter#5455)

Adds the iOS implementation for basic http authentication.

This PR is part of a series of PRs that aim to close flutter/flutter#83556.
The PR that contains all changes can be found at flutter#4140.
@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.

arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…(Platform Interface) (flutter#5362)

Adds the platform interface implementation for basic http authentication.

This PR is part of a series of PRs that aim to close flutter/flutter#83556.
The PR that contains all changes can be found at flutter#4140.
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…(Android) (flutter#5454)

Adds the Android implementation for basic http authentication.

This PR is part of a series of PRs that aim to close flutter/flutter#83556.
The PR that contains all changes can be found at flutter#4140.
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…(iOS) (flutter#5455)

Adds the iOS implementation for basic http authentication.

This PR is part of a series of PRs that aim to close flutter/flutter#83556.
The PR that contains all changes can be found at flutter#4140.
bill-skdnd pushed a commit to skdnd-metaspace/webview_flutter_wkwebview that referenced this pull request Aug 2, 2024
…(iOS) (#5455)

Adds the iOS implementation for basic http authentication.

This PR is part of a series of PRs that aim to close flutter/flutter#83556.
The PR that contains all changes can be found at flutter/packages#4140.
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