Skip to content
Skip to main content

How to use OAuth for Google Calendar

Last updated:

If your app reads or writes a user’s Google Calendar, OAuth is the permission boundary. The user authorizes your app, Google returns a code, and your server turns that into long-lived access. The native Google Calendar API makes you own the full OAuth flow, token refresh, scope review, and quota behavior.

Nylas hosted OAuth gives you the same user-consent model, but your app stores a grant_id instead of provider tokens. Nylas handles the Google token lifecycle behind that grant, and the same pattern works later if you add Microsoft, iCloud, or Exchange calendars.

Google scopes are full URI strings. Request the smallest set that matches your feature because broader scopes add friction on the consent screen and can lengthen Google’s verification review.

TaskGoogle scope
List calendars or check Free/Busyhttps://www.googleapis.com/auth/calendar.readonly
Read eventshttps://www.googleapis.com/auth/calendar.events.readonly
Create, update, delete, or respond to event invitationshttps://www.googleapis.com/auth/calendar.events
Manage calendars and eventshttps://www.googleapis.com/auth/calendar

The granular scopes reference lists the exact scope for every Nylas calendar endpoint. Google classifies Calendar scopes as sensitive, so production apps need Google OAuth verification. If you request Gmail restricted scopes in the same connector, you may also need a security assessment.

Send the user to /v3/connect/auth with your Nylas client ID, callback URI, provider, and state value. Set provider=google so the flow opens the Google consent screen.

Use state to bind the callback to the user who clicked Connect. Store a signed nonce or session ID, not a raw user ID by itself. When Google redirects back, check state before exchanging the code.

The Node.js SDK can build the URL:

After the user approves access, Google redirects to your callback with a code. Exchange it with Nylas to create the grant.

The response includes a grant ID. Save that ID on your user or workspace record:

{
"grant_id": "<NYLAS_GRANT_ID>",
"provider": "google",
"email": "[email protected]"
}

Use the grant ID for Calendar API calls. Your server authenticates with your Nylas API key, while the grant tells Nylas which Google Calendar account to act on.

Handle token refresh and re-authentication

Section titled “Handle token refresh and re-authentication”

Nylas refreshes the underlying Google access token for the grant, so your app doesn’t run a refresh-token job. A grant can still expire if the user revokes access, changes a password, or an admin policy invalidates tokens.

Subscribe to the grant.expired webhook and handle 401 responses on API calls. When a grant expires, send the user through hosted OAuth again. Re-authentication keeps the same account relationship and avoids losing your local sync mappings.

Error or symptomLikely causeFix
redirect_uri_mismatchCallback URI differs from the registered URIMatch the URI exactly in Google, your Nylas app, and the auth request
Unverified app warningGoogle OAuth consent screen isn’t verifiedAdd test users for development or complete Google verification
403 after a successful connectionConnector requested read-only scope but your app calls a write endpointAdd calendar.events or calendar, then re-authenticate the grant
User sees the wrong Google accountBrowser session picked an existing loginPass login_hint and let the user choose the correct account
Grant later expiresUser or admin revoked provider accessRe-authenticate the same grant and listen for grant.expired

The broader OAuth troubleshooting guide covers Microsoft errors and token-level failures too.

Things to know about Google Calendar OAuth

Section titled “Things to know about Google Calendar OAuth”

Calendar scopes are separate from Gmail scopes. Connecting Gmail doesn’t automatically grant calendar access. Add the calendar scope before the user authenticates.

Use calendar.events.readonly when you only display events. Don’t request write scopes until your app creates, updates, deletes, or responds to event invitations.

Use service accounts only for Workspace-wide calendar access. Per-user SaaS apps usually use hosted OAuth. Google Workspace service accounts are a separate admin-controlled model, and they support Google Calendar only.

Keep the API key server-side. Browser code can start OAuth, but Calendar API requests with your Nylas API key should happen from your server.