Click here to see other types of OAuth2 configurations or here for a tutorial.
- Open Google Cloud Console
- Create a new project
- Select the created project
- Navigate to APIs & Services → Enabled APis and services
- Search for "Gmail API" and enable it
- Search for "Cloud Pub/Sub" and enable it
- Navigate to APIs & Services → OAuth consent screen
- Choose your application type. "Internal" is valid only for email accounts in the same organization. "External" supports all Gmail accounts but requires extensive validation. In this tutorial, we use "Internal."
- Fill out the app-related fields in the "OAuth2 consent screen" form. Use the URL of your EmailEngine instance as the "Application home page."
- Click on Save and continue to get to the scopes form
- Click on Add or remove scopes and look for
https://www.googleapis.com/auth/gmail.modify
, add it and click Save and continue - Navigate to APIs & Services → Credentials
- Create new OAuth client ID
- Select Web application as the app type
- Add EmailEngine's URL as the authorized origin
- Use EmailEngine's URL with the /oauth path as the Authorized redirect URI
- Click Create to finish the application
- In the opened credentials screen, download credentials in JSON format
- In the credential page, click the Manage service accounts link to create a webhook service account. With Gmail API, EmailEngine needs to use the Cloud Pub/Sub API to retrieve email updates
- Create a new service account
- Grant the Pub/Sub Admin role to the service account. This is needed because EmailEngine needs to set up pubsub queues and give Gmail permissions to publish to that queue.
- Select the newly generated service account and navigate to Keys
- Create a new key in the JSON format and save the generated key file
- Create a new Gmail Service Account application in EmailEngine
- Select the JSON configuration file for the Pub/Sub service account
- Select Pub/Sub as base scopes and click on Register app
- Create a new Gmail OAuth2 application in EmailEngine
- Select the JSON file to autofill application configuration details
- Choose Gmail API as the base scope
- Choose the previously generated Gmail Service Account as the webhook handler for this app. (You can only choose a service account app with the same Google Cloud project ID.)
- Click Register app to finish the process