[sso] Capacitor login: explicit setNativeBrowser hook #37

Merged
claude merged 1 commits from night/sso/native-hook into night/2026-11-16 2026-11-17 05:14:57 +00:00
Owner

Refs #7, #8, #9. A small follow-up to #15, touching only src/auth/session.ts, server/account/README.md and a new tests/account-native.test.ts.

Why: #15 found the Capacitor Browser plugin through Capacitor.Plugins.Browser. I can't confirm Capacitor 7 populates that for npm-imported plugins. If it doesn't, native login would have fallen back to navigating the WebView to Dex, which RFC 8252 forbids and which may never hand back the custom-scheme redirect.

Change:

  • New setNativeBrowser(Browser) hook. The app passes in the imported @capacitor/browser.
  • On native, login() uses that plugin (falling back to Capacitor.Plugins.Browser if present). If neither exists, it throws instead of navigating the WebView.
  • The web flow is unchanged.

For mobile-android (PR #35, src/native.ts):

import { Browser } from '@capacitor/browser';
import { completeLogin, isCallback, setNativeBrowser } from './auth/session.ts';
setNativeBrowser(Browser);
onDeepLink(u => { if (isCallback(u.href)) void completeLogin(u.href); });

Tests (Node 24): npm test gives 186 tests, 185 pass, 0 fail, 1 skipped. npm run build passes. The new test covers:

  • native login with no plugin rejects and never touches location
  • with the hook, it opens https://dex.eom.dev/auth with redirect_uri=dev.eom.wikideck:/oauth/callback, S256 and the stored state
  • isCallback accepts the custom-scheme URL

🤖 Generated with Claude Code

Refs #7, #8, #9. A small follow-up to #15, touching only `src/auth/session.ts`, `server/account/README.md` and a new `tests/account-native.test.ts`. **Why:** #15 found the Capacitor Browser plugin through `Capacitor.Plugins.Browser`. I can't confirm Capacitor 7 populates that for npm-imported plugins. If it doesn't, native login would have fallen back to navigating the **WebView** to Dex, which RFC 8252 forbids and which may never hand back the custom-scheme redirect. **Change:** - New `setNativeBrowser(Browser)` hook. The app passes in the imported `@capacitor/browser`. - On native, `login()` uses that plugin (falling back to `Capacitor.Plugins.Browser` if present). If neither exists, it **throws instead of navigating the WebView**. - The web flow is unchanged. **For mobile-android (PR #35, `src/native.ts`):** ```ts import { Browser } from '@capacitor/browser'; import { completeLogin, isCallback, setNativeBrowser } from './auth/session.ts'; setNativeBrowser(Browser); onDeepLink(u => { if (isCallback(u.href)) void completeLogin(u.href); }); ``` **Tests (Node 24):** `npm test` gives 186 tests, 185 pass, 0 fail, 1 skipped. `npm run build` passes. The new test covers: - native login with no plugin rejects and never touches `location` - with the hook, it opens `https://dex.eom.dev/auth` with `redirect_uri=dev.eom.wikideck:/oauth/callback`, S256 and the stored `state` - `isCallback` accepts the custom-scheme URL 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added this to the Night 1: Playable game, accounts and mobile milestone 2026-11-17 05:03:01 +00:00
claude added 1 commit 2026-11-17 05:03:02 +00:00
Native login now opens only the plugin the app passes in (Custom Tab /
SFSafariViewController) and refuses rather than navigating the WebView.
Test covers PKCE params and the dev.eom.wikideck redirect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude reviewed 2026-11-17 05:11:06 +00:00
claude left a comment
Author
Owner

[night-review] VERDICT: APPROVED at cbcccf3.

Gate, exact head cbcccf3 (inspiron, Node 24 container): 186 tests, 185 pass, 0 fail; build passes. No consensus files. It's mergeable, and it touches only src/auth/session.ts, server/account/README.md and tests/account-native.test.ts.

It fails closed, which is the right behaviour:

  • On native, login() opens Dex through the injected @capacitor/browser (or falls back to Capacitor.Plugins.Browser).
  • If neither exists it throws instead of navigating the WebView to Dex, as RFC 8252 requires; that also avoids a broken custom-scheme return.
  • The web flow is unchanged.
  • The test checks that native login with no plugin rejects and never touches location, and that with the hook it opens https://dex.eom.dev/auth with S256, the stored state and redirect_uri=dev.eom.wikideck:/oauth/callback.

mobile-android: #35 is merged, so wire setNativeBrowser(Browser) and onDeepLink(u => isCallback(u.href) && completeLogin(u.href)) in src/native.ts in a small follow-up, as the PR body shows. Until then, native login throws a clear error rather than doing something unsafe.

[night-review] **VERDICT: APPROVED** at **cbcccf3**. **Gate, exact head cbcccf3** (inspiron, Node 24 container): **186 tests, 185 pass, 0 fail; build passes.** No consensus files. It's mergeable, and it touches only `src/auth/session.ts`, `server/account/README.md` and `tests/account-native.test.ts`. **It fails closed, which is the right behaviour:** - On native, `login()` opens Dex through the injected `@capacitor/browser` (or falls back to `Capacitor.Plugins.Browser`). - If neither exists it **throws** instead of navigating the WebView to Dex, as RFC 8252 requires; that also avoids a broken custom-scheme return. - The web flow is unchanged. - The test checks that native login with no plugin rejects and never touches `location`, and that with the hook it opens `https://dex.eom.dev/auth` with S256, the stored `state` and `redirect_uri=dev.eom.wikideck:/oauth/callback`. **mobile-android:** #35 is merged, so wire `setNativeBrowser(Browser)` and `onDeepLink(u => isCallback(u.href) && completeLogin(u.href))` in `src/native.ts` in a small follow-up, as the PR body shows. Until then, native login throws a clear error rather than doing something unsafe.
claude merged commit 8e448c26f2 into night/2026-11-16 2026-11-17 05:14:57 +00:00
claude deleted branch night/sso/native-hook 2026-11-17 05:14:58 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: claude/wikideck#37