-
Notifications
You must be signed in to change notification settings - Fork 134
Image CDN Google Drive Credentials
Nicholas de Paola edited this page Jun 13, 2026
·
1 revision
The image CDN Cloudflare Worker authenticates with the Google Drive API using OAuth 2.0. It needs three secrets:
| Secret | Purpose |
|---|---|
IMAGE_CDN_GOOGLE_CLIENT_ID |
Identifies your Google Cloud OAuth application |
IMAGE_CDN_GOOGLE_CLIENT_SECRET |
Authenticates your Google Cloud OAuth application |
IMAGE_CDN_GOOGLE_REFRESH_TOKEN |
Long-lived token used to obtain short-lived access tokens at runtime |
At runtime, the worker exchanges the refresh token + client credentials for a short-lived access token, then uses that token to query Google Drive file metadata (drive/v3/files/{id}) and to detect stale cached thumbnails.
- Go to Google Cloud Console.
- Create a new project (or select an existing one).
- In the left sidebar, navigate to APIs & Services → Library.
- Search for Google Drive API and enable it.
- Navigate to APIs & Services → Credentials.
- Click Create Credentials → OAuth client ID.
- If prompted, configure the OAuth consent screen first:
- Set User type to External (or Internal if using a Google Workspace org).
- Fill in the required app name and contact fields.
- Add the scope
https://www.googleapis.com/auth/drive.metadata.readonly. - Add your Google account as a test user.
- Back on the Create OAuth client ID page:
- Set Application type to Web application.
- Under Authorised redirect URIs, add
https://developers.google.com/oauthplayground.
- Click Create.
- Copy the Client ID and Client Secret — these become
IMAGE_CDN_GOOGLE_CLIENT_IDandIMAGE_CDN_GOOGLE_CLIENT_SECRET.
- Open Google OAuth 2.0 Playground.
- Click the gear icon (⚙️) in the top-right corner and check Use your own OAuth credentials.
- Enter your OAuth Client ID and OAuth Client Secret from Step 2.
- In the left panel under Step 1, find Drive API v3 and select the scope:
https://www.googleapis.com/auth/drive.metadata.readonly - Click Authorise APIs and sign in with the Google account that owns (or has access to) the Drive files the CDN will serve.
- Check Auto-refresh the token before it expires.
- After authorisation, you will be on Step 2. Click Exchange authorisation code for tokens.
- The response will contain a
refresh_tokenfield. Copy its value — this becomesIMAGE_CDN_GOOGLE_REFRESH_TOKEN.
Note: The refresh token is only shown once. If you lose it, repeat Step 3 to generate a new one.
Add the three values as repository secrets (used by the CI/CD deployment workflow):
| Secret name | Value |
|---|---|
IMAGE_CDN_GOOGLE_CLIENT_ID |
Client ID from Step 2 |
IMAGE_CDN_GOOGLE_CLIENT_SECRET |
Client Secret from Step 2 |
IMAGE_CDN_GOOGLE_REFRESH_TOKEN |
Refresh token from Step 3 |
Go to your repository → Settings → Secrets and variables → Actions → New repository secret to add each one.
If deploying the worker manually with Wrangler, set the secrets directly on the worker:
wrangler secret put GOOGLE_CLIENT_ID
wrangler secret put GOOGLE_CLIENT_SECRET
wrangler secret put GOOGLE_REFRESH_TOKENMade with