Google and Microsoft OAuth
Register Google and Microsoft OAuth apps for sign-in and mailbox connections on your own instance.
Self-hosted instances use their own OAuth apps. One app per provider covers sign-in, mailbox connections and members’ own mail accounts. Without them, password sign-in, forwarding, SMTP and IMAP mailboxes, and IMAP mail accounts still work.
Gmail mailbox connections can also use a separate Google client, for example in its own Google Cloud project while its Gmail scope is reviewed: set GOOGLE_MAILBOX_CLIENT_ID and GOOGLE_MAILBOX_CLIENT_SECRET, and register only the mailbox redirect URI on it. Microsoft mailbox connections can likewise use their own Entra app with MICROSOFT_MAILBOX_CLIENT_ID and MICROSOFT_MAILBOX_CLIENT_SECRET; Microsoft sign-in then stays off unless MICROSOFT_CLIENT_ID is set too.
Redirect URIs
Section titled “Redirect URIs”Register these, with API_URL exactly as configured (on a single domain, your site URL):
API_URL/v1/auth/oauth/{provider}/callback sign-inAPI_URL/v1/mailboxes/oauth/{provider}/callback mailbox connectionsAPI_URL/v1/collab/accounts/oauth/{provider}/callback mail accountsFor API_URL=https://desk.example.com:
| Provider | Redirect URIs |
|---|---|
https://desk.example.com/v1/auth/oauth/google/callback, https://desk.example.com/v1/mailboxes/oauth/google/callback, https://desk.example.com/v1/collab/accounts/oauth/google/callback |
|
| Microsoft | https://desk.example.com/v1/auth/oauth/microsoft/callback, https://desk.example.com/v1/mailboxes/oauth/microsoft/callback, https://desk.example.com/v1/collab/accounts/oauth/microsoft/callback |
Leave out the mail accounts URI if no one on your instance connects their own Google or Microsoft account.
Scopes
Section titled “Scopes”A mailbox connection sends replies from the mailbox, and its mail comes in by forwarding. With receiving over IMAP on (MAILBOX_IMAP, the default), a connection can instead sync the mailbox, which asks for more.
| Provider | Sign-in | Mailbox, send-only | Mailbox, sync (IMAP) |
|---|---|---|---|
openid, email, profile |
openid, email, https://www.googleapis.com/auth/gmail.send |
openid, email, https://mail.google.com/ |
|
| Microsoft | openid, email, profile |
openid, email, offline_access, https://graph.microsoft.com/Mail.Send, https://graph.microsoft.com/User.Read |
the same, plus https://outlook.office.com/IMAP.AccessAsUser.All |
Mailbox connections use PKCE and request offline access, so opendesk keeps working after the person who connected closes the browser. If no one on your instance syncs mailboxes, register only the send-only scopes.
-
Open the Google Cloud console and create (or pick) a project.
-
Go to APIs & Services → Library, search for Gmail API and click Enable. (Only needed for mailbox connections: replies are sent through it.)
-
Go to Google Auth Platform → Branding (formerly OAuth consent screen). Enter the app name, support email, your domain under Authorized domains, and links to your privacy policy and terms.
-
Under Audience, choose Internal if everyone who connects a mailbox is in your Google Workspace organization. Choose External otherwise.
-
Under Data Access, add the scopes
openid,.../auth/userinfo.email,.../auth/userinfo.profileand, for mailboxes,.../auth/gmail.send. Addhttps://mail.google.com/only if mailboxes will sync over IMAP, and.../auth/gmail.modifyand.../auth/gmail.settings.basiconly for mail accounts. -
Go to Clients → Create client. Choose Web application, give it a name, and add the Google redirect URIs above under Authorized redirect URIs. Click Create.
-
Copy the client id and secret into
.envand restart opendesk:Terminal window GOOGLE_CLIENT_ID=1234567890-abc.apps.googleusercontent.comGOOGLE_CLIENT_SECRET=GOCSPX-...
Microsoft
Section titled “Microsoft”-
Open the Microsoft Entra admin center → Identity → Applications → App registrations → New registration.
-
Enter a name. Under Supported account types, choose who may sign in:
- Accounts in this organizational directory only for one tenant (set
MICROSOFT_TENANTto your tenant id) - Accounts in any organizational directory and personal Microsoft accounts for everyone (keep
MICROSOFT_TENANT=common)
- Accounts in this organizational directory only for one tenant (set
-
Under Redirect URI, choose Web and enter the sign-in redirect URI. Click Register. Then open Authentication and add the mailbox redirect URI, and the mail accounts one if you use it, as further Web URIs.
-
Open Certificates & secrets → New client secret. Copy the secret value (not its id) now; it is shown once. Note its expiry and rotate it before then.
-
Open API permissions → Add a permission:
- Microsoft Graph → Delegated:
openid,email,profile,offline_access,User.Read,Mail.Send - Only if mailboxes will sync over IMAP: APIs my organization uses → search Office 365 Exchange Online → Delegated:
IMAP.AccessAsUser.All - Only for mail accounts: Microsoft Graph → Delegated:
Mail.ReadWrite,MailboxSettings.ReadWrite
For a single organization, click Grant admin consent so members are not asked individually.
- Microsoft Graph → Delegated:
-
Copy the Application (client) ID from Overview and the secret into
.env, then restart opendesk:Terminal window MICROSOFT_CLIENT_ID=00000000-0000-0000-0000-000000000000MICROSOFT_CLIENT_SECRET=...MICROSOFT_TENANT=common
A Microsoft app used by people outside your organization should have a verified publisher: under Branding & properties, set the publisher domain and link a Microsoft partner account, so the consent screen shows your name as verified.
Mailboxes that sync through Microsoft read mail over IMAP, so IMAP must be enabled for each of them in Microsoft 365. See Microsoft 365 and Outlook.
Mail accounts
Section titled “Mail accounts”Collab lets members connect their own Google and Microsoft accounts, private or shared with the team. Connect a mail account offers Google and Microsoft only once the instance has a client for them; until then it offers Other (IMAP) alone (while COLLAB_IMAP is on).
Mail accounts use the mailbox clients (GOOGLE_MAILBOX_CLIENT_ID, MICROSOFT_MAILBOX_CLIENT_ID, which default to the sign-in clients) unless you give them their own, for example a Google project of its own while its restricted scope is reviewed:
COLLAB_GOOGLE_CLIENT_ID=1234567890-def.apps.googleusercontent.comCOLLAB_GOOGLE_CLIENT_SECRET=...COLLAB_MICROSOFT_CLIENT_ID=00000000-0000-0000-0000-000000000000COLLAB_MICROSOFT_CLIENT_SECRET=...Whichever client they use needs the mail accounts redirect URI above and these scopes:
| Provider | Mail accounts |
|---|---|
openid, email, profile, https://www.googleapis.com/auth/gmail.modify, https://www.googleapis.com/auth/gmail.settings.basic, with the Gmail API enabled |
|
| Microsoft | openid, email, offline_access, https://graph.microsoft.com/Mail.ReadWrite, https://graph.microsoft.com/Mail.Send, https://graph.microsoft.com/User.Read, https://graph.microsoft.com/MailboxSettings.ReadWrite |
gmail.settings.basic and MailboxSettings.ReadWrite keep each account’s signature, From name and automatic replies in sync; an account connected without them still syncs its mail. When the Collab clients differ from the mailbox clients, also register the mailbox redirect URI on them: support mailboxes that read their inbox directly sign in with the Collab clients.
See Collab for COLLAB and COLLAB_IMAP.
GitHub and OIDC sign-in
Section titled “GitHub and OIDC sign-in”These are for sign-in only.
- GitHub: create an OAuth app under Settings → Developer settings → OAuth Apps with the callback
API_URL/v1/auth/oauth/github/callback, then setGITHUB_CLIENT_IDandGITHUB_CLIENT_SECRET. It requestsread:useranduser:email. - OIDC: register a web client with your identity provider with the redirect URI
API_URL/v1/auth/oauth/oidc/callbackand scopesopenid email profile, then setOIDC_ISSUER(the issuer your provider advertises; a trailing slash may be left on or off),OIDC_CLIENT_ID,OIDC_CLIENT_SECRETand optionallyOIDC_NAMEfor the button label.
Federated identities are bound by issuer and subject. If someone signs in with a provider using the email of an existing password account, the accounts are linked only after the password is entered.