Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat(cloud): return connector sign-ins to the app

leepokaif0e366a4760f
diff --git a/cloud/src/api.ts b/cloud/src/api.ts
index 64eb6a57..9c31e944 100644
--- a/cloud/src/api.ts
+++ b/cloud/src/api.ts
@@ -273,6 +273,14 @@ export const claimCanonical = (claimId: string, nonce: string, userId: string, c
export const health = async () => ({ ok: true, version: VERSION });
+/**
+ * Where a connector's sign-in page returns when the user signed in on the phone. Stateless: it bounces
+ * the query (code, state or error) to the app, which hands it to the host over the E2E channel. The code
+ * is useless without the PKCE verifier that only the host holds.
+ */
+export const oauthCallback = async (c: Ctx) =>
+ new Response(null, { status: 302, headers: { Location: `codync://oauth${c.url.search}`, "Cache-Control": "no-store" } });
+
// ---- Clerk (users) ----
export async function me(c: Ctx) {
diff --git a/cloud/src/index.ts b/cloud/src/index.ts
index 55ab44af..7eaaace0 100644
--- a/cloud/src/index.ts
+++ b/cloud/src/index.ts
@@ -26,6 +26,7 @@ type Handler = (c: Ctx, params: string[]) => Promise<unknown>;
const ID = "([A-Za-z0-9_-]{1,64})";
const routes: [string, RegExp, Handler][] = [
["GET", /^\/v1\/health$/, api.health],
+ ["GET", /^\/v1\/oauth\/callback$/, api.oauthCallback],
["GET", /^\/v1\/me$/, api.me],
["POST", /^\/v1\/devices$/, api.registerDevice],
["GET", /^\/v1\/devices$/, api.listDevices],
diff --git a/cloud/test/api.test.ts b/cloud/test/api.test.ts
index 211c504c..bbcff6bd 100644
--- a/cloud/test/api.test.ts
+++ b/cloud/test/api.test.ts
@@ -1,11 +1,12 @@
// /v1 HTTP API: auth, claims, access requests, grants, webhooks, cron.
-import { createScheduledController } from "cloudflare:test";
+import { createScheduledController, SELF } from "cloudflare:test";
import { Webhook } from "svix";
import { describe, expect, it } from "vitest";
import worker from "../src/index";
import {
AUTHORITY,
+ ORIGIN,
call,
clerkToken,
devicePath,
@@ -83,6 +84,12 @@ async function grantAccess(user: User, host: TestHost) {
}
describe("basics", () => {
+ it("bounces a connector sign-in to the app", async () => {
+ const res = await SELF.fetch(`${ORIGIN}/v1/oauth/callback?code=abc&state=xyz`, { redirect: "manual" });
+ expect(res.status).toBe(302);
+ expect(res.headers.get("Location")).toBe("codync://oauth?code=abc&state=xyz");
+ });
+
it("health", async () => {
expect(await call("GET", "/v1/health")).toEqual({ status: 200, body: { ok: true, version: "2.2.0" } });
});