> ## Documentation Index
> Fetch the complete documentation index at: https://www.klavis.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Setting Up Gmail OAuth App

> Complete guide to creating and configuring a Gmail OAuth application

## Prerequisites

* Google account

## Step 1: Create a Project

1. Visit [https://console.cloud.google.com/home/dashboard](https://console.cloud.google.com/home/dashboard) and select the project dropdown at the top.

![Google Cloud project dropdown](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step1_box.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=979a10fa2e6cb931cb1106d1197ab2c7)

2. Click **New Project**.

![Google Cloud new project button](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step2_new_project.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=0fb65a9d7eb2f539ca884460ab3ab362)

3. Enter the project details and click **Create**.

![Google Cloud create project form](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step3_create.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=f9fd379401a4cb6e908851396ae8c466)

4. Select your newly created project.

![Google Cloud select project](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step4_select_project.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=45d53835c84f172daa24bdb74d2687fb)

5. Go to **APIs & Services**.

![Google Cloud APIs & Services menu](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step5_apis_and_services.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=d917dc7b6c4a0459f2eb10ee94a94edc)

6. Click **Enable APIs and Services**.

![Enable APIs and Services button](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step6_enable_api_services.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=76e23df4ad8b9462b634e62fac19fe25)

7. Search for and select **Gmail API**.

![Search Gmail API](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step7_select_gmail.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=f9e58f255a6832f2e02f873cffcca333)

8. Click **Enable**.

![Enable Gmail API](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step8_enable.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=f5f64e9c59e6ffcd3d847454a63bbb35)

9. Go back to **APIs & Services** and select **OAuth consent screen**.

![OAuth consent screen menu](https://mintcdn.com/klavisai/b0PbegeaiTqWkRoA/images/knowledge-base/gmail_oauth_app/step9_oauth_screen.png?fit=max\&auto=format\&n=b0PbegeaiTqWkRoA\&q=85\&s=39b6b35f487fcb069f0c3e8eacf7e877)

10. Enter the required information and save.

![OAuth consent screen form](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step10_info.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=968a21be4efa3134cf0c3d45ce0041d4)

11. Go to **Credentials** in APIs & Services and click **Create Credentials**.

![Create credentials button](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step11_CreateCredentials.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=dc25db746c5e2ee16fe6eb7fc0f10863)

12. Select **OAuth Client ID**.

![OAuth Client ID selection](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step12_OAuthClientID.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=bd463f0ba413e9158eb01fe7a2e5c09a)

13. Choose **Web Application** and enter the required details.

![Web application OAuth settings](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step13_WebApplication.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=7f28dcbaf73b2602adb8cded5d3f651a)

14. Add redirect URLs:
    `https://api.klavis.ai/oauth/gmail/`
    Then click **Create**.

![Add redirect URIs](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step14_redirect_uri.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=5b61a6b6e46cc5a0e92ee9cda0f8fc2f)

15. Your **Client ID** and **Client Secret** will be displayed.

![OAuth credentials screen](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/step15_credentials.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=275dce3520198db4032996eaf5a3d7c4)

## Step 2: Request Scopes

> [!NOTE]
>
> Klavis Gmail MCP Server uses the following OAuth scopes:
> `https://www.googleapis.com/auth/gmail.readonly`
> `https://www.googleapis.com/auth/gmail.send`
> `https://www.googleapis.com/auth/gmail.compose`
> `https://www.googleapis.com/auth/gmail.modify`

1. Go to **OAuth consent screen**.

![OAuth consent screen](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/scope1_oauth.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=0da8df557acefabe998eb86af9954f84)

2. Click **Data Access**.

![Data access settings](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/scope2_data_access.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=e9838be95092c70f791bd6aad0799d81)

3. Click **Add or Remove Scopes**.

![Add or remove scopes](https://mintcdn.com/klavisai/2FN45VVIW760Qvl2/images/knowledge-base/gmail_oauth_app/scope3_add_scopes.png?fit=max\&auto=format\&n=2FN45VVIW760Qvl2\&q=85\&s=61c585f233e832e14829e687874dbc6c)

4. Enter the needed scopes and click **Update**.

> [!TIP]
>
> You have successfully created a Gmail OAuth application! You now have your Client ID and Client Secret ready for integration with Klavis AI.

## (Optional) Step 3: White Labeling

> [!NOTE]
>
> White labeling allows you to customize the OAuth experience with your own branding instead of Klavis AI's.

If you want to use your own Gmail OAuth application with custom branding:

1. **Configure White Labeling**: Go to [https://www.klavis.ai/home/white-label](https://www.klavis.ai/home/white-label)
2. **Add Your Credentials**: Enter your Gmail **Client ID** and **Client Secret** from Step 1.
3. **Set Redirect URI**: Use `https://api.klavis.ai/oauth/gmail/callback` or your custom callback URL.
4. **Initiate OAuth**: Use your client ID when starting the OAuth flow:

   ```javascript without SDK theme={null}
   // Example: Initiating Gmail OAuth with white-label
   const authUrl = `https://api.klavis.ai/oauth/gmail/authorize?instance_id=${instanceId}&client_id=${yourClientId}`;
   window.location.href = authUrl;
   ```

   ```typescript TypeScript SDK theme={null}
   import { Klavis } from "@klavis/sdk";

   const klavis = new Klavis({
     apiKey: "YOUR_API_KEY"
   });

   // Example: Initiating Gmail OAuth with white-label
   const oauthUrl = await klavis.mcpServer.getOAuthUrl({
     serverName: Klavis.McpServerName.Gmail,
     instanceId: instanceId,
     clientId: yourClientId,
     // redirectUri: YOUR_REDIRECT_URI,
     // scope: "YOUR_SCOPES", 
   });

   window.location.href = oauthUrl;
   ```

   ```python Python SDK theme={null}
   import webbrowser
   from klavis import Klavis
   from klavis.types import McpServerName

   klavis = Klavis(api_key="YOUR_API_KEY")

   # Example: Initiating Gmail OAuth with white-label
   oauth_url = klavis.mcp_server.get_oauth_url(
       server_name=McpServerName.GMAIL,
       instance_id=instance_id,
       client_id=your_client_id,
       # redirect_uri="YOUR_REDIRECT_URI",
       # scope="YOUR_SCOPES"
   )

   # Open OAuth URL in user's default browser
   webbrowser.open(oauth_url)
   ```

> [!TIP]
>
> For detailed white labeling implementation and code examples, see our [OAuth & White Labeling guide](https://www.klavis.ai/docs/auth/white-label.md).

## Resources

* [Klavis OAuth & White Labeling Guide](https://www.klavis.ai/docs/auth/white-label.md)
* [Klavis White Label Dashboard](https://www.klavis.ai/home/white-label)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.