---
title: "Organization connections · Workwae"
description: "Connect a whole Google Workspace or Microsoft 365 organization: domain-wide delegation, app-only access in any Microsoft cloud and shared mailboxes."
url: https://workwae.com/features/organizations
---

1. [Features](https://workwae.com/features/)
2. Organization connections

Organization connections

# Connect a whole organization, without asking every user.

A Google Workspace or Microsoft 365 administrator authorizes Workwae once, and each mailbox you add gets the same mail, calendar and contacts API.

[Request early access](https://workwae.com/early-access/) [API reference](https://docs.workwae.com/reference/organization-connections)

contoso.tscontoso.py

```ts
// Your own Entra app, signed with a certificate
const connection = await workwae.orgConnections.create({
  kind: "microsoft_app",
  name: "Contoso",
  cloud: "global",
  credential: {
    type: "certificate",
    clientId,
    certificate,
    privateKey,
  },
  directoryId,
});

// Request a token the way accounts will
const { checks } = await workwae.orgConnections.test({
  connectionId: connection.id,
});

// Pick mailboxes from the directory
const page = await workwae.orgConnections.directoryEntries({
  connectionId: connection.id,
  query: "sales",
});
```

```python
# Your own Entra app, signed with a certificate
connection = workwae.org_connections.create(
    kind="microsoft_app",
    name="Contoso",
    cloud="global",
    credential={
        "type": "certificate",
        "client_id": client_id,
        "certificate": certificate,
        "private_key": private_key,
    },
    directory_id=directory_id,
)

# Request a token the way accounts will
tested = workwae.org_connections.test(connection_id=connection.id)

# Pick mailboxes from the directory
page = workwae.org_connections.directory_entries(
    connection_id=connection.id,
    query="sales",
)
```

What you get

## Organization-wide access, with the checks built in.

Accounts added through a connection sync and send like any other.

### Google Workspace delegation

Workwae checks and seals a service account key, then returns the client id and exact scopes to authorize.

### Microsoft 365 app-only access

Your own app registration per cloud, with a client secret or a certificate and PKCS#8 key, or Workwae's with [admin consent](https://workwae.com/glossary#admin-consent) where we run one.

### Every Microsoft cloud

Worldwide (including GCC), [GCC High](https://workwae.com/glossary#gcc-high), [DoD](https://workwae.com/glossary#dod) or 21Vianet, with sign-in and Graph kept there.

### Directory listing

Users 200 at a time, matched on the start of names and addresses, with any account already added.

### Add mailboxes in bulk

Up to 100 addresses per call, each checked, then `created`, `exists` or `failed` with the reason.

### A test that names what's missing

Requests a token the way accounts will and reports each required or optional check.

### Shared mailboxes

A Microsoft 365 shared mailbox as its own account, through a user who can open it.

### Connection status

`pending_consent` until a Microsoft directory consents, `unverified` after a credential or scope change, then `active` or `failing`.

### Optional means optional

A missing optional permission limits only calendar, contacts or the directory, never mail.

### Authorize every listed scope

Google tokens ask for every scope the connection lists, so one left out stops mail too.

### The connection owns its accounts

A user sign-in can't take them over, and deleting the connection is refused with `connection_in_use` while any are live.

### Consent bound to the sign-in

With Workwae's Microsoft app, the directory comes from the admin's own console sign-in and belongs to one connection.

[All features](https://workwae.com/features/)

Build it

## Set up Google Workspace delegation

Register the service account key, give the admin the client id and scopes, and test once they're authorized.

- **Scopes come back in the Admin console's order**, ready to paste.
- **Calendar is on and contacts off by default.** Leaving one out stops only that sync.
- **A directory admin is optional.** Without one, add mailboxes by address; tests impersonate the `user` you name.

workspace.tsworkspace.py

```ts
const connection = await workwae.orgConnections.create({
  kind: "google_delegation",
  name: "Acme Workspace",
  domain: "acme.com",
  serviceAccountKey, // the JSON key file
  calendarEnabled: true,
  contactsEnabled: true,
  directoryAdmin: "it-admin@acme.com",
});

// For the admin: Security > API controls > Domain-wide delegation
showAdmin(connection.clientId, connection.google?.scopes);

// After they authorize it, test as the directory admin
const result = await workwae.orgConnections.test({
  connectionId: connection.id,
});
for (const check of result.checks) {
  if (!check.isOk) console.warn(check.name, check.detail);
}
```

```python
connection = workwae.org_connections.create(
    kind="google_delegation",
    name="Acme Workspace",
    domain="acme.com",
    service_account_key=service_account_key,  # the JSON key file
    calendar_enabled=True,
    contacts_enabled=True,
    directory_admin="it-admin@acme.com",
)

# For the admin: Security > API controls > Domain-wide delegation
show_admin(connection.client_id, connection.google.scopes if connection.google else None)

# After they authorize it, test as the directory admin
result = workwae.org_connections.test(connection_id=connection.id)
for check in result.checks:
    if not check.is_ok:
        print(check.name, check.detail)
```

Build it

## Add the mailboxes you need

Walk the directory, skip mailboxes that are already accounts, and add the rest, with one result per address in request order.

- **Checked first:** a delegated token for Google, the inbox for Microsoft.
- **Failures say why:** no such user, scopes not granted, no mailbox access, or the plan's account limit.
- **Bring your own ids.** An `externalRef``external_ref` per mailbox links the account to your records.

add-mailboxes.tsadd-mailboxes.py

```ts
import { paginate } from "@workwae/sdk";

const listDirectory = workwae.orgConnections.directoryEntries;
const query = { connectionId, query: "support" };

const mailboxes = [];
for await (const entry of paginate(listDirectory, query)) {
  if (entry.accountId) continue; // already an account
  const { email, id: externalRef } = entry;
  mailboxes.push({ email, externalRef });
}

const { items } = await workwae.orgConnections.addAccounts({
  connectionId,
  mailboxes,
});
for (const added of items) {
  if (added.status !== "failed") continue;
  // e.g. invalid_grant (no such user) or consent_revoked
  console.warn(added.email, added.error?.reason);
}
```

```python
from workwae import paginate
from workwae.types import AddMailboxInputParam

entries = paginate(
    workwae.org_connections.directory_entries,
    connection_id=connection_id,
    query="support",
)

mailboxes: list[AddMailboxInputParam] = []
for entry in entries:
    if entry.account_id:
        continue  # already an account
    mailboxes.append({"email": entry.email, "external_ref": entry.id})

added = workwae.org_connections.add_accounts(
    connection_id=connection_id,
    mailboxes=mailboxes,
)
for item in added.items:
    if item.status != "failed":
        continue
    # e.g. invalid_grant (no such user) or consent_revoked
    print(item.email, item.error.reason if item.error else None)
```

Build it

## Admin consent and shared mailboxes

With your own app registration, send the administrator to a consent link that returns to your app.

- **The return names the outcome:** `status`, `connection_id`, `error` and your `state`, with the directory recorded and the connection tested.
- **Workwae's own app** is consented from the console, by the administrator who signed in.
- **Shared mailboxes** need only a user's grant with shared mailbox access; Gmail has none, so use domain-wide delegation there.

consent.tsconsent.py

```ts
// Your own app registration, in GCC High
const connection = await workwae.orgConnections.create({
  kind: "microsoft_app",
  name: "Contoso (GCC High)",
  cloud: "gcc-high",
  credential: { type: "client_secret", clientId, clientSecret },
});

// Send the administrator here
const { consentUrl } = await workwae.orgConnections.consent({
  connectionId: connection.id,
  redirectUri: "https://app.example.com/admin/consent-done",
  state: tenantRef,
});

// A shared mailbox, through a user's own grant
const billing = await workwae.sharedMailboxes.create({
  accountId: userAccountId,
  email: "billing@contoso.us",
});
```

```python
# Your own app registration, in GCC High
connection = workwae.org_connections.create(
    kind="microsoft_app",
    name="Contoso (GCC High)",
    cloud="gcc-high",
    credential={"type": "client_secret", "client_id": client_id, "client_secret": client_secret},
)

# Send the administrator here
consent = workwae.org_connections.consent(
    connection_id=connection.id,
    redirect_uri="https://app.example.com/admin/consent-done",
    state=tenant_ref,
)

# A shared mailbox, through a user's own grant
billing = workwae.shared_mailboxes.create(
    account_id=user_account_id,
    email="billing@contoso.us",
)
```

Reference

## Details and questions administrators ask.

**Access methods compared**

Organization access methods compared

| Aspect | Google Workspace delegation | Microsoft 365 app-only | Microsoft 365 shared mailbox |
| --- | --- | --- | --- |
| Who authorizes | A Workspace admin, for the service account's client id and the connection's scopes. | A directory administrator, by admin consent. | A user who can open the mailbox, connected with `options.sharedMailboxesEnabled`. |
| Credential | The sealed service account key; each token is a signed assertion for one mailbox. | Your own app registration per cloud, with a client secret or a certificate, or Workwae's where we run one. | The delegating user's own grant. |
| Scopes and permissions | `gmail.modify` always; `calendar` by default; `contacts` when you choose; `admin.directory.user.readonly` with a directory admin. | Required: `Mail.ReadWrite`, `Mail.Send`. Optional: `Calendars.ReadWrite`, `MailboxSettings.Read`, `Contacts.ReadWrite`, `User.Read.All`. | `Mail.ReadWrite.Shared` and `Mail.Send.Shared`, plus `Calendars.ReadWrite.Shared` and `Contacts.ReadWrite.Shared` for calendar and contacts. |
| Directory | The Admin SDK user list, read as the directory admin you name, only when you ask. | Graph's user list, with `User.Read.All`. | Not applicable |
| How the mailbox is reached | Gmail, Calendar and People, as for any Google account. | Graph as `/users/{mailbox}`, change notifications included. | Graph as `/users/{mailbox}`, or Exchange IMAP as `user@domain\shared`. |
| When access is withdrawn | Google refuses the token: `reauth_required` with `consent_revoked`. | A token without `Mail.ReadWrite`: `consent_revoked`. | The delegating account is deleted: `reauth_required` with `delegate_missing`. |

**Microsoft clouds and endpoints**

Microsoft clouds and their endpoints

| Cloud | Covers | Sign-in | Graph |
| --- | --- | --- | --- |
| `global` | Worldwide Microsoft 365, including GCC | `login.microsoftonline.com` | `graph.microsoft.com` |
| `gcc-high` | US Government GCC High | `login.microsoftonline.us` | `graph.microsoft.us` |
| `dod` | US Government DoD | `login.microsoftonline.us` | `dod-graph.microsoft.us` |
| `china` | Microsoft 365 operated by 21Vianet | `login.chinacloudapi.cn` | `microsoftgraph.chinacloudapi.cn` |

- Tokens don't cross clouds, and each cloud needs its own app registration; yours works in any cloud.
- Where a national cloud lacks change notifications, the scheduled poll keeps accounts current.
- In 21Vianet, Graph has no message delta yet, so mail runs over IMAP and SMTP with a user's Microsoft sign-in.

**Account events**

Account events for organization connections

| Event | When |
| --- | --- |
| `account.connected` | A mailbox became an account; again with `reauthorized: true` when a passing test brings it back. |
| `account.reauth_required` | The connection's authorization was refused; `reason` carries the provider's refusal. |
| `account.initialized` | The first sync finished, with mailbox and message counts. |
| `account.updated` | An account's status, settings or other fields changed. |

**What happens if the administrator removes access?**

The affected accounts move to `reauth_required` with `consent_revoked`, and the next test marks the connection `failing`. Once access is restored, a passing test returns them to active and announces them again.

**Can a user fix a stopped connection account by signing in?**

No. Those accounts belong to the connection, so fix the connection, then test it.

**Why is consent to Workwae's Microsoft app started from the console?**

The app is shared by every customer, so the directory is recorded only from the administrator's own sign-in in that console session, and a forwarded link attaches nothing. With your own app registration, you can start consent through the API.

Early access

## Bring a whole organization in at once.

Workwae is in early access. Tell us what you are building, and read the docs in the meantime.

[Request early access](https://workwae.com/early-access/) [Read the docs](https://docs.workwae.com/)
