This Cloudflare Worker provides Google Drive API operations with OAuth 2.0 user authentication.
/auth/google to start OAuth flow
X-Session-ID header for API calls
GOOGLE_CLIENT_ID - Your OAuth client IDGOOGLE_CLIENT_SECRET - Your OAuth client secretGOOGLE_REDIRECT_URI - https://your-worker.workers.dev/auth/callbackUSER_SESSIONS and bind it to your workerStart OAuth 2.0 authentication flow - redirects to Google's consent screen
Query Parameters: ?state=optional_state (for security)
https://your-worker.workers.dev/auth/google
OAuth callback endpoint - handles the response from Google (don't call directly)
Returns HTML page with session ID on success
Check authentication status and token validity
Headers: X-Session-ID: your_session_id
curl -H "X-Session-ID: your_session_id_here" \
https://your-worker.workers.dev/auth/status
{
"authenticated": true,
"user": {
"id": "123456789",
"email": "user@example.com",
"name": "John Doe",
"picture": "https://..."
},
"expires_at": 1640995200000,
"needs_refresh": false
}
Manually refresh expired access token
Headers: X-Session-ID: your_session_id
curl -X POST -H "X-Session-ID: your_session_id_here" \
https://your-worker.workers.dev/auth/refresh
Authentication: All endpoints require X-Session-ID header with a valid session ID
Create a new folder in Google Drive
Headers: X-Session-ID: your_session_id (required)
Request Body: {"name": "My Folder", "parentId": "optional_parent_folder_id"}
curl -X POST https://your-worker.workers.dev/create-folder \
-H "Content-Type: application/json" \
-H "X-Session-ID: your_session_id_here" \
-d '{"name": "My New Folder"}'
Upload a file to Google Drive
Headers: X-Session-ID: your_session_id (required)
Form Data Fields:
file: File to upload (optional if textContent provided)textContent: Text content to upload as file (optional if file provided)fileName: Name for the filefolderId: Target folder ID (optional)curl -X POST https://your-worker.workers.dev/upload-file \
-H "X-Session-ID: your_session_id_here" \
-F "file=@/path/to/your/document.pdf" \
-F "fileName=my-document.pdf"
List files in Google Drive
Headers: X-Session-ID: your_session_id (required)
Query Parameters: ?folderId=folder_id (optional)
curl -H "X-Session-ID: your_session_id_here" \
https://your-worker.workers.dev/list-files
List only folders in Google Drive (excludes files)
Headers: X-Session-ID: your_session_id (required)
Query Parameters: ?parentId=folder_id (optional)
curl -H "X-Session-ID: your_session_id_here" \
https://your-worker.workers.dev/list-folders
Share a folder with specific users
Headers: X-Session-ID: your_session_id (required)
Request Body: {"folderId": "folder_id", "emails": ["user@example.com"], "role": "writer"}
Available roles: reader, writer, commenter
curl -X POST https://your-worker.workers.dev/share-folder \
-H "Content-Type: application/json" \
-H "X-Session-ID: your_session_id_here" \
-d '{
"folderId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
"emails": ["colleague@company.com"],
"role": "writer"
}'
/auth/google in browser/auth/googleX-Session-ID header for API callsAll endpoints return JSON responses:
{
"success": true,
"data": { ... },
// or on error:
"error": "Error message"
}
X-Session-ID header2. Copy your session ID
3. Start making API calls with your session ID!