Skip to content

Fall back to Drive export when Docs API returns 403 (Shared Drive / Workspace policy fix)#93

Merged
a-bonus merged 1 commit intoa-bonus:mainfrom
andrie:fix/shared-drive-403-fallback
Mar 23, 2026
Merged

Fall back to Drive export when Docs API returns 403 (Shared Drive / Workspace policy fix)#93
a-bonus merged 1 commit intoa-bonus:mainfrom
andrie:fix/shared-drive-403-fallback

Conversation

@andrie
Copy link
Copy Markdown
Contributor

@andrie andrie commented Mar 23, 2026

Problem

In some Google Workspace organisations, admins restrict third-party OAuth app access to the Google Docs API while still allowing the Drive API. This causes readDocument to return Permission denied (HTTP 403) even for documents the authenticated user owns in a Shared Drive.

The Drive API already handles Shared Drive access correctly throughout this codebase (supportsAllDrives: true is set on all Drive API calls). The Docs API does not have an equivalent parameter, and cannot be used in these environments.

Fix

When docs.documents.get() returns 403 and the requested format is text, fall back to drive.files.export() with mimeType: 'text/plain'. This uses the Drive API instead and works in restricted Workspace environments.

markdown and json formats still throw, since they require the full document structure from the Docs API.

Changes

  • src/tools/docs/readGoogleDoc.ts: import getDriveClient, add 403 fallback to drive.files.export()

Testing

Verified manually against a Shared Drive document in a Workspace org where the Docs API is restricted:

  • Before: Permission denied for doc (ID: ...)
  • After: document content returned successfully via Drive export fallback

Fixes #92, relates to #33

Some Google Workspace admins restrict third-party access to the Docs
API while allowing the Drive API. In that case, docs.documents.get()
returns 403 even for documents the user owns in a Shared Drive.

When readDocument receives a 403 and the requested format is 'text',
fall back to drive.files.export() with mimeType 'text/plain'. The
Drive API is more permissive in enterprise environments and already
handles Shared Drive access correctly elsewhere in the codebase.

Fixes a-bonus#92, relates to a-bonus#33
@a-bonus a-bonus merged commit bd5b21d into a-bonus:main Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readDocument returns 403 for Shared Drive documents when Google Docs API is restricted by Workspace policy

2 participants