Gmail
OAuth Access Token vs Refresh Token
Published 2026-09-20 · CSV Sender
Access tokens call Gmail API briefly; refresh tokens obtain new access tokens server-side. CSV Sender encrypts refresh material and refreshes before send.
Quick answer
An OAuth access token authorizes individual Gmail API requests for roughly an hour. A refresh token lets CSV Sender’s server request fresh access tokens without showing the consent screen each time. Access token expiry is normal and handled in ensureAccessToken; losing refresh authorization triggers REAUTH_REQUIRED (Gmail authorization expired).
Access token responsibilities
- Sent as
Authorization: Beareronusers.messages.send - Stored encrypted with expiry timestamp
- Discarded logically after expiry—refreshed proactively
Refresh token responsibilities
- Obtained during initial OAuth with offline access (web server flow—see Google docs in sources)
- Encrypted at rest with
TOKEN_ENCRYPTION_KEY - Used only server-side in workers and connect callback routes
- Invalidated when user revokes app (revoke Gmail app access)
CSV Sender flow
- User completes OAuth consent for Gmail send scope.
- Callback stores encrypted refresh + first access token.
- Each cron tick loads Gmail account, refreshes if near expiry, sends prepared rows.
- Auth errors classify as AUTH without pointless retries (email send retries).
Security comparison
| Token | Lifetime | Exposure risk if leaked |
|---|---|---|
| Access | Short | Limited window |
| Refresh | Long until revoked | High—must stay server-only |
FAQ
Should I log access tokens?
No—treat as secrets.
Does refresh token appear in browser?
No—CSV Sender keeps it server-side.
Can I export refresh tokens?
Not via UI—by design.
Multiple Gmail accounts?
Each mailbox has its own token pair (multiple Gmail senders).
Where is scope hub?
Related reading
- Gmail OAuth for email sending
- Gmail Google permissions
- Idempotent email sending
- Gmail API send email
Clock skew considerations
Access token expiry checks use server clocks. Large skew between app servers and NTP may cause premature refresh or rare 401s—keep infrastructure time-synchronized in production deployments.
Rotation and key management
TOKEN_ENCRYPTION_KEY rotation requires re-encrypting stored tokens—a operational procedure outside day-to-day sending. Document key rotation in your deployment runbook if you self-host CSV Sender.
Shared hosting caution
Multi-tenant SaaS must isolate refresh tokens per workspace with database RLS—CSV Sender’s schema ties gmail_accounts to workspaces so one tenant cannot decrypt another’s tokens even with SQL injection defenses failing (defense in depth).
Comparison to API keys
Some products use long-lived API keys for SMTP. OAuth refresh tokens are similarly sensitive but revocable per app in Google Account UI without rotating the user’s Gmail password.
Educational analogy
Access tokens are like day passes; refresh tokens are like a renewable badge issued once at onboarding. Users revoke the badge centrally when offboarding CSV Sender.
Incident response if refresh token leaks
Rotate TOKEN_ENCRYPTION_KEY only with a planned maintenance window and re-encryption job. Force users to reconnect Gmail if plaintext refresh material ever appeared in logs—treat as equivalent to password compromise for that mailbox’s sending capability.
Document in security policies that refresh tokens grant sending capability until revoked—matching user education in gmail Google permissions.
Production checklist (1)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Production checklist (2)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Production checklist (3)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Production checklist (4)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Sources
Related articles
Gmail
Gmail OAuth for Sending Email: Scopes, Security, and CSV Workflows
Understand Google OAuth for Gmail send-only access, why CSV Sender requests gmail.send, and how tokens stay encrypted at rest.
Email Operations
What Happens When Gmail Authorization Expires?
When Gmail OAuth access expires, CSV Sender usually refreshes silently. Reconnect when refresh fails, tokens are revoked, or the sender shows REAUTH_REQUIRED.
Gmail
Can You Revoke Gmail App Access?
Remove CSV Sender’s OAuth access from Google Account settings, understand REAUTH_REQUIRED in the product, and resume campaigns after reconnecting.
Gmail
What Is the gmail.send Scope?
Google’s scope table describes gmail.send as sending email on a user’s behalf. CSV Sender uses only that scope—matching lib/gmail/scopes.ts.
Permalink: http://localhost:3000/blog/oauth-access-vs-refresh-token