Skip to content

feat(macos): Native OAuth via ASWebAuthenticationSession#4004

Merged
louis030195 merged 3 commits into
screenpipe:mainfrom
divanshu-go:feat/macos-native-auth-session
Jun 11, 2026
Merged

feat(macos): Native OAuth via ASWebAuthenticationSession#4004
louis030195 merged 3 commits into
screenpipe:mainfrom
divanshu-go:feat/macos-native-auth-session

Conversation

@divanshu-go

@divanshu-go divanshu-go commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What changed

Clicking Login on macOS now opens a native system Safari sheet anchored to the screenpipe window, instead of a separate in-app WebView window.

The previous macOS path used a WebviewWindowBuilder window that loaded the login URL and an on_navigation hook intercepted the screenpipe:// redirect.

Before — in-app WebView window After — ASWebAuthenticationSession
UX Separate login-browser window pops up inside the app System Safari sheet overlays the current window
Cookies / SSO WKWebView's own isolated cookie jar Shares existing Safari cookies — SSO works out of the box
Callback handling on_navigation hook detects screenpipe:// scheme in the WebView Framework intercepts screenpipe:// itself, no hook needed
Window lifecycle App must manually close the login-browser window after auth Sheet closes itself automatically
Window focus after auth Focus stays in the WebView window App re-activates via activateIgnoringOtherApps
Screen.Recording.2026-06-11.at.9.48.59.PM.mov
Screen.Recording.2026-06-11.at.9.50.09.PM.mov

Why ASWebAuthenticationSession?

Apple built ASWebAuthenticationSession specifically for OAuth in native apps. It has been the recommended path since macOS 10.15 Catalina.

  • Sandboxed — the app only ever sees the final callback URL; it cannot read Safari cookies directly. Secure by design.

  • Shared session — the user's existing Safari login is reused, so SSO just works without re-entering credentials.

  • No extra plumbing — no on_navigation hook, no window lifecycle management, no manual close. The framework handles everything.

Other production macOS apps that use this API

This is the industry-standard approach for native macOS login flows:

  • ChatGPT macOS
  • Claude desktop app
  • GitHub Desktop
  • AppAuth-iOS/macOS

Replace the old open-system-browser + deep-link flow with Apple's
ASWebAuthenticationSession — a sandboxed Safari sheet that stays anchored
inside the app window and handles the screenpipe:// callback itself.

- Add auth_session module: macOS impl (apple.rs) + cross-platform stub (mod.rs)
- Wire open_login_window Tauri command to start_session on macOS
- Register module in main.rs
…ocus

Add concise Apple doc hyperlinks and explain non-obvious decisions in apple.rs.
Re-activate the app window after the auth sheet closes.

- Document presentationAnchor fallback chain (keyWindow -> windows.firstObject)
- Explain canceledLogin error code detection
- Comment prefersEphemeralWebBrowserSession trade-off
- Call activateIgnoringOtherApps after sheet closes to pull focus back

@louis030195 louis030195 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

apps/screenpipe-app-tauri/src-tauri/Cargo.toml:191 — should these be under [target.'cfg(target_os = "macos")'.dependencies] to avoid linking failures on windows/linux?
apps/screenpipe-app-tauri/src-tauri/src/auth_session/apple.rs:76 — what if screenpipe runs in menu-bar-only mode with no windows open? will this panic?

generated by the screenpipe pr-review pipe (https://screenpi.pe), not written by a human — reply and tag @louis030195 if it got something wrong.

…bar-only) panic

get_key_window_as_anchor() now returns Option instead of calling .expect().
start_session pre-checks for an available NSWindow before calling session.start(),
so the ObjC presentationAnchor delegate never fires without a valid anchor.
@divanshu-go

Copy link
Copy Markdown
Contributor Author

apps/screenpipe-app-tauri/src-tauri/Cargo.toml:191 — should these be under [target.'cfg(target_os = "macos")'.dependencies] to avoid linking failures on windows/linux? apps/screenpipe-app-tauri/src-tauri/src/auth_session/apple.rs:76 — what if screenpipe runs in menu-bar-only mode with no windows open? will this panic?

generated by the screenpipe pr-review pipe (https://screenpi.pe), not written by a human — reply and tag @louis030195 if it got something wrong.

Done.

@divanshu-go divanshu-go requested a review from louis030195 June 11, 2026 17:39
@louis030195 louis030195 merged commit e8697a6 into screenpipe:main Jun 11, 2026
11 of 12 checks passed
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