feat(mobile): passkeys for Browser page sites from the phone #17762
Closedntindle(GitHub profile, opens in a new tab)wants to merge 12 commits into
main fromrefs/pull/17762/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/mobile/src/features/browser/PreviewStreamWebView.tsx line 422OutdatedResolvedby ntindle(GitHub profile, opens in a new tab)@@ -394,11 +406,17 @@394406 onViewport?.(message);395407 return;396408 case "clipboard":397- void Clipboard.setStringAsync(message.text).catch(() => undefined);409+ copyTextWithHaptic(message.text, { target: "browser page selection" });410+ return;411+ case "input":412+ onPageInput?.(message.focused);398413 return;399414 case "download":400415 offerDownload(message);401416 return;402417 case "fileChooser":403418 setFileChooser(message.chooser);404419 return;420+ case "passkey": {421+ const { request } = message;422+ void performBrowserPasskey(request).then((result) =>apps/server/src/preview/ServerBrowser.ts lines 2443 to 2443Resolvedby ntindle(GitHub profile, opens in a new tab)@@ -2209,10 +2380,18 @@22092380 if (next._tag === "frame") runFork(next.ack);22102381 // State a stalled viewer cannot miss replaces its backlog. It runs22112382 // synchronously so an older replacement can never land after a newer one.2212- else if (next._tag === "gone" || next._tag === "control" || next._tag === "fileChooser") {2383+ else if (2384+ next._tag === "gone" ||2385+ next._tag === "control" ||2386+ next._tag === "fileChooser" ||2387+ next._tag === "passkey" ||2388+ next._tag === "passkeyCancel"2389+ ) {22132390 const dropped = Effect.runSyncExit(Queue.clear(output));22142391 if (dropped._tag === "Failure") return;22152392 Queue.offerUnsafe(output, next);22162393 // The controller's open picker may have been in the dropped backlog.22172394 const chooser = next._tag === "control" ? fileChooserMessage(tab) : null;22182395 if (chooser && tab.control.controller === viewer.id) Queue.offerUnsafe(output, chooser);2396+ // So may a passkey request the page still waits on; sent twice, it would open twice.2397+ const request = dropped.value.find((item) => item._tag === "passkey");apps/server/src/preview/ServerBrowser.ts line 1233Resolvedby ntindle(GitHub profile, opens in a new tab)@@ -1102,0 +1181,21 @@1181+ if (tab && pending && pending.ticket === ticket && pending.frame === frame) {1182+ cancelPasskey(tab);1183+ }1184+ return null;1185+ }1186+ // Pages often check once, on load, so a device watching the tab counts before it takes control.1187+ if (kind === "available") {1188+ return tab !== undefined && [...tab.viewers].some((viewer) => viewer.passkeys);1189+ }1190+ const controller = tab1191+ ? [...tab.viewers].find((viewer) => viewer.id === tab.control.controller && viewer.passkeys)1192+ : undefined;1193+ if (!tab || !controller) return { native: true };1194+ if (kind !== "create" && kind !== "get") return { error: "TypeError" };1195+ // Chromium names the origin, never the page. Like Chromium's own sheet, only a1196+ // top-level page asks, one request at a time, right after the person touched it.1197+ const origin =1198+ frame === page.mainFrame() ? ServerBrowserPasskeys.passkeyOrigin(frame.url()) : null;1199+ if (1200+ origin === null ||1201+ tab.passkey !== null ||
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/mobile/modules/t3-passkeys/ios/T3PasskeysModule.swift lines 196 to 204OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +184,21 @@184+ "authenticatorAttachment": "cross-platform",185+ "transports": registration.transports.map(\.rawValue),186+ ]))187+ case let assertion as ASAuthorizationPlatformPublicKeyCredentialAssertion:188+ finish(succeeded([189+ "id": assertion.credentialID.base64URL,190+ "clientDataJSON": assertion.rawClientDataJSON.base64URL,191+ "authenticatorData": assertion.rawAuthenticatorData.base64URL,192+ "signature": assertion.signature.base64URL,193+ "userHandle": assertion.userID.base64URL,194+ "authenticatorAttachment": Self.attachment(assertion.attachment),195+ ]))196+ case let assertion as ASAuthorizationSecurityKeyPublicKeyCredentialAssertion:197+ finish(succeeded([198+ "id": assertion.credentialID.base64URL,199+ "clientDataJSON": assertion.rawClientDataJSON.base64URL,200+ "authenticatorData": assertion.rawAuthenticatorData.base64URL,201+ "signature": assertion.signature.base64URL,202+ "userHandle": assertion.userID.base64URL,203+ "authenticatorAttachment": "cross-platform",204+ ]))apps/mobile/src/features/browser/BrowserPreviewRouteScreen.tsx line 31Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -27,3 +32,5 @@2732 const BrowserPreviewStack = createNativeStackNavigator<{ BrowserPreview: undefined }>();28332934 const NO_PICTURE_IN_PICTURE: PreviewPictureInPictureState = { supported: false, active: false };35+// Cmd+C runs as the page's copy command, and the page sends its selection back.36+const COPY_KEY = { key: "c", code: "KeyC", keyCode: 67, modifiers: 4 } as const;apps/server/src/preview/ServerBrowser.ts lines 1241 to 1256Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1102,0 +1204,21 @@1204+ return { error: "NotAllowedError" };1205+ }1206+ const request = ServerBrowserPasskeys.passkeyRequest(kind, origin, options);1207+ if ("error" in request) return request;1208+ const id = NodeCrypto.randomUUID();1209+ const answer = await new Promise<ServerBrowserPasskeys.PasskeyAnswer>((resolve) => {1210+ const timer = setTimeout(() => cancelPasskey(tab), request.timeoutMs);1211+ tab.passkey = {1212+ id,1213+ ticket,1214+ frame,1215+ viewerId: controller.id,1216+ request,1217+ settle: (next) => {1218+ clearTimeout(timer);1219+ if (tab.passkey?.id === id) tab.passkey = null;1220+ resolve(next);1221+ },1222+ };1223+ controller.push({ _tag: "passkey", id, kind, origin, publicKey: request.publicKey });1224+ });coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
@@ -403,7 +426,21 @@426+ case "input":427+ onPageInput?.(message.focused);403428 return;404429 case "download":405430 offerDownload(message);406431 return;407432 case "fileChooser":408433 setFileChooser(message.chooser);409434 return;435+ case "passkey": {436+ const { request } = message;437+ passkeyRequest.current = request.id;438+ void performBrowserPasskey(request).then((result) => {439+ if (passkeyRequest.current === request.id) passkeyRequest.current = null;440+ command({ type: "passkeyResult", id: request.id, result });441+ });442+ return;443+ }444+ case "passkeyCancel":445+ cancelBrowserPasskey(message.id);446+ return;maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed