Helper script to refresh OAuth2 tokens for Gmail test accounts.
npm install googleapis
node scripts/refresh-test-tokens.js- Prompts you to select which test account(s) to refresh
- Generates an OAuth2 authorization URL for each account
- Starts a local web server on port 3000 to receive the OAuth callback
- Opens your browser to authenticate with Google
- Exchanges the authorization code for new access and refresh tokens
- Automatically updates the
.envfile with the new refresh tokens
googleapispackage (installed as dev dependency).envfile with the following variables:
Full access accounts (gmail.modify scope):
GMAIL_API_CLIENT_IDGMAIL_API_CLIENT_SECRETGMAIL_API_ACCOUNT_EMAIL_1GMAIL_API_ACCOUNT_REFRESH_1GMAIL_API_ACCOUNT_EMAIL_2GMAIL_API_ACCOUNT_REFRESH_2
Send-only account (gmail.send scope only):
GMAIL_SENDONLY_CLIENT_IDGMAIL_SENDONLY_CLIENT_SECRETGMAIL_SENDONLY_ACCOUNT_EMAILGMAIL_SENDONLY_ACCOUNT_REFRESH
- The script requests
offlineaccess to get refresh tokens - It uses
prompt=consentto ensure a new refresh token is issued - The OAuth redirect URI is set to
http://127.0.0.1:3000/oauth - Make sure port 3000 is available before running the script
- The script binds to 127.0.0.1 (not 0.0.0.0) for security