Google Workspace delegation
Workwae checks and seals a service account key, then returns the client id and exact scopes to authorize.
A Google Workspace or Microsoft 365 administrator authorizes Workwae once, and each mailbox you add gets the same mail, calendar and contacts API.
// 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",
});# 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",
)
Accounts added through a connection sync and send like any other.
Workwae checks and seals a service account key, then returns the client id and exact scopes to authorize.
Your own app registration per cloud, with a client secret or a certificate and PKCS#8 key, or Workwae's with admin consent where we run one.
Worldwide (including GCC), GCC High, DoD or 21Vianet, with sign-in and Graph kept there.
Users 200 at a time, matched on the start of names and addresses, with any account already added.
Up to 100 addresses per call, each checked, then created, exists or failed with the reason.
Requests a token the way accounts will and reports each required or optional check.
A Microsoft 365 shared mailbox as its own account, through a user who can open it.
pending_consent until a Microsoft directory consents, unverified after a credential or scope change, then active or failing.
A missing optional permission limits only calendar, contacts or the directory, never mail.
Google tokens ask for every scope the connection lists, so one left out stops mail too.
A user sign-in can't take them over, and deleting the connection is refused with connection_in_use while any are live.
With Workwae's Microsoft app, the directory comes from the admin's own console sign-in and belongs to one connection.
Register the service account key, give the admin the client id and scopes, and test once they're authorized.
user you name.
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);
}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)
Walk the directory, skip mailboxes that are already accounts, and add the rest, with one result per address in request order.
externalRefexternal_ref per mailbox links
the account to your records.
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);
}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)
With your own app registration, send the administrator to a consent link that returns to your app.
status,
connection_id, error and your state, with the
directory recorded and the connection tested.
// 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",
});# 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",
)
| 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. |
| 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 |
| Event | When |
|---|---|
account. | A mailbox became an account; again with reauthorized: true when a passing test brings it back. |
account. | The connection's authorization was refused; reason carries the provider's refusal. |
account. | The first sync finished, with mailbox and message counts. |
account. | An account's status, settings or other fields changed. |
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.
No. Those accounts belong to the connection, so fix the connection, then test it.
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.
Workwae is in early access. Tell us what you are building, and read the docs in the meantime.