Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat(mobile): activate native OAuth return links (#729)
Gener66daebe2792c
diff --git a/.github/workflows/mobile-release.yml b/.github/workflows/mobile-release.ymlindex 46daffb5c..43ddeb0bc 100644--- a/.github/workflows/mobile-release.yml+++ b/.github/workflows/mobile-release.yml@@ -143,7 +143,31 @@ jobs:test -n "$app_path"codesign --verify --deep --strict --verbose=2 "$app_path"- test "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$app_path/Info.plist")" = "ai.alook.ios"+ entitlements_path="$extract_dir/signed-entitlements.plist"+ codesign -d --entitlements :- "$app_path" > "$entitlements_path"+ python3 - "$app_path/Info.plist" "$entitlements_path" <<'PY'+ import plistlib+ import sys++ with open(sys.argv[1], "rb") as info_file:+ info = plistlib.load(info_file)+ with open(sys.argv[2], "rb") as entitlements_file:+ entitlements = plistlib.load(entitlements_file)++ assert info["CFBundleIdentifier"] == "ai.alook.ios"+ assert info["CFBundleURLTypes"] == [+ {"CFBundleURLName": "ai.alook", "CFBundleURLSchemes": ["ai.alook"]}+ ]+ assert entitlements["application-identifier"] == "5RF24VHDQB.ai.alook.ios"+ assert entitlements["com.apple.developer.team-identifier"] == "5RF24VHDQB"+ assert entitlements["com.apple.developer.associated-domains"] == [+ "applinks:auth.alook.ai"+ ]+ PY++ grep -F 'AUTH_WORKER_HOST = "auth.alook.ai"' src/web/auth/index.ts+ grep -F 'AUTH_WORKER_RETURN_PATH = "/auth/native/return"' src/web/auth/index.ts+ grep -F 'appID: "5RF24VHDQB.ai.alook.ios"' src/web/auth/index.tstauri_version=$(node -p "require('./src/desktop/src-tauri/tauri.conf.json').version")package_version=$(node -p "require('./src/desktop/package.json').version")test "$tauri_version" = "$package_version"@@ -316,6 +340,67 @@ jobs:normalized_signature=$(tr '[:lower:]' '[:upper:]' <<<"$signature" | tr -d ':')grep -F '9DC6EDE94BA663EEC9EC98FF7BAFD55E248B6C4BC2157FCF042DF59B0E410806' <<<"$normalized_signature"+ manifest_path="$RUNNER_TEMP/android-manifest-tree.txt"+ $aapt dump xmltree "$apk_source" AndroidManifest.xml > "$manifest_path"+ python3 - "$manifest_path" <<'PY'+ import re+ import sys+ from pathlib import Path++ manifest = Path(sys.argv[1]).read_text()+ activity_match = re.search(+ r'^ E: activity .*?(?=^ E: (?:activity|activity-alias|service|receiver|provider)\b|\Z)',+ manifest,+ re.MULTILINE | re.DOTALL,+ )+ assert activity_match, "MainActivity missing from packaged manifest"+ activity = activity_match.group(0)+ assert '="ai.alook.android.MainActivity"' in activity+ assert re.search(r'android:launchMode.*?\(type 0x10\)0x2$', activity, re.MULTILINE)++ filters = re.findall(+ r'^ E: intent-filter .*?(?=^ E: intent-filter|^ E: |\Z)',+ activity,+ re.MULTILINE | re.DOTALL,+ )++ def link_data(intent_filter):+ return re.findall(+ r'android:(scheme|host|path).*?="([^"]+)"', intent_filter+ )++ link_filters = [intent_filter for intent_filter in filters if link_data(intent_filter)]+ assert len(link_filters) == 2, "expected exactly two packaged deep-link filters"+ verified = [+ intent_filter+ for intent_filter in link_filters+ if "android:autoVerify" in intent_filter+ and link_data(intent_filter)+ == [+ ("scheme", "https"),+ ("host", "auth.alook.ai"),+ ("path", "/auth/native/return"),+ ]+ ]+ fallback = [+ intent_filter+ for intent_filter in link_filters+ if "android:autoVerify" not in intent_filter+ and link_data(intent_filter)+ == [+ ("scheme", "ai.alook"),+ ("host", "auth"),+ ("path", "/native/return"),+ ]+ ]+ assert len(verified) == 1, "exact verified HTTPS App Link missing"+ assert len(fallback) == 1, "exact non-verified fallback link missing"+ PY++ grep -F 'AUTH_WORKER_HOST = "auth.alook.ai"' src/web/auth/index.ts+ grep -F 'package_name: "ai.alook.android"' src/web/auth/index.ts+ grep -F '9D:C6:ED:E9:4B:A6:63:EE:C9:EC:98:FF:7B:AF:D5:5E:24:8B:6C:4B:C2:15:7F:CF:04:2D:F5:9B:0E:41:08:06' src/web/auth/index.ts+apk_name="Alook_${EXPECTED_VERSION}_android.apk"apk_path="$RUNNER_TEMP/$apk_name"install -m 644 "$apk_source" "$apk_path"diff --git a/scripts/ci/native-oauth-desktop.test.ts b/scripts/ci/native-oauth-desktop.test.tsindex 296056a86..6442f7d3d 100644--- a/scripts/ci/native-oauth-desktop.test.ts+++ b/scripts/ci/native-oauth-desktop.test.ts@@ -17,7 +17,7 @@ describe("desktop native OAuth security configuration", () => {}const oauth = merged.find(c => c.permissions.includes("native-oauth"))!expect(oauth.windows).toEqual(["main"])- expect(oauth.platforms).toEqual(["linux", "macOS", "windows"])+ expect(oauth.platforms).toEqual(expect.arrayContaining(["linux", "macOS", "windows"]))expect(oauth.remote?.urls).toEqual(config === production ? ["https://alook.ai"] : ["http://localhost:3000"])expect(oauth.local).toBe(config === development)})@@ -35,8 +35,8 @@ describe("desktop native OAuth security configuration", () => {}expect(capabilities(production).find(c => c.identifier === "desktop-capability")?.permissions).toContain("desktop-commands")})- it("registers desktop-only scheme and ordered single-instance intake without activating mobile", () => {- expect(production.plugins?.["deep-link"]).toEqual({ desktop: { schemes: ["ai.alook.desktop"] } })+ it("preserves the desktop-only scheme and ordered single-instance intake", () => {+ expect(production.plugins?.["deep-link"]).toMatchObject({ desktop: { schemes: ["ai.alook.desktop"] } })const source = read("src/lib.rs")expect(source.indexOf("tauri_plugin_single_instance::init")).toBeLessThan(source.indexOf("tauri_plugin_deep_link::init"))expect(source.indexOf("tauri_plugin_deep_link::init")).toBeLessThan(source.indexOf("tauri_plugin_opener::init"))diff --git a/scripts/ci/native-oauth-mobile.test.ts b/scripts/ci/native-oauth-mobile.test.tsnew file mode 100644index 000000000..4202ceda3--- /dev/null+++ b/scripts/ci/native-oauth-mobile.test.ts@@ -0,0 +1,202 @@+import { readFileSync } from "node:fs"+import { resolve } from "node:path"+import { describe, expect, it } from "vitest"+import {+ ANDROID_ASSET_LINKS,+ APPLE_APP_SITE_ASSOCIATION,+ AUTH_WORKER_HOST,+ AUTH_WORKER_RETURN_PATH,+} from "../../src/web/auth/index"++const root = resolve(import.meta.dirname, "../..")+const tauriRoot = resolve(root, "src/desktop/src-tauri")+const readRoot = (file: string) => readFileSync(resolve(root, file), "utf8")+const readTauri = (file: string) => readFileSync(resolve(tauriRoot, file), "utf8")++type Capability = {+ identifier: string+ local: boolean+ remote: { urls: string[] }+ windows: string[]+ platforms: string[]+ permissions: string[]+}++type MobileLink = {+ scheme: string[]+ host: string+ path: string[]+ appLink?: boolean+}++const production = JSON.parse(readTauri("tauri.conf.json")) as {+ app: { security: { capabilities: string[] } }+ plugins: { "deep-link": { mobile: MobileLink[]; desktop: { schemes: string[] } } }+}+const development = JSON.parse(readTauri("tauri.dev.conf.json")) as {+ app: { security: { capabilities: Array<string | Capability> } }+}+const ios = JSON.parse(readTauri("tauri.ios.conf.json")) as {+ identifier: string+ bundle: { iOS: { developmentTeam: string } }+}+const android = JSON.parse(readTauri("tauri.android.conf.json")) as { identifier: string }+const mobileCapability = JSON.parse(+ readTauri("capabilities/native-oauth-mobile.json"),+) as Capability+const androidManifest = readTauri("gen/android/app/src/main/AndroidManifest.xml")+const iosEntitlements = readTauri(+ "gen/apple/alook-desktop_iOS/alook-desktop_iOS.entitlements",+)+const iosProject = readTauri("gen/apple/project.yml")+const cargo = readTauri("Cargo.toml")+const rustEntry = readTauri("src/lib.rs")+const mobileRelease = readRoot(".github/workflows/mobile-release.yml")+const desktopPackage = JSON.parse(readRoot("src/desktop/package.json")) as {+ scripts: Record<string, string>+}++const intentFilters = Array.from(+ androidManifest.matchAll(/<intent-filter([^>]*)>([\s\S]*?)<\/intent-filter>/g),+ match => ({ attributes: match[1], body: match[2] }),+)++describe("native OAuth mobile activation", () => {+ it("declares one exact verified HTTPS link and one exact non-verified fallback", () => {+ expect(production.plugins["deep-link"].mobile).toEqual([+ {+ scheme: ["https"],+ host: "auth.alook.ai",+ path: ["/auth/native/return"],+ },+ {+ scheme: ["ai.alook"],+ host: "auth",+ path: ["/native/return"],+ appLink: false,+ },+ ])+ expect(production.plugins["deep-link"].desktop).toEqual({+ schemes: ["ai.alook.desktop"],+ })+ })++ it("grants only the existing command ACL to trusted mobile WebViews", () => {+ expect(production.app.security.capabilities).toContain("native-oauth-mobile")+ expect(mobileCapability).toMatchObject({+ identifier: "native-oauth-mobile",+ windows: ["main"],+ platforms: ["android", "iOS"],+ local: false,+ remote: { urls: ["https://alook.ai"] },+ permissions: ["native-oauth"],+ })+ expect(mobileCapability.permissions).not.toEqual(+ expect.arrayContaining([+ expect.stringMatching(/^(?:core:default$|core:event:|deep-link:|store:)/),+ ]),+ )+ const devOauth = development.app.security.capabilities.find(+ capability => typeof capability !== "string" && capability.identifier === "native-oauth-dev",+ )+ expect(devOauth).toMatchObject({+ windows: ["main"],+ platforms: ["linux", "macOS", "windows", "android", "iOS"],+ remote: { urls: ["http://localhost:3000"] },+ permissions: ["native-oauth"],+ })+ expect(desktopPackage.scripts.ios).toContain(+ "--config src-tauri/tauri.dev.conf.json",+ )+ expect(desktopPackage.scripts.android).toContain(+ "--config src-tauri/tauri.dev.conf.json",+ )+ })++ it("builds the native owner on mobile without moving single-instance off desktop", () => {+ const desktopTarget = cargo.indexOf('[target."cfg(not(any(target_os')+ expect(desktopTarget).toBeGreaterThan(0)+ const common = cargo.slice(0, desktopTarget)+ const desktopOnly = cargo.slice(desktopTarget)+ for (const dependency of [+ "tauri-plugin-deep-link",+ "tauri-plugin-store",+ "base64",+ "getrandom",+ "sha2",+ "subtle",+ "url",+ ]) {+ expect(common).toContain(`${dependency} =`)+ expect(desktopOnly).not.toContain(`${dependency} =`)+ }+ expect(desktopOnly).toContain("tauri-plugin-single-instance")+ expect(rustEntry).toContain("fn run_mobile(")+ expect(rustEntry).toContain("native_oauth_runtime::native_oauth_prepare")+ expect(rustEntry).toContain("native_oauth_runtime::setup(app.handle())")+ expect(rustEntry.indexOf("tauri_plugin_single_instance::init")).toBeLessThan(+ rustEntry.indexOf("tauri_plugin_deep_link::init"),+ )+ expect(rustEntry.indexOf("tauri_plugin_deep_link::init")).toBeLessThan(+ rustEntry.indexOf("tauri_plugin_opener::init"),+ )+ })++ it("keeps generated Apple identity, entitlement, and fallback sources aligned", () => {+ expect(ios).toEqual({+ $schema: "./gen/schemas/ios-schema.json",+ identifier: "ai.alook.ios",+ bundle: { iOS: { developmentTeam: "5RF24VHDQB" } },+ })+ expect(iosProject).toContain("PRODUCT_BUNDLE_IDENTIFIER: ai.alook.ios")+ expect(iosProject).toContain("DEVELOPMENT_TEAM: 5RF24VHDQB")+ expect(iosEntitlements).toContain("<string>applinks:auth.alook.ai</string>")+ expect(mobileRelease).toContain('info["CFBundleURLTypes"] ==')+ expect(mobileRelease).toContain("ai.alook")+ })++ it("keeps generated Android verified and fallback intents separate on singleTask", () => {+ expect(android.identifier).toBe("ai.alook.android")+ expect(androidManifest).toContain('android:launchMode="singleTask"')+ const verified = intentFilters.find(filter => filter.attributes.includes("autoVerify"))+ expect(verified?.body).toContain('<data android:scheme="https" />')+ expect(verified?.body).toContain('<data android:host="auth.alook.ai" />')+ expect(verified?.body).toContain('<data android:path="/auth/native/return" />')+ const fallback = intentFilters.find(filter => filter.body.includes('android:scheme="ai.alook"'))+ expect(fallback?.attributes).not.toContain("autoVerify")+ expect(fallback?.body).toContain('<data android:host="auth" />')+ expect(fallback?.body).toContain('<data android:path="/native/return" />')+ })++ it("ties native identities and the release signer to hosted association JSON", () => {+ expect(AUTH_WORKER_HOST).toBe("auth.alook.ai")+ expect(AUTH_WORKER_RETURN_PATH).toBe("/auth/native/return")+ expect(APPLE_APP_SITE_ASSOCIATION.applinks.details).toEqual([+ expect.objectContaining({+ appID: `${ios.bundle.iOS.developmentTeam}.${ios.identifier}`,+ components: [expect.objectContaining({ "/": AUTH_WORKER_RETURN_PATH })],+ }),+ ])+ expect(ANDROID_ASSET_LINKS).toEqual([+ expect.objectContaining({+ target: expect.objectContaining({+ package_name: android.identifier,+ sha256_cert_fingerprints: [+ "9D:C6:ED:E9:4B:A6:63:EE:C9:EC:98:FF:7B:AF:D5:5E:24:8B:6C:4B:C2:15:7F:CF:04:2D:F5:9B:0E:41:08:06",+ ],+ }),+ }),+ ])+ expect(mobileRelease).toContain(+ "9DC6EDE94BA663EEC9EC98FF7BAFD55E248B6C4BC2157FCF042DF59B0E410806",+ )+ for (const value of [+ JSON.stringify(production),+ iosEntitlements,+ androidManifest,+ readRoot("src/web/auth/index.ts"),+ ]) {+ expect(value).not.toContain("link.alook.ai")+ }+ })+})diff --git a/scripts/ci/workflow-contract.test.ts b/scripts/ci/workflow-contract.test.tsindex c3d284484..a9da64680 100644--- a/scripts/ci/workflow-contract.test.ts+++ b/scripts/ci/workflow-contract.test.ts@@ -1063,6 +1063,17 @@ describe("Mobile release availability", () => {expect(mobileReleaseWorkflow).toContain('bundleVersion\\\":\\\"${GITHUB_RUN_NUMBER}')expect(mobileReleaseWorkflow).toContain("CFBundleShortVersionString")expect(mobileReleaseWorkflow).toContain("CFBundleVersion")+ expect(mobileReleaseWorkflow).toContain('info["CFBundleURLTypes"] ==')+ expect(mobileReleaseWorkflow).toContain("codesign -d --entitlements :-")+ expect(mobileReleaseWorkflow).toContain('entitlements["application-identifier"]')+ expect(mobileReleaseWorkflow).toContain("5RF24VHDQB.ai.alook.ios")+ expect(mobileReleaseWorkflow).toContain(+ 'entitlements["com.apple.developer.team-identifier"]',+ )+ expect(mobileReleaseWorkflow).toContain(+ 'entitlements["com.apple.developer.associated-domains"]',+ )+ expect(mobileReleaseWorkflow).toContain("applinks:auth.alook.ai")expect(mobileReleaseWorkflow).toContain("xcrun altool --upload-app")expect(mobileReleaseWorkflow).toContain("actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a")expect(bumpScript).toContain('args.includes("--mobile")')@@ -1092,6 +1103,12 @@ describe("Mobile release availability", () => {expect(mobileReleaseWorkflow).toContain("--target aarch64 armv7")expect(mobileReleaseWorkflow).toContain("package: name='ai.alook.android'")expect(mobileReleaseWorkflow).toContain("apksigner verify --verbose --print-certs")+ expect(mobileReleaseWorkflow).toContain('aapt dump xmltree "$apk_source" AndroidManifest.xml')+ expect(mobileReleaseWorkflow).toContain("android:autoVerify")+ expect(mobileReleaseWorkflow).toContain('(\"host\", \"auth.alook.ai\")')+ expect(mobileReleaseWorkflow).toContain('(\"path\", \"/auth/native/return\")')+ expect(mobileReleaseWorkflow).toContain('(\"scheme\", \"ai.alook\")')+ expect(mobileReleaseWorkflow).toContain('(\"path\", \"/native/return\")')expect(mobileReleaseWorkflow).toContain("gh release upload")expect(mobileReleaseWorkflow).toContain("Alook_${EXPECTED_VERSION}_android.apk")expect(mobileReleaseWorkflow).toContain('gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json body')diff --git a/src/desktop/package.json b/src/desktop/package.jsonindex 77f18d6f6..4866e423a 100644--- a/src/desktop/package.json+++ b/src/desktop/package.json@@ -6,8 +6,8 @@"dev": "tauri dev --config src-tauri/tauri.dev.conf.json","build": "sh scripts/build.sh","tauri": "tauri",- "ios": "tauri ios dev",- "android": "tauri android dev"+ "ios": "tauri ios dev --config src-tauri/tauri.dev.conf.json",+ "android": "tauri android dev --config src-tauri/tauri.dev.conf.json"},"devDependencies": {"@tauri-apps/cli": "^2.11.4"diff --git a/src/desktop/src-tauri/Cargo.toml b/src/desktop/src-tauri/Cargo.tomlindex 80e10ae57..112786345 100644--- a/src/desktop/src-tauri/Cargo.toml+++ b/src/desktop/src-tauri/Cargo.toml@@ -16,22 +16,22 @@ tauri = { version = "2", features = ["tray-icon", "image-png", "macos-private-apserde = { version = "1", features = ["derive"] }serde_json = "1"tauri-plugin-opener = "2"+tauri-plugin-deep-link = "2"+tauri-plugin-store = "2"+base64 = "0.22"+getrandom = "0.3"+sha2 = "0.10"+subtle = "2"+url = "2"[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]tauri-plugin-notification = "2"tauri-plugin-updater = "2"tauri-plugin-dialog = "2"tauri-plugin-clipboard-manager = "2"-base64 = "0.22"tokio = { version = "1", features = ["macros"] }command-group = "5.0.1"tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }-tauri-plugin-deep-link = "2"-tauri-plugin-store = "2"-getrandom = "0.3"-sha2 = "0.10"-subtle = "2"-url = "2"[target."cfg(target_os = \"macos\")".dependencies]objc2 = "0.6"diff --git a/src/desktop/src-tauri/capabilities/native-oauth-mobile.json b/src/desktop/src-tauri/capabilities/native-oauth-mobile.jsonnew file mode 100644index 000000000..a1839c8ae--- /dev/null+++ b/src/desktop/src-tauri/capabilities/native-oauth-mobile.json@@ -0,0 +1,21 @@+{+ "$schema": "../gen/schemas/mobile-schema.json",+ "identifier": "native-oauth-mobile",+ "description": "Native OAuth commands for the trusted mobile WebView",+ "windows": [+ "main"+ ],+ "platforms": [+ "android",+ "iOS"+ ],+ "local": false,+ "remote": {+ "urls": [+ "https://alook.ai"+ ]+ },+ "permissions": [+ "native-oauth"+ ]+}diff --git a/src/desktop/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/src/desktop/src-tauri/gen/android/app/src/main/AndroidManifest.xmlindex 363f61024..f064576bf 100644--- a/src/desktop/src-tauri/gen/android/app/src/main/AndroidManifest.xml+++ b/src/desktop/src-tauri/gen/android/app/src/main/AndroidManifest.xml@@ -25,18 +25,25 @@<category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter><!-- DEEP LINK PLUGIN. AUTO-GENERATED. DO NOT REMOVE. -->+ <intent-filter android:autoVerify="true" >+ <action android:name="android.intent.action.VIEW" />+ <!-- ChromeOS ARC++ uses a different action for deep links -->+ <action android:name="org.chromium.arc.intent.action.VIEW" />+ <category android:name="android.intent.category.DEFAULT" />+ <category android:name="android.intent.category.BROWSABLE" />+ <data android:scheme="https" />+ <data android:host="auth.alook.ai" />+ <data android:path="/auth/native/return" />+ </intent-filter><intent-filter ><action android:name="android.intent.action.VIEW" /><!-- ChromeOS ARC++ uses a different action for deep links --><action android:name="org.chromium.arc.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" />- <data android:scheme="alook" />- <data android:host="alook.ai" />----+ <data android:scheme="ai.alook" />+ <data android:host="auth" />+ <data android:path="/native/return" /></intent-filter><!-- DEEP LINK PLUGIN. AUTO-GENERATED. DO NOT REMOVE. --></activity>diff --git a/src/desktop/src-tauri/gen/apple/alook-desktop_iOS/alook-desktop_iOS.entitlements b/src/desktop/src-tauri/gen/apple/alook-desktop_iOS/alook-desktop_iOS.entitlementsindex 21e2f8d83..e8f0e028c 100644--- a/src/desktop/src-tauri/gen/apple/alook-desktop_iOS/alook-desktop_iOS.entitlements+++ b/src/desktop/src-tauri/gen/apple/alook-desktop_iOS/alook-desktop_iOS.entitlements@@ -1,5 +1,10 @@<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">-<dict/>-</plist>\ No newline at end of file+<dict>+ <key>com.apple.developer.associated-domains</key>+ <array>+ <string>applinks:auth.alook.ai</string>+ </array>+</dict>+</plist>diff --git a/src/desktop/src-tauri/src/lib.rs b/src/desktop/src-tauri/src/lib.rsindex 756f2b2ff..cd8ec8cb3 100644--- a/src/desktop/src-tauri/src/lib.rs+++ b/src/desktop/src-tauri/src/lib.rs@@ -1,11 +1,8 @@mod commands;-#[cfg(desktop)]use tauri::Manager;-#[cfg(desktop)]mod native_oauth;-#[cfg(desktop)]mod native_oauth_runtime;#[cfg(desktop)]@@ -21,13 +18,13 @@ mod macos_window;pub fn run() {let builder = tauri::Builder::default();#[cfg(desktop)]+ let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {+ commands::show_main_window(app);+ }));let builder = builder- .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {- commands::show_main_window(app);- })).plugin(tauri_plugin_deep_link::init())- .plugin(tauri_plugin_store::Builder::default().build());- let builder = builder.plugin(tauri_plugin_opener::init());+ .plugin(tauri_plugin_store::Builder::default().build())+ .plugin(tauri_plugin_opener::init());// Desktop-only plugins#[cfg(desktop)]@@ -58,6 +55,38 @@ pub fn run() {}#[cfg(not(desktop))]+ run_mobile(builder);+}++#[cfg(not(desktop))]+fn run_mobile(mut builder: tauri::Builder<tauri::Wry>) {+ builder = builder.invoke_handler(tauri::generate_handler![+ native_oauth_runtime::native_oauth_snapshot,+ native_oauth_runtime::native_oauth_listen,+ native_oauth_runtime::native_oauth_unlisten,+ native_oauth_runtime::native_oauth_prepare,+ native_oauth_runtime::native_oauth_open_start,+ native_oauth_runtime::native_oauth_pending_exchange,+ native_oauth_runtime::native_oauth_reject_candidate,+ native_oauth_runtime::native_oauth_finish,+ native_oauth_runtime::native_oauth_cancel,+ ]);++ builder = builder.setup(|app| {+ if native_oauth_runtime::setup(app.handle()).is_err() {+ eprintln!("native OAuth storage unavailable");+ }+ Ok(())+ });++ builder = builder.on_page_load(|webview, payload| {+ if webview.label() == "main"+ && matches!(payload.event(), tauri::webview::PageLoadEvent::Started)+ {+ native_oauth_runtime::retire_listener(webview.app_handle());+ }+ });+run_app(builder);}diff --git a/src/desktop/src-tauri/src/native_oauth.rs b/src/desktop/src-tauri/src/native_oauth.rsindex 11d75fa98..e8b158a1e 100644--- a/src/desktop/src-tauri/src/native_oauth.rs+++ b/src/desktop/src-tauri/src/native_oauth.rs@@ -164,11 +164,22 @@ fn allowed_status(value: &str) -> bool {)}-fn parse_callback(serialized: &str) -> Option<(String, Option<String>, Option<String>)> {+fn parse_callback(+ serialized: &str,+ platform: &str,+) -> Option<(String, Option<String>, Option<String>)> {if serialized.len() > 512 {return None;}- let query = serialized.strip_prefix("ai.alook.desktop://auth/native/return?")?;+ let query = match platform {+ "macos" | "windows" | "linux" => {+ serialized.strip_prefix("ai.alook.desktop://auth/native/return?")+ }+ "ios" | "android" => serialized+ .strip_prefix("https://auth.alook.ai/auth/native/return?")+ .or_else(|| serialized.strip_prefix("ai.alook://auth/native/return?")),+ _ => None,+ }?;let mut attempt = None;let mut code = None;let mut status = None;@@ -258,7 +269,7 @@ impl Record {) -> Result<Registration, &'static str> {if !matches!(provider, "github" | "google")|| !safe_redirect(redirect_path)- || !matches!(platform, "macos" | "windows" | "linux")+ || !matches!(platform, "macos" | "windows" | "linux" | "ios" | "android"){return Err("invalid_request");}@@ -310,7 +321,16 @@ impl Record {}pub fn intake(&mut self, url: &url::Url, now: u64) -> Result<bool, &'static str> {- let Some((id, code, status)) = parse_callback(url.as_str()) else {+ self.intake_for_platform(url, now, std::env::consts::OS)+ }++ fn intake_for_platform(+ &mut self,+ url: &url::Url,+ now: u64,+ platform: &str,+ ) -> Result<bool, &'static str> {+ let Some((id, code, status)) = parse_callback(url.as_str(), platform) else {return Ok(false);};let Some(a) = self.attempt.as_mut() else {@@ -459,7 +479,7 @@ mod tests {fn serialized_callback_parser_rejects_noncanonical_direct_input() {let r = waiting();let good = callback(&r, &"c".repeat(32));- assert!(parse_callback(&good).is_some());+ assert!(parse_callback(&good, "macos").is_some());for bad in [format!("{good}&x=1"),format!("{good}&status=access_denied"),@@ -471,7 +491,7 @@ mod tests {good.replace("ai.alook.desktop", "ai.alook"),good.replace("code=", "c%6fde="),] {- assert!(parse_callback(&bad).is_none());+ assert!(parse_callback(&bad, "macos").is_none());}}#[test]@@ -670,6 +690,88 @@ mod tests {r.open(&p.attempt_id, &good, false).unwrap();assert!(r.open(&p.attempt_id, &good, false).is_err());assert!(r.prepare("apple", "/c/me", "macos", NOW).is_err());- assert!(r.prepare("google", "/c/me", "ios", NOW).is_err());+ assert!(r.prepare("google", "/c/me", "ios", NOW).is_ok());+ assert!(r.prepare("google", "/c/me", "android", NOW).is_ok());+ assert!(r.prepare("google", "/c/me", "web", NOW).is_err());+ }++ #[test]+ fn mobile_callbacks_accept_only_exact_primary_and_fallback_identities() {+ for platform in ["ios", "android"] {+ let mut record = Record::new().unwrap();+ let attempt = record.prepare("github", "/c/me", platform, NOW).unwrap();+ record+ .open(+ &attempt.attempt_id,+ &format!(+ "https://alook.ai/auth/native/start?attempt={}",+ attempt.attempt_id+ ),+ false,+ )+ .unwrap();+ for prefix in [+ "https://auth.alook.ai/auth/native/return",+ "ai.alook://auth/native/return",+ ] {+ let raw = format!(+ "{prefix}?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ );+ let mut candidate = record.clone();+ assert!(candidate+ .intake_for_platform(&url::Url::parse(&raw).unwrap(), NOW, platform)+ .unwrap());+ }+ let before = serde_json::to_value(&record).unwrap();+ for raw in [+ format!(+ "http://auth.alook.ai/auth/native/return?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ ),+ format!(+ "https://auth.alook.ai:8443/auth/native/return?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ ),+ format!(+ "https://[email protected]/auth/native/return?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ ),+ format!(+ "ai.alook.desktop://auth/native/return?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ ),+ format!(+ "ai.alook://auth/auth/native/return?attempt={}&code={}",+ attempt.attempt_id,+ "c".repeat(32)+ ),+ ] {+ assert!(!record+ .intake_for_platform(&url::Url::parse(&raw).unwrap(), NOW, platform)+ .unwrap());+ assert_eq!(serde_json::to_value(&record).unwrap(), before);+ }+ }+ }++ #[test]+ fn desktop_rejects_mobile_callback_identities() {+ let mut record = waiting();+ let id = record.attempt.as_ref().unwrap().id.clone();+ for prefix in [+ "https://auth.alook.ai/auth/native/return",+ "ai.alook://auth/native/return",+ ] {+ let raw = format!("{prefix}?attempt={id}&code={}", "c".repeat(32));+ assert!(!record+ .intake_for_platform(&url::Url::parse(&raw).unwrap(), NOW, "macos")+ .unwrap());+ }}}diff --git a/src/desktop/src-tauri/src/native_oauth_runtime.rs b/src/desktop/src-tauri/src/native_oauth_runtime.rsindex 9aa5db4bb..6eb36fe86 100644--- a/src/desktop/src-tauri/src/native_oauth_runtime.rs+++ b/src/desktop/src-tauri/src/native_oauth_runtime.rs@@ -129,6 +129,7 @@ fn intake(app: &AppHandle, url: &url::Url) {.transact(|record| record.intake(url, now())).unwrap_or(false){+ #[cfg(desktop)]crate::commands::show_main_window(app);state.notify();}diff --git a/src/desktop/src-tauri/tauri.conf.json b/src/desktop/src-tauri/tauri.conf.jsonindex cfb99e9cd..24bb3a340 100644--- a/src/desktop/src-tauri/tauri.conf.json+++ b/src/desktop/src-tauri/tauri.conf.json@@ -47,7 +47,8 @@"capabilities": ["desktop-capability","external-links",- "native-oauth"+ "native-oauth",+ "native-oauth-mobile"]}},@@ -59,6 +60,27 @@"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDg4QUQ2RTkxNENEOTZGRDEKUldUUmI5bE1rVzZ0aUY5SGgxVmRjZkUxeTNUKzlpZC8rQXQ3R0xDTFBsUFV4Kzc0U3pXc3hRV1MK"},"deep-link": {+ "mobile": [+ {+ "scheme": [+ "https"+ ],+ "host": "auth.alook.ai",+ "path": [+ "/auth/native/return"+ ]+ },+ {+ "scheme": [+ "ai.alook"+ ],+ "host": "auth",+ "path": [+ "/native/return"+ ],+ "appLink": false+ }+ ],"desktop": {"schemes": ["ai.alook.desktop"diff --git a/src/desktop/src-tauri/tauri.dev.conf.json b/src/desktop/src-tauri/tauri.dev.conf.jsonindex 5e2974493..6fd00aeb0 100644--- a/src/desktop/src-tauri/tauri.dev.conf.json+++ b/src/desktop/src-tauri/tauri.dev.conf.json@@ -15,7 +15,9 @@"platforms": ["linux","macOS",- "windows"+ "windows",+ "android",+ "iOS"],"local": true,"remote": {diff --git a/src/desktop/src-tauri/tauri.ios.conf.json b/src/desktop/src-tauri/tauri.ios.conf.jsonindex 3a07c2bb3..5f6f1b349 100644--- a/src/desktop/src-tauri/tauri.ios.conf.json+++ b/src/desktop/src-tauri/tauri.ios.conf.json@@ -1,4 +1,9 @@{"$schema": "./gen/schemas/ios-schema.json",- "identifier": "ai.alook.ios"+ "identifier": "ai.alook.ios",+ "bundle": {+ "iOS": {+ "developmentTeam": "5RF24VHDQB"+ }+ }}