This page describes how to set up and configure a third-party application before
creating the Microsoft 365 data store.

## Set up authentication and permissions

The Microsoft 365 connector signs in as the end user using the OAuth 2.0
authorization code flow against the Microsoft identity platform. All
Microsoft Graph permissions are delegated, so the connector can reach
only the data the signed-in user can already reach. You can configure
authentication in one of two ways:

- **Google-managed OAuth** (**OAuth 2.0 (Google Managed)** , default): The connector uses a multitenant Microsoft Entra application that Google registers and manages. You don't register an application or enter a tenant ID, client ID, or client secret. See [Use Google-managed OAuth](https://docs.cloud.google.com/gemini/enterprise/docs/connectors/ms-365/third-party-config.md.txt#google-managed-oauth).
- **Bring your own app** (**OAuth 2.0 (Bring Your Own App)** ): You register your own Microsoft Entra application, grant it the Microsoft Graph permissions for the actions you plan to enable, and enter its tenant ID, client ID, and client secret in Gemini Enterprise. Choose this option if your organization needs to control the application and its permissions directly, if you need static IP egress, or if your tenant is in a US Government cloud. See [Register an Microsoft Entra app](https://docs.cloud.google.com/gemini/enterprise/docs/connectors/ms-365/third-party-config.md.txt#entra-app-registration).

### Use Google-managed OAuth

With **OAuth 2.0 (Google Managed)** , you don't create anything in
Microsoft Entra before you create the data store. When a user authorizes the
connector, Microsoft asks them to consent to the
Microsoft Graph permissions that the enabled actions need. For the full
list, see [Configure Microsoft API permissions](https://docs.cloud.google.com/gemini/enterprise/docs/connectors/ms-365/third-party-config.md.txt#configure-api-permissions).

Some of these permissions, and some tenant consent policies, require an
Microsoft Entra administrator to consent on behalf of the organization. If users
see a **Need admin approval** message when they authorize the connector, an
administrator must grant tenant-wide consent to the Google-managed
application. For more information, see
[Grant tenant-wide admin consent to an application](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent)
in the Microsoft documentation.

Keep the following in mind when you use Google-managed OAuth:

- The Google-managed application is registered in the commercial Microsoft cloud, so leave **Microsoft 365 Environment Type** set to **Standard** . For tenants in GCC High or DoD, use **OAuth 2.0 (Bring Your
  Own App)**.
- Static IP egress isn't available, because the shared application can't carry a per-customer IP allowlist.

The rest of this section applies only to **OAuth 2.0 (Bring Your Own App)**.

### Register an Microsoft Entra app for the Microsoft 365 connector

To register Gemini Enterprise as an OAuth 2.0 application in Microsoft Entra, do
the following:

1. Navigate to the [Microsoft Entra admin center](https://entra.microsoft.com).

2. In the navigation menu, expand **Entra ID** and select
   **App registrations**.

3. On the **App registrations** page, click
   **New registration**.

4. On the **Register an application** page, do the following:

   1. In the **Name** field, enter a name for your app.
   2. In the **Supported account types** section, select **Accounts in this
      organizational directory only**.
   3. In the **Redirect URI** section, do the following:
      1. In the platform list, select **Web**.
      2. In the redirect URI field, enter `https://vertexaisearch.cloud.google.com/oauth-redirect`.
   4. Click **Register**. Microsoft Entra creates your app and displays the overview page of your app.

### Obtain the client ID and client secret

1. To obtain the client ID, do the following:

   1. In the app navigation menu, select **Overview**.
   2. Copy the **Application (client) ID**.
2. To obtain the client secret for the app, do the following:

   1. In the app navigation menu, select **Certificates \& secrets**.
   2. Click **New
      client secret**.
   3. In the client secret pane, do the following:
      1. In the **Description** field, enter a description for the secret.
      2. In the **Expires** list, select an expiry duration.
      3. Click **Add**.
   4. Copy the client secret from the **Value** column.

> [!NOTE]
> **Note:** The client secret value is shown only once. Store it securely before you leave the page. When the secret expires, the connection stops refreshing its token and you must update the data store with a new secret.

### Obtain the tenant ID

Your tenant ID can be found in the **Tenant ID** box on the
[overview page](https://entra.microsoft.com/#view/Microsoft_AAD_IAM/TenantOverview.ReactView)
in the Microsoft Entra admin center.

### Configure Microsoft API permissions

If you use **OAuth 2.0 (Bring Your Own App)** , grant your app the delegated
Microsoft Graph permissions for the actions you plan to enable. If you
use **OAuth 2.0 (Google Managed)**, you don't add these permissions yourself;
users are asked to consent to them when they authorize the connector.

The permissions each action needs are listed in the **Required permissions**
column of the
[supported actions](https://docs.cloud.google.com/gemini/enterprise/docs/connectors/ms-365.md.txt#supported-actions)
tables. Every connection also needs `User.Read` and `offline_access`.

To configure the required API permissions on your own app, do the following:

1. On the app page, select **API permissions**.

2. Click **Add a permission**.

3. On the **Request API permissions** page, select **Microsoft
   Graph** , and then select **Delegated permissions**.

4. Search for and select `User.Read`, `offline_access`, and the permissions
   listed for each action you plan to enable.

5. Click **Add permissions**.

> [!NOTE]
> **Note:** Grant only the permissions for the actions you enable. Gemini Enterprise builds the authorization request from the actions selected on the data store, so a permission that no enabled action needs is never requested.

> [!NOTE]
> **Note:** Some of these permissions require tenant-wide admin consent. After adding them, grant admin consent for your tenant. For more information, see [Grant tenant-wide admin consent](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent?pivots=portal#grant-tenant-wide-admin-consent-in-enterprise-apps-pane) in the Microsoft documentation.

## Sovereign and government clouds

If your tenant is not in the standard Microsoft cloud, set both of the
following when you create the data store. Sign-in through **US Government**
requires **OAuth 2.0 (Bring Your Own App)**, with an app registered in that
cloud.

- **Microsoft 365 Environment Type** , in the **Authentication settings**
  section, selects the sign-in endpoint: **Standard** uses
  `login.microsoftonline.com` and **US Government** uses
  `login.microsoftonline.us`.

- **Microsoft 365 Cloud Environment** , in the **Advanced options**
  section, selects the Microsoft Graph endpoint: **Standard / GCC**
  uses `https://graph.microsoft.com`, **GCC High** uses
  `https://graph.microsoft.us`, and **DoD** uses
  `https://dod-graph.microsoft.us`.

> [!NOTE]
> **Note:** GCC tenants run in the commercial cloud, so they use the same Microsoft Graph endpoint as standard tenants. GCC High and DoD tenants don't.

## Troubleshooting

This section describes errors you might see after configuring the
Microsoft Entra application, and how to resolve them.

### Actions fail with HTTP 403

An action that returns HTTP 403 is usually missing a permission. Check that the
permission the action needs was consented to, that admin consent was granted
where required, and that the connection was re-authorized after the action was
enabled. With **OAuth 2.0 (Bring Your Own App)**, also check that your
Microsoft Entra app registration grants the permission. An existing refresh token carries
only the scopes consented to when it was issued.

### Mail search returns `MailboxNotEnabledForRESTAPI`

This error means the mailbox isn't reachable through Microsoft Graph.
It occurs when the mailbox is hosted on-premises in a hybrid Exchange
deployment, when the mailbox is inactive or soft-deleted, or when there is a
tenant or directory mismatch. To resolve it, ensure the mailbox is hosted in
Exchange Online. For more information, see
[How to fix MailboxNotEnabledForRESTAPI](https://learn.microsoft.com/en-us/answers/questions/1657546/how-to-fix-mailboxnotenabledforrestapi)
in the Microsoft documentation.