The CLI supports multiple authentication methods and scope presets. OAuth uses Authorization Code + PKCE for installed/desktop apps (public client). The default client is ID-only (no embedded secret).
Credentials are resolved in this order:
- CLI flags (
--client-id,--client-secret) - Environment variables (
GDRV_CLIENT_ID,GDRV_CLIENT_SECRET) - Config file (
oauthClientId,oauthClientSecret) - Default public OAuth client (embedded ID, no secret)
No partial overrides: if any OAuth client variable is set, all required OAuth client fields must be set (client ID always; secret only if your client type requires it).
Config file path (defaults):
- macOS:
~/Library/Application Support/gdrv/config.json - Linux:
~/.config/gdrv/config.json - Windows:
%APPDATA%\\gdrv\\config.json - Override with
GDRV_CONFIG_DIR
Contributor/CI policy: set GDRV_REQUIRE_CUSTOM_OAUTH=1 to refuse default credentials.
Default public client IDs may rotate between releases. If you see invalid_client errors with the default client, upgrade or configure a custom client.
- The default public client is ID-only; any secret provided is treated as public (PKCE is used).
- The shared client is hosted in a dedicated Google Cloud project with quota monitoring and a rotation plan.
- If the shared client is disabled or rotated, the CLI will instruct you to upgrade or configure a custom client.
- Preferred: system keyring (Keychain / Secret Service / Credential Manager).
- Fallback: encrypted file storage at
.../credentials/<profile>.encwith0600permissions and a local key file at.../.keyfile. - Plain file storage is development-only and must be explicitly forced.
gdrv auth logoutremoves local credentials only (does not revoke remote consent).
When using gdrv on remote servers or headless environments, use one of these methods:
Best for interactive SSH sessions where you can access a browser on your local machine.
gdrv auth device- Run the command on the remote server
- Visit google.com/device on your local machine
- Enter the code displayed in your SSH session
- No browser needed on the remote server
Ideal for CI/CD, scripts, and automated workflows.
gdrv auth service-account --key-file /path/to/service-account.json- Non-interactive, works headlessly
- Copy the JSON key to the remote machine first
- No browser or manual steps required
When you need OAuth but can't use device flow.
# Option A: Use the --no-browser flag
gdrv auth login --no-browser
# Option B: Set the environment variable
GDRV_NO_BROWSER=1 gdrv auth login- Run the command on the remote server
- Shows a URL - open it in your local browser
- Complete the OAuth flow locally
- Copy the authorization code from the browser
- Paste it back into your SSH session
Authenticate on your local machine, then securely copy credentials to the remote server.
On your local machine:
gdrv auth login
scp ~/.config/gdrv/credentials/* remote:~/.config/gdrv/credentials/For custom OAuth clients, set credentials via environment:
export GDRV_CLIENT_ID="your-client-id"
export GDRV_CLIENT_SECRET="your-client-secret"
gdrv auth loginNote: Credentials are resolved in this order: CLI flags → Environment variables → Config file → Default client.
Default Scope Preset: workspace-full (full read/write access) is the default when no preset is specified. Use --preset workspace-basic for read-only access.
| Preset | Description | Use Case |
|---|---|---|
workspace-basic |
Read-only Drive, Sheets, Docs, Slides, Labels | Viewing and downloading |
workspace-full |
Full Drive, Sheets, Docs, Slides, Labels | Editing and management |
admin |
Admin Directory users and groups, Admin Labels | User/group/label administration |
workspace-with-admin |
Workspace full + Admin Directory + Admin Labels | Full workspace + admin |
workspace-activity |
Workspace basic + Activity API | Read-only with activity auditing |
workspace-labels |
Workspace full + Labels API | Full access with label management |
workspace-sync |
Workspace full + Changes API | Full access with change tracking |
workspace-complete |
All Workspace APIs + Activity + Labels + Changes | Complete API access |
Use workspace-basic for least-privilege read-only access; use workspace-full only when write access is required. Use the specialized presets (workspace-activity, workspace-labels, workspace-sync, workspace-complete) when you need the advanced APIs.
# Basic presets
gdrv auth login --preset workspace-basic
gdrv auth login --preset workspace-full
gdrv auth login --preset admin
gdrv auth login --preset workspace-with-admin
# Advanced API presets
gdrv auth login --preset workspace-activity
gdrv auth login --preset workspace-labels
gdrv auth login --preset workspace-sync
gdrv auth login --preset workspace-complete
# Device code flow
gdrv auth device --preset workspace-basic
# Service account
gdrv auth service-account --key-file ./key.json --preset workspace-completegdrv auth login --scopes "https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/spreadsheets.readonly"
gdrv auth service-account --key-file ./key.json --scopes "https://www.googleapis.com/auth/drive.file"Drive Scopes:
https://www.googleapis.com/auth/drive- Full Drive accesshttps://www.googleapis.com/auth/drive.file- Per-file accesshttps://www.googleapis.com/auth/drive.readonly- Read-only Drive accesshttps://www.googleapis.com/auth/drive.metadata.readonly- Read-only metadata
Workspace Scopes:
https://www.googleapis.com/auth/spreadsheets- Full Sheets accesshttps://www.googleapis.com/auth/spreadsheets.readonly- Read-only Sheetshttps://www.googleapis.com/auth/documents- Full Docs accesshttps://www.googleapis.com/auth/documents.readonly- Read-only Docshttps://www.googleapis.com/auth/presentations- Full Slides accesshttps://www.googleapis.com/auth/presentations.readonly- Read-only Slides
Admin SDK Scopes:
https://www.googleapis.com/auth/admin.directory.user- User managementhttps://www.googleapis.com/auth/admin.directory.user.readonly- Read-only usershttps://www.googleapis.com/auth/admin.directory.group- Group managementhttps://www.googleapis.com/auth/admin.directory.group.readonly- Read-only groups
Advanced API Scopes:
https://www.googleapis.com/auth/drive.activity- Full Activity API accesshttps://www.googleapis.com/auth/drive.activity.readonly- Read-only Activityhttps://www.googleapis.com/auth/drive.labels- Full Labels accesshttps://www.googleapis.com/auth/drive.labels.readonly- Read-only Labelshttps://www.googleapis.com/auth/drive.admin.labels- Admin label managementhttps://www.googleapis.com/auth/drive.admin.labels.readonly- Read-only admin labels
# Create and switch profiles
gdrv auth login --profile work
gdrv auth login --profile personal
# Use specific profile
gdrv --profile work files listIf your OAuth consent screen is in testing mode, refresh tokens expire after 7 days and Google enforces a 100 refresh-token issuance cap per client. If you see repeated invalid_grant errors, re-authenticate and revoke unused tokens in Google Cloud Console or move the app to production to avoid the testing-mode limits.
If you want to use your own OAuth client:
- Create a project in Google Cloud Console
- Enable the Google Drive API
- Create OAuth 2.0 credentials (Desktop application)
- Set credentials via environment variables or command flags:
export GDRV_CLIENT_ID="your-client-id"
export GDRV_CLIENT_SECRET="your-client-secret" # only if required by your client type
gdrv auth login --client-id "your-client-id" --client-secret "your-client-secret"