Authentication APIs
Hosted OAuth - Token exchange
The standard OAuth token endpoint for Hosted Authentication. This endpoint doesn't require authentication, as it is part of the auth process. You can pass one of the following grant_type values:
- authorization_code: Exchange the code Nylas returns from the OAuth 2.0 authorization flow for tokens (access_token and refresh_token). - refresh_token: Use the existing refresh_token for an existing grant to issue a new access_token. You must pass your API key in the client_secret field.
- client_credentials: Issue a new short-lived (1 hour) access_token using an existing grant_id. You must pass your API key in the client_secret field. This is mainly used in Scheduler implementations.
This endpoint accepts both application/json and application/x-www-form-urlencoded request body types. The body parameters are the same for both, with the same naming conventions. For more information, see the Hosted authentication with access token documentation.
Failed token exchange requests
Each OAuth code is a unique, one-time-use credential. If your token exchange fails, you must restart the OAuth process. If you try to pass the original code in another token exchange request, the provider rejects the code and Nylas returns an error.
post/v3/connect/token
Request body
Example request
{
"client_id": "<NYLAS_CLIENT_ID>",
"client_secret": "<NYLAS_API_KEY>",
"grant_type": "authorization_code",
"redirect_uri": "https://example.com/callback-handler",
"code_verifier": "nylas"
}Response
The token exchange was successful.
Example response
{
"access_token": "<NYLAS_ACCESS_TOKEN>",
"expires_in": 3600,
"id_token": "<JWT_TOKEN>",
"email": "example@gmail.com",
"refresh_token": "<REFRESH_TOKEN>",
"scope": "https://www.googleapis.com/auth/gmail.readonly profile",
"token_type": "Bearer",
"grant_id": "<NYLAS_GRANT_ID>",
"provider": "google"
}