Gmail is an email service use to communicate. By adding the Gmail connector, developers will be able index emails into Ocular and make them searchable.

This approach will explore how an individual can connect to Gmail using OAuth.

Obtaining Gmail Secrets

  1. Navigate to Google Cloud Console to create a Google Cloud Project.

  2. Add the Gmail Api to your Cloud Project.

    • Click on API & Services and then Enable API Services.
    • Click on +Enable Api Services
    • Search for Gmail API and click Enable.
  3. Create OAuth Credentials For Gmail.

    • Click on Configure OAuth screen then follow instructions.
    • Click on Credentials to Generate Client Id and Client Secret.
    • Create the Client Id and Client Secret and add URI as http://localhost:3001 and the redirect URI http://localhost:3001/dashboard/marketplace/google-drive.

Enviroment Variables

Add CLIENT_ID and CLIENT_SECRET variable to env.local if you are running Ocular fully in Docker or env.dev if you running Ocular in Dev mode.

GOOGLE_CLIENT_ID=<CLIENT_ID_FROM_ABOVE>
GOOGLE_CLIENT_SECRET=<CLIENT_SECRET_FROM_ABOVE>

Installing the Gmail Connector

To install a connector in your backend, add the connector to the Ocular config file in your backend.

The following config files are currenlty supported

  • core-config-local.js - for running Ocular in Docker.
  • core-config-dev.js - for running Ocular in development mode.

Set the following in the core-config-xxx.js apps section.

core-config-xxx.js
apps: [
   //..
   {
      resolve: `gmail`,
      options: {
        client_id: process.env.GOOGLE_CLIENT_ID,
        client_secret: process.env.GOOGLE_CLIENT_SECRET,
        redirect_uri: `${UI_CORS}/dashboard/marketplace/gmail`,
        // Rate limiter options for regulating the calls to the Gmail api.
        rate_limiter_opts: {
          requests: 60, // Number of Requests
          interval: 60, // Interval in Seconds
        },
        // Authentication Strategy For Ocular. Set to OAuth since we are using OAuth in this case.
        auth_strategy: AppAuthStrategy.OAUTH_TOKEN_STRATEGY,
      },
    },
]