Skip to content

feat: support HTTP Basic auth on macOS WKWebView - #1356

Merged
tw93 merged 6 commits into
tw93:mainfrom
xiaojueshi:feat/macos-basic-auth
Aug 22, 2026
Merged

feat: support HTTP Basic auth on macOS WKWebView#1356
tw93 merged 6 commits into
tw93:mainfrom
xiaojueshi:feat/macos-basic-auth

Conversation

@xiaojueshi

@xiaojueshi xiaojueshi commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a --basic-auth <user:pass> CLI option that makes HTTP Basic auth work on macOS. WKWebView never shows the native 401 dialog, so sites behind Basic auth render an "Authentication required" error page and are unusable in Pake apps. The option installs a navigation-delegate proxy that answers Basic challenges, and sends the initial navigation with the Authorization header so the cold-start 401 race never triggers.

Why

macOS WKWebView only handles the 401 challenge path when the app implements webView:didReceiveAuthenticationChallenge:completionHandler:; wry's WryNavigationDelegate does not implement it, so WebKit falls back to default handling (reject the challenge, show the 401 body). Windows WebView2 and Linux WebKitGTK show their own dialogs, so this is a macOS-only gap.

Changes

  • bin/: new --basic-auth <user:pass> option; config plumbing basicAuthpake.basic_auth
  • src-tauri/: new app/auth.rs — WKWebView navigation-delegate proxy (objc2) answering HTTP Basic challenges with an NSURLCredential, plus a KVO guard that re-asserts the proxy if anything later replaces the delegate
  • src-tauri/src/app/window.rs: for the main window, start on about:blank, install the delegate, then navigate with the Authorization header embedded in the first request
  • schema/pake.schema.json, docs/cli-usage*.md, dist/cli.js: CLI surface kept in sync (enforced by the config-file sync test)

Tests

  • npx vitest run: 343 tests pass, including the schema/CLI sync suite
  • parse_basic_auth unit tests: empty input, missing separator, empty user, empty password, colons in password
  • macOS verified locally: node dist/cli.js <url> --basic-auth user:pass --iterative-build compiles and bundles cleanly on aarch64-apple-darwin; the app opens directly to the authenticated site with no "Authentication required" page on first launch
  • CI's Full Tauri Build will cross-verify on Linux/Windows once the fork-PR workflow is approved

Risks

  • macOS-only: the field is ignored on Windows/Linux (their WebViews already auto-handle Basic auth)
  • Combining --basic-auth with --ignore-certificate-errors does not chain perfectly (documented in auth.rs)
  • Credentials are visible in the shell process list while building (documented in docs/cli-usage.md)
  • Only the main window carries Basic auth; multi-window clones (pake-N) do not

xiaojueshi and others added 6 commits August 17, 2026 17:54
macOS WKWebView never shows the native 401 dialog, so sites behind
HTTP Basic auth render "Authentication required" and are unusable.
Add a --basic-auth user:pass CLI option that installs a
navigation-delegate proxy answering Basic challenges, and send the
initial navigation with the Authorization header so the cold-start
401 race cannot trigger.

- bin: --basic-auth option, config plumbing, schema, docs, dist rebuild
- src-tauri: new app/auth.rs delegate proxy with KVO guard (macOS only)
- window.rs: about:blank start + delegate install for the main window
The base64-encoded credential comes back from msg_send as a raw
*mut NSString; calling to_string() on the pointer does not compile.
Dereference it to &NSString (Display impl) first.
…the delegate

user/pass are moved into PakeBasicAuthDelegate::new, so building the
base64 header after that point borrows moved values. Compute it first
(borrowing only), then hand ownership to the delegate.
The Authorization header build can fail (nil NSData/NSString), which
previously aborted setup and left the window stuck on about:blank.
Fall back to a bare navigation and let the challenge delegate answer
the 401 instead.

Also drop the stale "lazy delegate install" wording from comments
(wry sets its navigation delegate at webview creation) and remove the
mistaken reference to issue tw93#1348 (that issue is about mTLS client
certificates, not HTTP Basic auth).
@tw93
tw93 merged commit 891bab1 into tw93:main Aug 22, 2026
@tw93

tw93 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

@xiaojueshi Thanks for digging into WKWebView's missing Basic Auth prompt. I reworked the authentication path on your branch so credentials are requested at runtime in a compact native macOS dialog, scoped to the target host, kept only for the session, and compatible with the existing certificate handling; it is now merged into main and will ship in the next Pake release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants