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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix: a connector sign-in only lands on the server it started for
leepokai653e42d2850d
diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/ConnectionRequestCard.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/ConnectionRequestCard.swiftindex 914da83b..d55a2aa2 100644--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/ConnectionRequestCard.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/ConnectionRequestCard.swift@@ -6,7 +6,7 @@ struct ConnectionRequestCard: View {let entry: Entrylet request: ConnectionRequest@Environment(BotStore.self) private var model- private var signInFlow = ConnectorSignInFlow()+ private let signInFlow = ConnectorSignInFlow()@State private var app: ComposioApp?@State private var item: MarketConnector?@State private var agent: Backend?diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swiftindex 8fd01a83..2898bbee 100644--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swift@@ -6,7 +6,7 @@ struct CustomConnectorSheet: View {@Environment(BotStore.self) private var model@Environment(\.dismissModal) private var dismiss- private var signInFlow = ConnectorSignInFlow()+ private let signInFlow = ConnectorSignInFlow()@State private var name = ""@State private var mode = Mode.command@State private var target = ""diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swiftindex aabce3c5..879f0559 100644--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swift@@ -10,7 +10,7 @@ struct InstallConnectorSheet: View {let done: () -> Void@Environment(BotStore.self) private var model@Environment(\.dismissModal) private var dismiss- private var signInFlow = ConnectorSignInFlow()+ private let signInFlow = ConnectorSignInFlow()@State private var optionId = ""@State private var values: [String: String] = [:]@State private var installed: InstalledConnector?diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swiftindex 0e454f92..9336a671 100644--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swift@@ -4,7 +4,7 @@ import SwiftUIstruct InstalledView: View {let back: () -> Void@Environment(BotStore.self) private var model- private var signInFlow = ConnectorSignInFlow()+ private let signInFlow = ConnectorSignInFlow()@State private var removing: Removal?@State private var signingIn: String?@State private var viewingSkill: SkillRef?diff --git a/docs/features/marketplace.md b/docs/features/marketplace.mdindex e4b4e974..d35451dd 100644--- a/docs/features/marketplace.md+++ b/docs/features/marketplace.md@@ -93,9 +93,9 @@ Installing a remote connector probes it: a 401 to `initialize`, or (with no head| On the phone (E2E channel caller) | `<cloud>/v1/oauth/callback` → 302 `codync://oauth?…` | the app's system sign-in sheet sends `connectorSignInFinish` || Anywhere, with a code (GitHub) | none | the host polls the token endpoint |-The cloud page is stateless and the code is useless without the PKCE verifier held by the host.+The cloud page is stateless and the code is useless without the PKCE verifier held by the host. The host trades it only if the connector still has the URL the sign-in started for.-GitHub has no dynamic client registration, so it signs in through Codync's own OAuth App (the "Codync" app on leepokai's account that Clerk's GitHub sign-in also uses; Device Flow enabled; client id in `oauth/device.rs`) with the device flow (RFC 8628). The app is used only for a connector whose URL starts with its `resource` and whose metadata names its issuer, and asks for its own fixed scopes, never the server's: any server can name GitHub as its issuer, and the token goes to the connector's URL. `connectorSignIn {id, showsCode: true}` answers `{url, callback: "host", code}`. The iPhone, Android and desktop apps show the code in a dialog whose **Copy and open** copies it and opens GitHub's page (GitHub can't prefill it), then wait for the connector to read signed in, as with the loopback page; its Cancel ends the sign-in quietly, and an Add or a connection request started from it stops there too. The terminal UI has no dialog: it copies the code, opens the page and keeps the code in its hint (Extensions) or note (connection request), with the page's address when no browser opened. The host polls in the background until the code is entered, refused or expired (15 minutes). The token doesn't expire and has no refresh token, so a 401 signs the connector out. A client that doesn't send `showsCode` gets "Update Codync on this device to sign in to GitHub." A GitHub connector set up with a token header before this (no `oauth`; its URL starts with the app's `resource`) lists `canSignIn: true`: the installed list says *Sign in instead of using a saved token* beside a Sign in button (terminal UI: `↵ sign in instead of the token`). Its token keeps working until the device sign-in lands; then the host stores the sign-in and drops the `Authorization` header (`device::signed_in`), so clients wait for `auth: "signedIn"`, not merely not signed out. An organization that restricts OAuth Apps hides its repositories from the new token until an owner approves Codync; the user manual says so, since the old token is gone by then. Other servers without dynamic client registration need a token header instead (custom connector, URL + headers). `connectorTarget` (loopback only) hands the proxy the URL and headers.+GitHub has no dynamic client registration, so it signs in through Codync's own OAuth App (the "Codync" app on leepokai's account that Clerk's GitHub sign-in also uses; Device Flow enabled; client id in `oauth/device.rs`) with the device flow (RFC 8628). The app is used only for a connector whose URL starts with its `resource` and whose metadata names its issuer, and asks for its own fixed scopes, never the server's: any server can name GitHub as its issuer, and the token goes to the connector's URL. `connectorSignIn {id, showsCode: true}` answers `{url, callback: "host", code}`. The iPhone, Android and desktop apps show the code in a dialog whose **Copy and open** copies it and opens GitHub's page (GitHub can't prefill it), then wait for the connector to read signed in, as with the loopback page; its Cancel ends the sign-in quietly, and an Add or a connection request started from it stops there too. The terminal UI has no dialog: it copies the code, opens the page and keeps the code in its hint (Extensions) or note (connection request), with the page's address when no browser opened. The host polls in the background until the code is entered, refused or expired (15 minutes), and saves the token only if the connector still has the URL the sign-in started for (it can be removed and another added under its id meanwhile). The token doesn't expire and has no refresh token, so a 401 signs the connector out. A client that doesn't send `showsCode` gets "Update Codync on this device to sign in to GitHub." A GitHub connector set up with a token header before this (no `oauth`; its URL starts with the app's `resource`) lists `canSignIn: true`: the installed list says *Sign in instead of using a saved token* beside a Sign in button (terminal UI: `↵ sign in instead of the token`). Its token keeps working until the device sign-in lands; then the host stores the sign-in and drops the `Authorization` header (`device::signed_in`), so clients wait for `auth: "signedIn"`, not merely not signed out. An organization that restricts OAuth Apps hides its repositories from the new token until an owner approves Codync; the user manual says so, since the old token is gone by then. Other servers without dynamic client registration need a token header instead (custom connector, URL + headers). `connectorTarget` (loopback only) hands the proxy the URL and headers.Registry packages install only at the exact version the MCP Registry lists (no `latest`), since they run as the user. An enabled skill tells the bot where its instruction folder lives. These are distinct from the built-in `team` and `computer` MCP services.diff --git a/host/src/market/oauth.rs b/host/src/market/oauth.rsindex 780bb440..59c2bb91 100644--- a/host/src/market/oauth.rs+++ b/host/src/market/oauth.rs@@ -224,7 +224,8 @@ pub async fn finish(store: &Store, state: &str, code: Option<&str>, error: Optiolet code = code.ok_or_else(|| anyhow!("Sign-in didn't return a code"))?;let c = market::connectors(store)?.into_iter()- .find(|c| c.id == p.connector)+ // Still the server the sign-in started for: it can be removed and another added under its id meanwhile.+ .find(|c| c.id == p.connector && c.url.as_deref() == Some(p.resource.as_str())).ok_or_else(|| anyhow!("unknown connector"))?;let oauth = c.oauth.ok_or_else(|| anyhow!("unknown connector"))?;let v = token_request(@@ -365,4 +366,27 @@ mod tests {let err = rt.block_on(finish(&store, "nope", Some("code"), None)).unwrap_err();assert!(err.to_string().contains("expired"));}++ #[test]+ fn a_connector_replaced_during_sign_in_gets_no_code() {+ let store = Store::open(std::path::Path::new(":memory:")).unwrap();+ // Removed while the sign-in page was open, and another server added under the same id.+ let c: Connector = serde_json::from_value(json!({+ "id": "notes", "name": "Notes", "url": "https://other.example/mcp",+ "oauth": {"clientId": "theirs", "tokenEndpoint": "http://127.0.0.1:1/token"},+ }))+ .unwrap();+ market::save_connectors(&store, &[c]).unwrap();+ let pending = Pending {+ connector: "notes".into(),+ verifier: "v".into(),+ redirect_uri: loopback_uri(1),+ resource: "https://notes.example/mcp".into(),+ started: Instant::now(),+ };+ PENDING.locked().get_or_insert_with(HashMap::new).insert("replaced".into(), pending);+ let rt = tokio::runtime::Builder::new_current_thread().build().unwrap();+ let err = rt.block_on(finish(&store, "replaced", Some("code"), None)).unwrap_err();+ assert_eq!(err.to_string(), "unknown connector");+ }}diff --git a/host/src/market/oauth/device.rs b/host/src/market/oauth/device.rsindex 0d6ceff0..1f4761d8 100644--- a/host/src/market/oauth/device.rs+++ b/host/src/market/oauth/device.rs@@ -77,10 +77,18 @@ pub(super) async fn start(let oauth = OAuth { client_id: app.client_id.to_owned(), token_endpoint, ..OAuth::default() };let interval = v["interval"].as_u64().unwrap_or(5);let lasts = Duration::from_secs(v["expires_in"].as_u64().unwrap_or(900));- tokio::spawn(poll(hub.clone(), c.id.clone(), oauth, device_code, interval, lasts));+ let target = Target { id: c.id.clone(), url: c.url.clone() };+ tokio::spawn(poll(hub.clone(), target, oauth, device_code, interval, lasts));Ok(json!({"url": page, "callback": "host", "code": code}))}+/// The connector a sign-in is for. The URL too: while GitHub waits for the code, that connector+/// can be removed and another one added under its id, and the token goes only where it was asked for.+struct Target {+ id: String,+ url: Option<String>,+}+/// What one answer from the token endpoint means.#[derive(Debug, PartialEq)]enum Step {@@ -103,7 +111,8 @@ fn step(v: &Value, interval: u64) -> Step {}}-async fn poll(hub: Arc<Hub>, id: String, oauth: OAuth, device_code: String, mut interval: u64, lasts: Duration) {+async fn poll(hub: Arc<Hub>, target: Target, oauth: OAuth, device_code: String, mut interval: u64, lasts: Duration) {+ let id = &target.id;let until = Instant::now() + lasts;while Instant::now() < until {tokio::time::sleep(Duration::from_secs(interval)).await;@@ -117,8 +126,15 @@ async fn poll(hub: Arc<Hub>, id: String, oauth: OAuth, device_code: String, mut};match step(&v, interval) {Step::Done => {- if let Err(error) = update(&hub.store, &id, |c| signed_in(c, &oauth, &v)) {- tracing::warn!(connector = %id, error = format!("{error:#}"), "couldn't save the sign-in");+ let mut saved = false;+ match update(&hub.store, id, |c| saved = signed_in(c, &target, &oauth, &v)) {+ Err(error) => {+ tracing::warn!(connector = %id, error = format!("{error:#}"), "couldn't save the sign-in");+ }+ Ok(_) if !saved => {+ tracing::warn!(connector = %id, "connector changed during sign-in; token dropped");+ }+ Ok(_) => {}}return;}@@ -132,10 +148,15 @@ async fn poll(hub: Arc<Hub>, id: String, oauth: OAuth, device_code: String, mut}/// Keeps the token, and drops the token header the connector was set up with before it could sign in.-fn signed_in(c: &mut Connector, app: &OAuth, v: &Value) {+/// `false`, with nothing changed, when the connector no longer points where the sign-in started.+fn signed_in(c: &mut Connector, target: &Target, app: &OAuth, v: &Value) -> bool {+ if c.url != target.url {+ return false;+ }c.oauth = Some(app.clone());store_tokens(c, v);c.headers.retain(|k, _| !k.eq_ignore_ascii_case("authorization"));+ true}#[cfg(test)]@@ -151,12 +172,27 @@ mod tests {.unwrap();assert!(offers_sign_in(c.url.as_deref().unwrap()));let app = OAuth { client_id: "id".into(), token_endpoint: "https://github.com/t".into(), ..OAuth::default() };- signed_in(&mut c, &app, &json!({"access_token": "gho_new"}));+ let target = Target { id: c.id.clone(), url: c.url.clone() };+ assert!(signed_in(&mut c, &target, &app, &json!({"access_token": "gho_new"})));let o = c.oauth.unwrap();assert_eq!((o.client_id.as_str(), o.access_token.as_str()), ("id", "gho_new"));assert_eq!(c.headers.keys().collect::<Vec<_>>(), ["X-MCP-Toolsets"]);}+ #[test]+ fn a_connector_replaced_during_sign_in_gets_no_token() {+ let target = Target { id: "github".into(), url: Some("https://api.githubcopilot.com/mcp/".into()) };+ // Removed while GitHub waited for the code, and another server added under the same id.+ let mut c: Connector = serde_json::from_value(json!({+ "id": "github", "name": "GitHub", "url": "https://evil.example/mcp",+ "headers": {"Authorization": "Bearer theirs"},+ }))+ .unwrap();+ assert!(!signed_in(&mut c, &target, &OAuth::default(), &json!({"access_token": "gho_new"})));+ assert!(c.oauth.is_none());+ assert_eq!(c.headers.keys().collect::<Vec<_>>(), ["Authorization"]);+ }+#[test]fn only_github_s_own_server_gets_codync_s_github_app() {let github = "https://github.com/login/oauth";