HTTP Authentication support with unified interceptor API #391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds first-class handling of HTTP authentication challenges (Basic and Digest) to the Compose WebView Multiplatform library via a single, unified interceptor API. The API lets apps supply credentials or cancel when a site challenges for authentication. The underlying platforms (Android/iOS) negotiate the exact scheme with the server.
BasicAuthInterceptor(existing name retained) +rememberWebViewNavigator(basicAuthInterceptor = …).Motivation
What’s changed
WKNavigationDelegate.kt: Accepts bothNSURLAuthenticationMethodHTTPBasicandNSURLAuthenticationMethodHTTPDigestand forwards the challenge to the interceptor.NSURLCredentialconstructed from the provided username/password whenhandler.proceedis called.AccompanistWebView.kt: Keeps usingonReceivedHttpAuthRequest; clarifying comments document that Android funnels all HTTP auth schemes through the same callback and the platform negotiates Basic vs Digest after credentials are supplied.Public API (unchanged)
interface BasicAuthInterceptorwithonHttpAuthRequest(challenge, handler, navigator): Booleaninterface BasicAuthHandler { proceed(username, password); cancel() }data class BasicAuthChallenge(host, realm, isProxy, previousFailureCount)@Composable fun rememberWebViewNavigator(basicAuthInterceptor = …)No breaking changes. The interceptor name remains
BasicAuthInterceptorto minimize churn; it works for both Basic and Digest.Usage (excerpt)
Platform specifics and behavior
onReceivedHttpAuthRequest(view, handler, host, realm)without scheme details.handler.proceed(username, password)lets the platform choose Basic or Digest per the server’s challenge.WKWebViewexposesprotectionSpace.authenticationMethod; we forward only when it’sHTTPBasicorHTTPDigest.proceed, aNSURLCredentialis created and returned to the challenge.Security notes
Documentation updates
Testing and verification
proceedfinishes the auth.handler.proceedauthenticates successfully.Compatibility
Future work (optional)
HttpAuthInterceptorwith a deprecation shim forBasicAuthInterceptor.