> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/g/google-directory.md).

# Google Directory

Google Directory (Admin SDK) holds the user accounts of Google Workspace. OctoXLabs reads the users and adds them to the user inventory.

## Use cases

* List the Google Workspace users that OctoXLabs collected.

```
Adapters = google-directory
```

* Check what one Google Directory connection collected.

```
Connections = YOUR_CONNECTION_NAME
```

## Before you begin

### Network

| Source              | Destination           | Port | Protocol |
| ------------------- | --------------------- | ---- | -------- |
| OctoXLabs connector | oauth2.googleapis.com | 443  | HTTPS    |
| OctoXLabs connector | admin.googleapis.com  | 443  | HTTPS    |

The port is not set in the connector code; HTTPS URLs use the default port 443.

### Required permissions

| Scope or role                                                                                  | Permission | Needed for                                    |
| ---------------------------------------------------------------------------------------------- | ---------- | --------------------------------------------- |
| `https://www.googleapis.com/auth/admin.directory.user.readonly` (domain-wide delegation scope) | Read       | Listing users                                 |
| Workspace administrator account to impersonate                                                 | Admin      | Delegated access (`sub` of the token request) |

See [Domain-wide delegation](https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority).

## Create credentials in Google Directory

{% stepper %}
{% step %}

### Create a service account and key

Create a service account on the [Service accounts page](https://console.cloud.google.com/iam-admin/serviceaccounts). Open it, go to **Keys**, select **Add key** > **Create new key**, choose **JSON** and download the file.
{% endstep %}

{% step %}

### Authorize domain-wide delegation

In the Admin console go to **Security** > **Access and data control** > **API controls** > **Manage Domain Wide Delegation** > **Add new**. Enter the service account Client ID and the scope `https://www.googleapis.com/auth/admin.directory.user.readonly`.
{% endstep %}

{% step %}

### Choose customer or domain

Decide whether to collect all users of the customer account (Customer Id) or the users of one domain (Domain Name). Use exactly one of them.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
The key file is the only copy of the private key. Store it securely. If it is lost, create a new key.
{% endhint %}

## Connection parameters

| Parameter                | Required | Type    | Default | Description                                                                                              |
| ------------------------ | -------- | ------- | ------- | -------------------------------------------------------------------------------------------------------- |
| Service account email    | Yes      | String  | None    | Email address of the service account.                                                                    |
| Service account key file | Yes      | File    | None    | The JSON key file of the service account.                                                                |
| Workspace admin email    | Yes      | String  | None    | User the application requests delegated access for.                                                      |
| Customer id              | No       | String  | None    | Unique ID of the Google Workspace customer account. Use it to fetch all users of a multi-domain account. |
| Domain name              | No       | String  | None    | Fetch users of this domain only.                                                                         |
| Timeout                  | No       | Integer | 30      | Time in seconds to wait for API responses.                                                               |

Exactly one of Customer id and Domain name must be set.

## Troubleshooting

| Error message                                                                                | Cause                                                                     | Fix                                                                                         |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| Exactly one of domain\_name or customer\_id must be provided.                                | Both or neither of Customer id and Domain name are set.                   | Set exactly one.                                                                            |
| You must specify domain\_name or customer\_id.                                               | Neither is set during discovery.                                          | Set one of them.                                                                            |
| 403 Forbidden (the connector logs `Forbidden, status code 403.` and raises the API response) | The service account does not have the required role or API access.        | Grant the role from the permissions table and check that the API is enabled in the project. |
| 429 Too Many Requests                                                                        | Google rate limit. The connector waits 60 seconds and retries.            | No action needed. Reduce the number of projects per connection if it happens often.         |
| 401 Unauthorized                                                                             | The access token expired. The connector requests a new token and retries. | If it keeps failing, check the service account email and key file.                          |

## Change history

{% hint style="info" %}
Available starting from version 5.5.0.
{% endhint %}
