Google Drive Integration
Status note (2026-11-18). This page previously described a Postgres/Valkey-era Drive storage provider (
/api/drive-storage/*, a cloud Drive sync worker, a Changes-API poller, and/api/drive/files*file operations). None of those routes or workers exist in the current code, so they were removed. The page now covers only what is implemented today.
What exists today
| Capability | Where it lives |
|---|---|
| Drive scope upgrade for a signed-in Google user | GET /api/auth/oauth/google/drive and /callback, handled by the accounts worker (auth.studiobrain.ai) and forwarded by api.studiobrain.ai |
| Storage-provider OAuth tokens (Dropbox, OneDrive, Google Drive) | Accounts worker, /internal/storage-oauth/{provider}/exchange (service-secret gated, service-to-service) |
| Drive folder picker | GET / POST /api/drive/folders in core sb-server (requires the gdrive Cargo feature) |
| Export an entity to Google Drive | POST /api/entities/:id/export/gdrive in core sb-server (requires the gdrive feature and ENABLE_GDRIVE_EXPORT=true) |
| Drive token status | GET /api/oauth/drive/status (in the core edition this is a stub that always reports no token; the cloud extension supplies the real answer) |
Authentication
Account sign-in with Google requests identity scopes only (openid email profile).
Drive access is a separate, authenticated scope upgrade:
- A signed-in user starts
GET /api/auth/oauth/google/drive. - Google redirects back to
/api/auth/oauth/google/drive/callback. - The accounts worker stores the resulting tokens encrypted. Tokens are never returned in API responses.
The accounts worker’s storage-OAuth service requests the Google scope
https://www.googleapis.com/auth/drive for the gdrive storage provider. Its
browser connect routes (/api/auth/storage-oauth/:provider) support Dropbox and
OneDrive only; the Google Drive connect flow is the scope upgrade above.
OAuth token handling belongs to the accounts/identity lane. Cloud and client frontends do not store or edit Drive credentials.
Folder picker
GET /api/drive/folders lists folders on the user’s Drive for the picker, and
POST /api/drive/folders creates one. On api.studiobrain.ai this route is not
yet served by the Worker (the router keeps its own 404 until its backing storage
exists), so the picker is available where core sb-server runs with the
gdrive feature (self-hosted and desktop).
Exporting an entity
POST /api/entities/:id/export/gdrive exports an entity to Google Drive. It is
disabled unless the gdrive feature is compiled in and ENABLE_GDRIVE_EXPORT=true
is set at runtime.
Not available
These were documented previously and are not implemented in the current code:
- Drive as a continuous sync/storage backend for a project (the SaaS content index is the per-project ProjectStore Durable Object plus R2).
/api/drive-storage/*(status, select-folder, disconnect, test, register-desktop-tokens, cloud-sync-status, force-sync)./api/drive/status,/api/drive/files*,/api/drive/export-entity.- Valkey-held OAuth state. OAuth state is a signed state token.
Desktop BYO bucket sync (S3, Google Drive, Dropbox, OneDrive via OpenDAL) is a
separate, feature-flagged path; see the sync design plan
docs/plans/SBAI-8040-continuous-sync-design.md.
Troubleshooting
- OAuth authorization fails: confirm the Google OAuth client ID and secret are
configured on the accounts worker and the redirect URI matches
{OAUTH_REDIRECT_BASE}/api/auth/oauth/google/drive/callback. - Drive scope missing: rerun
GET /api/auth/oauth/google/driveto grant Drive access. - Provider not configured (503): the storage-OAuth service returns 503 when the provider’s client ID and secret are not set.
Related Documentation
- Cloud Sync - Overview of sync features
- Self-Hosting - Drive integration on self-hosted
- Google Drive API Docs - Official Google Drive API