# Generating OAuth 2.0 Credentials

The following procedures outline how to generate the necessary OAuth 2.0 credentials.

> [!NOTE]
>
> When generating client credentials and service account credentials, use a Google Workspace user who has permission to generate refresh tokens and the required roles or IAM roles to manage Google Workspace and GCP data. Refer to [Prerequisites](<https://documentation.sailpoint.com/connectors/google_workspace/saas/help/supported_features_prerequisites.html#prerequisites>) and [Required Roles for Google Workspace and GCP Management](<https://documentation.sailpoint.com/connectors/google_workspace/saas/help/supported_features_prerequisites.html#required-roles-for-google-workspace-and-gcp-management>).

## Client Credentials

This section describes the procedures for generating the Client ID, Client Secret, and Refresh Token.

### Generating a Client ID and Client Secret

1. Go to **Google Cloud Platform \> APIs &amp; Services \> Credentials**.
2. From the project dropdown list, select an existing project or create a new one.
3. On the **Credentials** page, select **Create Credentials \> OAuth Client ID**.
4. If prompted with a Consent page, select the application type as **Internal**, enter the application name, and save it.
5. Under **Application type**, select **Web application**.
6. Enter an **Application Name**.
7. Under **Authorized redirect URLs**, add the following:

   ```text
   https://developers.google.com/oauthplayground
   ```
8. Select **Create**.

   Note the Client ID and Client Secret displayed, as these are required for generating the refresh token.

### Generating a Refresh Token

> [!NOTE]
>
> Before proceeding, ensure you have generated the Client ID and Client Secret.

1. Go to the [OAuth2 Playground](<https://developers.google.com/oauthplayground/>).
2. Select the gear icon in the upper right corner and select the **Use your own OAuth credentials** checkbox (if it is not already selected).

   1. Confirm that OAuth Flow is set to Server-side and Access type is set to **Offline**. This ensures that you get a refresh token and an access token.
   2. Enter the **OAuth2 client ID** and **OAuth2 client secret** you obtained in the previous step.
   3. In **Step 1 - Select &amp; authorize APIs**, enter the required scopes in the text box at the bottom. Use a comma as a separator to add more than one scope.

   | Scope | Purpose |
   | --- | --- |
   | `https://www.googleapis.com/auth/admin.directory.user` | User Provisioning |
   | `https://www.googleapis.com/auth/apps.groups.settings` | Group Settings API |
   | `https://www.googleapis.com/auth/admin.directory.rolemanagement` | All role management operations, including creating roles and role assignments |
   | `https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly` | Getting and listing roles, privileges, and role assignments |
   | `https://www.googleapis.com/auth/cloud-platform`<br>`https://www.googleapis.com/auth/iam` | Accessing GCP-related data |
   | `https://www.googleapis.com/auth/admin.directory.domain` | Managing a domain as an account type in GCP |
3. When prompted, sign in to the account that you want to grant access to and select **Allow**.

   > **Note**
   >
   > If a `redirect_uri_mismatch` error states that your changes might not have propagated, select **Back** and try selecting **Authorize APIs** again.
4. On **Step 2 - Exchange authorization code for tokens**, verify that the **Authorization code** is displayed.
5. Select **Exchange authorization code for tokens**.

   The **Refresh token** and **Access token** fields are displayed.
6. Copy the **Refresh token** into the configuration file for the client library with the Client ID and Client Secret.

## Service Account

> [!NOTE]
>
> SailPoint's Cloud Infrastructure Entitlement Management (CIEM) only supports Service Account as a grant type.

A Service Account belongs to the application. Create a service account for the project in the API Console, delegate domain-wide access to the service account, and add the required scopes in the admin console against the service account Client ID.

### Creating a Service Account and Generating a Private Key

1. Sign in to the Google Cloud Platform Console using a user who has the permissions required to generate the private key and manage Google Workspace and GCP data.
2. Go to [Service Accounts](<https://console.cloud.google.com/iam-admin/serviceaccounts>).
3. Select an existing project or create a new project.
4. Select **Create service account**.
5. Enter a name and description for the service account. For example, enter `Project-Service Account`.
6. Select **Done**.
7. Select the email address of the newly created service account.
8. Go to **Keys**.
9. Select **Add key \> Create new key**.
10. Select **JSON**.
11. Select **Create**. The private key downloads to the computer in JSON format.
12. Select **Close**.

### Adding Scopes to the Service Account

1. Sign in to the [Google Admin Console](<https://admin.google.com/>) as a Super Admin user.
2. Go to **Menu \> Security \> Access and data control \> API controls**.
3. Select **Manage Domain Wide Delegation**.
4. Select **Add new**.
5. Enter the service account client ID. The client ID, also called the Unique ID, is the `client_id` in the downloaded JSON file, for example, `"client_id":"102996919678308170059"`. You can also find it under **IAM &amp; Admin \> Service accounts \> \[your service account\]**.
6. In **OAuth scopes**, enter the required scopes. Use a comma as a separator to add more than one scope.

   | Scope | Purpose |
   | --- | --- |
   | `https://www.googleapis.com/auth/admin.directory.group` | Group Provisioning |
   | `https://www.googleapis.com/auth/admin.directory.user` | User Provisioning |
   | `https://www.googleapis.com/auth/apps.groups.settings` | Group Settings API |
   | `https://www.googleapis.com/auth/admin.directory.rolemanagement` | All role management operations, including creating roles and role assignments |
   | `https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly` | Getting and listing roles, privileges, and role assignments |
   | `https://www.googleapis.com/auth/gmail.settings.sharing` | Gmail API provisioning |
   | `https://www.googleapis.com/auth/cloud-platform`<br>`https://www.googleapis.com/auth/iam` | Accessing GCP-related data |
   | `https://www.googleapis.com/auth/gmail.settings.basic`<br>`https://mail.google.com/`<br>`https://www.googleapis.com/auth/gmail.modify`<br>`https://www.googleapis.com/auth/gmail.readonly` | Gmail API aggregation |
   | `https://www.googleapis.com/auth/admin.directory.domain` | Managing a domain as an account type in GCP |
7. Select **Authorize**.

   > **Note**
   >
   > If an error displays, the client ID might not be registered with Google or the scopes might contain duplicates or unsupported values.
8. Select the new **Client ID**.
9. Select **View details** and verify that each scope is listed.
10. If a scope is missing, select **Edit**, enter the missing scope, and select **Authorize**. You can't edit the client ID.

The application should be available within minutes, but availability can take up to 24 hours.

### Assigning Scopes to the Service Account

[![Service Account Scopes](<https://documentation.sailpoint.com/connectors/google_workspace/saas/help/img/scopes_service_account.png>)](<https://documentation.sailpoint.com/connectors/google_workspace/saas/help/img/scopes_service_account.png>)

1. Go to [Google Admin](<https://admin.google.com/>).
2. Go to **Security \> Access and Data Control \> API controls**.
3. Select **Manage Domain Wide Delegation**.
4. Select the service account and assign the applicable scopes documented in this guide.

### Converting a Service Account Private Key to RSA Format

1. Open the downloaded JSON file.
2. Copy the private key value into a new file.

   For example:

   ```text
   -----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDVAm/9T1/yBO2Z\nCCUn9xJbaoFloMUQcQyc7Xd2snXeKSWXGNMmHFPOMTXT4KNCMsxfGPXeHixYcgp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wLUl46eGUbeMO9M4b1rrI7Sy+mVO97eH38Df\nPvkdyntXWXt7gcXQ26G1CUyTDe66JjWt1wXWIuMBk+AlfKShFsuTc+ajMQKBgFNB\nXbLp3409it3ywWsKXfBjr1zB1onRh3J1cQkrhwMeTpOD0UI7WefviF3fj6ju4jOk\nEt0ZMjgTf6IHd+AdP8RpSZLjMy+XpM0P5rLQMN/ZOStGJ6gwftNkaKU293Lx0aX3\nIt0np7OBwO0KCsjoeZ30jEse0P75KwRtp+Z8zIsBAoGAN47TexfJtaEK+ZQBoIn0\nh0mqV1si1QkPfMHSDvriKQ5d5tG8kF0vPVKAQV5kgytBeI+3bEO1iZC8i2FJzL7x\neN8ifRCcNXDRXjRdR0oPVIHImQ0XXwTB6JQmzVIFLWgxddDhZKpCQlA8GSRsbqEe\njtbTjDN0f5sX9llpKxd9xXw=\n-----END PRIVATE KEY-----\n
   ```
3. Replace each literal `\n` with a line break. In private key syntax, `\n` denotes a new line. You can make this change in most text editors.

   For example, in Notepad++, replace each `\\n` with `\n`.

   The following is an example of the converted key:

   ```text
   -----BEGIN PRIVATE KEY-----
   MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDVAm/9T1/yBO2ZCCUn9xJbaoFloMUQcQyc7Xd2snXeKSWXGNMmHFPOMTXT4KNCMsxfGPXeHixYcgpuPGok/bqJjY9rWncYh8/UUy3gox4fr+J21rj4qCZ5gvOItF7oVKfjk/E4SQrSRvApAc08W3u8vjNAmFoTBeUyEoKuHqCp48N5Gg3pM6htLXMrf2+q+wcv8IwtWAhopoG38XpjAh4+/bff/gkfFoDdIFYwo3IJ5qlU9xawmbZzy3R+8eZTM2WFAkG75lWfX7idj87J32EiSe9etCyER9EtaKbxIKC/bww/JKcz3nIWweyXOAX4/tMDs8ThcsztBTa/pseo4PI1AgMBAAECggEAEsdo+55OkV3lW4c4DV6vH9+TIlRK41DwIXqe/Fgt44Tho0FFRjgbnFNC0Vfd1MV5No4TCP7EfpSp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HImQ0XXwTB6JQmzVIFLWgxddDhZKpCQlA8GSRsbqEejtbTjDN0f5sX9llpKxd9xXw=

   -----END PRIVATE KEY-----
   ```
4. Save the converted private key in a new file.
5. Download and extract the latest version of OpenSSL.
6. From the OpenSSL `bin` folder, run one of the following commands:

   ```text
   openssl rsa -aes-256-cbc -in "<converted-private-key-file>" -out "<output-file>" -traditional
   ```

   For example:

   ```text
   $ openssl rsa -aes-256-cbc -in ConvertedGSuitePK.txt -out rsa.pem -traditional
   ```

   Or:

   ```text
   openssl rsa -aes-128-cbc -in "<converted-private-key-file>" -out "<output-file>" -traditional
   ```

   For example:

   ```text
   $ openssl rsa -aes-128-cbc -in ConvertedGSuitePK.txt -out rsa.pem -traditional
   ```
7. Enter the PEM passphrase.
8. Confirm the passphrase.

> [!NOTE]
>
> Use the generated RSA-format private key and the passphrase as the private key and private key password in the connector configuration.
