Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(oauth): add README and test files for OAuth module

Steven Enamakel21c03c65fb19
diff --git a/crates/openhuman-tinyhumans/src/hosted/oauth/README.md b/crates/openhuman-tinyhumans/src/hosted/oauth/README.md
new file mode 100644
index 0000000000..c6a334b78e
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/oauth/README.md
@@ -0,0 +1,22 @@
+# oauth (hosted)
+
+Backend-brokered OAuth integrations on the TinyHumans SDK's typed `auth()`
+client. Stateless RPC adapter; the backend runs the OAuth dance and stores
+the provider tokens.
+
+| Method | Inputs | Backend call |
+| --- | --- | --- |
+| `auth_oauth_connect` | `provider`, `skillId?`, `responseType?`, `encryptionMode?` | `GET /auth/{provider}/connect` |
+| `auth_oauth_list_integrations` | none | `GET /auth/integrations` |
+| `auth_oauth_fetch_integration_tokens` | `integrationId`, `key` | `POST /auth/integrations/{id}/tokens` (AES-GCM handoff, decrypted with the core's `api::decrypt_handoff_blob`) |
+| `auth_oauth_revoke_integration` | `integrationId` | `DELETE /auth/integrations/{id}` |
+
+These share the `auth` namespace with the core's credential controllers
+(`auth.set_credential`, `auth.get_state`, provider credentials, …), which stay
+in the core. `auth_oauth_fetch_client_key` also stays in the core: its route
+(`POST /auth/integrations/{id}/client-key`) has no SDK method and is missing
+from the SDK's public-route registry.
+
+The core's `oauth_connect_url` / `oauth_list` agent tools reach these through
+the controller registry, so they report `BACKEND_UNAVAILABLE:` on a core
+without `openhuman_tinyhumans::install`.
diff --git a/crates/openhuman-tinyhumans/src/hosted/oauth/ops_tests.rs b/crates/openhuman-tinyhumans/src/hosted/oauth/ops_tests.rs
new file mode 100644
index 0000000000..533f0fb8bb
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/oauth/ops_tests.rs
@@ -0,0 +1,144 @@
+use super::*;
+use crate::hosted::test_support;
+use tempfile::TempDir;
+use wiremock::matchers::{body_json, method, path, query_param};
+use wiremock::{Mock, MockServer, ResponseTemplate};
+
+const ID: &str = "0123456789abcdef01234567";
+
+fn ok(data: Value) -> ResponseTemplate {
+ ResponseTemplate::new(200).set_body_json(json!({"success": true, "data": data}))
+}
+
+#[tokio::test]
+async fn validation_runs_before_the_credential() {
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::config(&tmp, "http://127.0.0.1:9");
+ assert_eq!(
+ oauth_connect(&config, " / ", None, None, None)
+ .await
+ .unwrap_err(),
+ "provider is required"
+ );
+ assert_eq!(
+ oauth_fetch_integration_tokens(&config, "short", "k")
+ .await
+ .unwrap_err(),
+ "integrationId must be a 24-char hex id"
+ );
+ assert_eq!(
+ oauth_revoke_integration(&config, " ").await.unwrap_err(),
+ "integration id is required"
+ );
+ assert!(oauth_list_integrations(&config)
+ .await
+ .unwrap_err()
+ .contains("no backend session token"));
+}
+
+#[tokio::test]
+async fn local_session_is_backend_unavailable() {
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::local_session(&tmp);
+ let err = oauth_connect(&config, "github", None, None, None)
+ .await
+ .unwrap_err();
+ assert!(err.starts_with("BACKEND_UNAVAILABLE:"), "{err}");
+}
+
+#[tokio::test]
+async fn connect_forwards_non_empty_query_and_shapes_the_result() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/auth/github/connect"))
+ .and(query_param("skillId", "s1"))
+ .and(query_param("encryptionMode", "encrypted"))
+ .respond_with(ok(json!({"oauthUrl": "https://gh/authorize", "state": "st"})))
+ .expect(1)
+ .mount(&server)
+ .await;
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::signed_in(&tmp, &server.uri());
+ let out = oauth_connect(&config, "/github/", Some("s1"), Some(""), Some("encrypted"))
+ .await
+ .unwrap();
+ assert_eq!(
+ out.value,
+ json!({"oauthUrl": "https://gh/authorize", "state": "st"})
+ );
+}
+
+#[tokio::test]
+async fn connect_rejects_a_response_without_url_or_state() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/auth/notion/connect"))
+ .respond_with(ok(json!({"oauthUrl": "https://n"})))
+ .mount(&server)
+ .await;
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::signed_in(&tmp, &server.uri());
+ let err = oauth_connect(&config, "notion", None, None, None)
+ .await
+ .unwrap_err();
+ assert!(err.contains("missing state"), "{err}");
+}
+
+#[tokio::test]
+async fn list_revoke_and_token_handoff_round_trip() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/auth/integrations"))
+ .respond_with(ok(json!({"integrations": [
+ {"id": ID, "provider": "google", "createdAt": "2026-01-01T00:00:00Z", "extra": 1}
+ ]})))
+ .expect(1)
+ .mount(&server)
+ .await;
+ Mock::given(method("DELETE"))
+ .and(path(format!("/auth/integrations/{ID}")))
+ .respond_with(ok(json!({})))
+ .expect(1)
+ .mount(&server)
+ .await;
+ Mock::given(method("POST"))
+ .and(path(format!("/auth/integrations/{ID}/tokens")))
+ .and(body_json(json!({"key": "enc-key"})))
+ .respond_with(ok(json!({"encrypted": "not-base64!"})))
+ .expect(1)
+ .mount(&server)
+ .await;
+
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::signed_in(&tmp, &server.uri());
+
+ let out = oauth_list_integrations(&config).await.unwrap();
+ assert_eq!(
+ out.value,
+ json!([{"id": ID, "provider": "google", "createdAt": "2026-01-01T00:00:00Z"}])
+ );
+
+ let out = oauth_revoke_integration(&config, ID).await.unwrap();
+ assert_eq!(out.value, json!({"revoked": true, "integrationId": ID}));
+
+ let err = oauth_fetch_integration_tokens(&config, ID, " enc-key ")
+ .await
+ .unwrap_err();
+ assert!(err.starts_with("integration tokens handoff:"), "{err}");
+}
+
+#[tokio::test]
+async fn token_handoff_without_encrypted_payload_errors() {
+ let server = MockServer::start().await;
+ Mock::given(method("POST"))
+ .and(path(format!("/auth/integrations/{ID}/tokens")))
+ .respond_with(ok(json!({})))
+ .mount(&server)
+ .await;
+ let tmp = TempDir::new().unwrap();
+ let config = test_support::signed_in(&tmp, &server.uri());
+ let err = oauth_fetch_integration_tokens(&config, ID, "k")
+ .await
+ .unwrap_err();
+ assert_eq!(err, "integration tokens response missing encrypted payload");
+}
diff --git a/crates/openhuman-tinyhumans/src/hosted/oauth/schemas_tests.rs b/crates/openhuman-tinyhumans/src/hosted/oauth/schemas_tests.rs
new file mode 100644
index 0000000000..1af20eeff5
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/oauth/schemas_tests.rs
@@ -0,0 +1,43 @@
+use super::*;
+
+#[test]
+fn catalog_keeps_the_auth_oauth_wire_names() {
+ let names: Vec<String> = all_oauth_controller_schemas()
+ .iter()
+ .map(|s| format!("{}.{}", s.namespace, s.function))
+ .collect();
+ assert_eq!(
+ names,
+ vec![
+ "auth.oauth_connect",
+ "auth.oauth_list_integrations",
+ "auth.oauth_fetch_integration_tokens",
+ "auth.oauth_revoke_integration",
+ ]
+ );
+ assert_eq!(all_oauth_registered_controllers().len(), FUNCTIONS.len());
+}
+
+#[test]
+fn connect_requires_provider_and_tokens_require_id_and_key() {
+ let connect = oauth_schemas("auth_oauth_connect");
+ let required: Vec<_> = connect.inputs.iter().filter(|f| f.required).map(|f| f.name).collect();
+ assert_eq!(required, vec!["provider"]);
+ let tokens = oauth_schemas("auth_oauth_fetch_integration_tokens");
+ let required: Vec<_> = tokens.inputs.iter().filter(|f| f.required).map(|f| f.name).collect();
+ assert_eq!(required, vec!["integrationId", "key"]);
+ assert_eq!(oauth_schemas("nope").function, "unknown");
+}
+
+#[test]
+fn params_are_camel_case() {
+ let params: AuthOauthConnectParams = deserialize_params(
+ serde_json::json!({"provider": "github", "skillId": "s"})
+ .as_object()
+ .unwrap()
+ .clone(),
+ )
+ .unwrap();
+ assert_eq!(params.skill_id.as_deref(), Some("s"));
+ assert!(deserialize_params::<AuthOauthRevokeParams>(Map::new()).is_err());
+}