Skip to content
Skip to main content

Bulk authentication grants

Last updated:

Bulk authentication grants let you authenticate users without requiring each person to go through an individual OAuth flow. This is useful when you need to access mailboxes or calendars for many users in an organization.

Google and Microsoft use different mechanisms for this:

  • Google uses service accounts with domain-wide delegation. A Google Workspace admin grants your service account access to user data across the domain.
  • Microsoft uses admin consent. A Microsoft Entra ID (formerly Azure AD) admin approves your app’s requested permissions for all users in the tenant. You don’t need to create a service account or generate new keys — you use your existing Azure app’s client ID and secret.

Both flows require you to register your provider credentials with Nylas using the Create Credential API, then create grants for individual users using the Custom Authentication API.

Bulk auth grants aren’t related to Nylas Service Accounts, which use cryptographic request signing for organization-level admin APIs.

Make sure your Nylas application has a working Google or Microsoft connector. You can check this on the Nylas Dashboard, or make a Get all connectors request.

If you don’t have a connector, create one from the Dashboard or make a Create Connector request.

Google bulk auth grants use a Google Workspace service account with domain-wide delegation. The service account’s private key lets Nylas request access tokens for any user in the domain without individual OAuth flows.

  1. Create a Google service account and delegate domain-wide authority.
  2. Register the service account with Nylas.
  3. Create a grant for a user.

Follow the Google provider guide to create a service account and delegate domain-wide authority. You’ll need the service account’s JSON key file for the next step.

When you delegate domain-wide authority, the scope list you enter in the Google Admin console must include every scope you plan to pass when you create grants in Step 3.

Step 2: Register the service account with Nylas

Section titled “Step 2: Register the service account with Nylas”

Make a Create Credential request to register your Google service account with Nylas. Include the service account details from the JSON key file you downloaded.

Save the id from the response. You’ll use this credential_id when creating grants.

Make a Custom Authentication request to create a grant for a specific user’s email address. Use the credential_id from the previous step, and list the scopes the grant needs. Each scope must appear in the service account’s domain-wide delegation list, or grant creation fails.

Repeat this step for each user you want to authenticate. Because the service account has domain-wide delegation, you can create grants for any user in the Google Workspace domain.

Create Microsoft bulk authentication grants

Section titled “Create Microsoft bulk authentication grants”

Microsoft bulk auth grants use Microsoft Entra admin consent to grant your app application-level permissions. Unlike Google (where you generate a service account key), you use your existing Azure app’s client ID and secret. A Microsoft admin at your customer’s organization then approves your app for their tenant, which gives it access to user mailboxes and calendars without individual OAuth flows.

  1. Configure your Azure app for application permissions.
  2. Register your Azure app credentials with Nylas.
  3. Get admin consent for your app.
  4. Create a grant for a user.

Step 1: Configure your Azure app for application permissions

Section titled “Step 1: Configure your Azure app for application permissions”

Your Azure app needs a web platform, a client secret, and Microsoft Graph application permissions. If you already configured the platform and secret when setting up your Microsoft connector, skip to step 4 and add the application permissions. If you don’t have an Azure app yet, create one first, then configure it:

  1. From the Authentication tab, click Add a platform.
  2. Set the Platform to Web and enter the Custom Auth URI.
  3. In the Certificates & secrets tab, click New client secret and add a client secret.
  4. In the API permissions tab, click Add a permission and select Microsoft Graph from the list of APIs.
  5. Select Application permissions and add the Microsoft Graph permissions your project needs, including User.Read.All. To work out which ones, see Calculating scopes in the Azure app guide and the scopes reference. Only add the permissions your integration uses, because tenant admins see the full list when they grant consent.

You don’t need to select Grant admin consent here. You’ll grant consent in Step 3 using an authorization request.

Step 2: Register your Azure app credentials with Nylas

Section titled “Step 2: Register your Azure app credentials with Nylas”

Make a Create Credential request to register your Azure app’s client_id and client_secret with Nylas. You don’t need to generate any new credentials for this step — use the client ID and secret from your existing Azure app.

Save the id from the response. You’ll use this credential_id in the next steps.

The tenant field controls which organizations can use the admin consent URL:

  • common — the consent URL works for any Microsoft organization. Your app gets the scopes configured in your Azure app’s API permissions.
  • A specific tenant ID — the consent URL only works for that organization, but you can override scopes in the URL itself.

If you don’t define client_id and client_secret, Nylas uses the credentials from your application’s Microsoft connector.

Send the following OAuth Authorization URL to the Microsoft admin at your customer’s organization. When they open it, Microsoft prompts them to approve your app’s application-level permissions for their tenant. Use the credential_id from the previous step.

If you set tenant to common (scopes come from your Azure app’s API permissions):

If you specified a tenant ID (you can override scopes in the URL):

After the admin approves, Nylas redirects to your redirect_uri with admin_consent=true, state, and tenant_id=<azure-tenant-guid>. If the flow fails, Nylas returns an OAuth 2.0 error with state, error, error_description, and error_uri.

Wait at least 5 minutes after admin consent before creating a grant. Microsoft caches scopes and needs time to propagate the updated permissions.

Step 4: Create a Microsoft bulk auth grant

Section titled “Step 4: Create a Microsoft bulk auth grant”

Make a Custom Authentication request to create a grant for a specific user’s email address. Use the credential_id from Step 2. Unlike the Google request, you don’t pass scopes here. The grant inherits the application permissions the admin consented to.

The scope and app_permission_scopes arrays in the response mirror the application permissions the admin consented to in Azure. Nylas doesn’t require a fixed list. Your response shows whichever Graph permissions you configured on your Azure app, so it might differ from this example.

Repeat this step for each user you want to authenticate. The admin consent you obtained in the previous step covers all users in the tenant.