Skip to content

NylasConnect.callback()

NylasConnect.callback() is a callback handler that works for both pop-up and inline authentication flows. This is the recommended method when handling OAuth callbacks on your backend.

The url parameter is optional in the browser (defaults to window.location) but required on the backend since there’s no window object available.

Use callback(url) on your backend when:

  • You want to handle OAuth code exchange with client_secret (more secure than PKCE)
  • You need to store tokens on the backend, not in the browser
  • You want to link grants to users securely using a state parameter
  • You’re making Nylas API calls from the backend using your API key

See the backend-handled OAuth flow guide for a complete example.

PropertyTypeDescription
urlstring?The callback URL to process. Optional in browser (uses window.location). Required on backend.

The callback() method returns a Promise<ConnectResult> with the following properties.

PropertyTypeDescription
accessTokenstringThe access token associated with the user’s grant.
expiresAtnumberWhen the access token will expire, in milliseconds using the Unix timestamp format.
grantIdstringA unique identifier for the user’s grant.
grantInfoGrantInfo?Optional grant information from the idToken.
idTokenstringAn ID token containing information about the user.
scopestringA space-delimited list of scopes associated with the user’s grant.
PropertyTypeDescription
emailstringThe email address associated with the grant.
emailVerifiedboolean?When true, indicates that the user has verified their email address.
familyNamestring?The user’s surname (last name).
givenNamestring?The user’s given (first) name.
idstringA unique identifier for the user’s grant.
namestring?The user’s display name.
picturestring?A URL that links to the user’s profile picture.
providerstringThe OAuth provider that the user authenticated with.