Repository navigation
feat: support Microsoft Entra ID OAuth 2.0 for SMTP providers - #15810
Harshit-2208 wants to merge 4 commits into
Conversation
Code review
Adds Microsoft Entra ID client-credentials authentication to SMTP providers, including access-token caching and XOAUTH2 authentication. Extends the SMTP provider APIs and adapter factory with OAuth credentials, redacts client secrets, and adds package, API, and response-model tests. The update API also supports clearing OAuth credentials to return to Basic Auth. Latest changes: The latest commits allow explicitly clearing all OAuth credentials during an SMTP provider update and include HTTP status and OAuth error details in token-fetch exceptions, with regression tests for transient 503 responses. Note @Harshit-2208 does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve. Walkthrough (9)
Fixed since the last review (4)
Merged Tip Comment |

What does this PR do?
Adds support for Microsoft Entra ID (Azure AD) OAuth 2.0 (
client_credentialsflow +AUTH XOAUTH2) to Appwrite's SMTP email provider so organizations can send transactional emails through Microsoft 365 without relying on basic username/password SMTP authentication.Summary of Changes
packages/messaging(Utopia\Messaging\Adapter\Email\SMTP):$clientId,$clientSecret, and$tenantIdparameters toSMTP::__construct().fetchAccessToken()to request and cache short-lived OAuth 2.0 Bearer tokens fromhttps://login.microsoftonline.com/{tenantId}/oauth2/v2.0/tokenusing thehttps://outlook.office365.com/.defaultscope (with a 60-second expiry safety buffer).authenticators()to authenticate viaUtopia\SMTP\Auth\XOAuth2when OAuth credentials are configured, while preserving existingPLAIN/LOGINauthentication when using Basic Auth.src/Appwrite/):clientId,clientSecret, andtenantIdparameters tocreateSMTPProviderandupdateSMTPProvider, validating that partial OAuth configurations are rejected with400 general_argument_invalid.Utopia\Messaging\Adapter\Email\SMTPinAppwrite\Messaging\Provider::email().clientSecrettoAppwrite\Utopia\Response\Model\Provider::filter()so secrets are redacted from API responses.app/config/sdks/parameters.lock.jsonfor the new optional parameters.packages/messaging/tests/Adapter/Email/SMTPOAuthTest.phpcovering token acquisition, caching, expiry refresh, error handling, andPLAINfallback.tests/unit/Utopia/Response/Model/ProviderTest.phpto verifyclientSecretredaction.tests/e2e/Services/Messaging/MessagingBase.phpfor creating and updating SMTP providers with Entra ID OAuth 2.0 credentials.Configuration Note for Microsoft 365 Administrators
To use this with Microsoft 365 (
smtp.office365.comon port587with TLS):SMTP.SendAsAppapplication permission (Office 365 Exchange Online).New-ServicePrincipal) and grant itSendAsorFullAccesspermission on the target sender mailbox.username, along withclientId,clientSecret, andtenantId.Test Plan
SMTPOAuthTest: Verified OAuth token request format,AUTH XOAUTH2handshake againstScriptedSmtpServer, token caching/refresh behavior, and Basic Auth fallback.ProviderTest: VerifiedclientSecretis stripped from API responses whileclientIdandtenantIdremain visible.MessagingBase: Added E2E tests coveringPOST /v1/messaging/providers/smtpandPATCH /v1/messaging/providers/smtp/:providerIdwith valid and partial Entra ID OAuth credentials.Related PRs and Issues
Closes #15482
Checklist