Skip to content

[6.2] Add SMTP OAuth2 mailer support in Global Configuration (Microsoft/Google/Custom) / Replacement for #47656 (correct head branch)#47669

Open
dawe78 wants to merge 49 commits into
joomla:6.2-devfrom
dawe78:feature/oauth2-mail-6.2
Open

[6.2] Add SMTP OAuth2 mailer support in Global Configuration (Microsoft/Google/Custom) / Replacement for #47656 (correct head branch)#47669
dawe78 wants to merge 49 commits into
joomla:6.2-devfrom
dawe78:feature/oauth2-mail-6.2

Conversation

@dawe78

@dawe78 dawe78 commented Apr 23, 2026

Copy link
Copy Markdown

Summary of Changes

This PR adds SMTP OAuth2 support in Global Configuration for outgoing mail on 6.2-dev.

Implemented changes:

  • New mailer value: smtpoauth2
  • OAuth2 token issue/check flow in com_config
  • Provider support: Microsoft, Google, Custom
  • Microsoft tenant mode: common and tenant-specific
  • XOAUTH2 SMTP integration in mail factory
  • PHPCS/CS fixes in touched files

Important Clarification (Review Feedback)

The previous provider-specific legacy wrappers (m365auth, m365callback, m365checktoken) were removed/adjusted because there was no real historical route contract to preserve in core.

Security / Callback Flow Notes

  • OAuth flow is initiated from authenticated administrator context (com_config).
  • Callback state is validated against session (com_config.oauth2_state) using hash_equals.
  • If state/session is missing or invalid, callback exits with invalid token error.
  • Token persistence requires admin privileges (core.admin check) before writing config.

Testing Instructions

  1. Login to Administrator.
  2. Open Global Configuration -> Server/Mail settings.
  3. Set mailer to smtpoauth2.
  4. Configure provider credentials for one provider:
  5. Microsoft (common tenant)
  6. Microsoft (specific tenant)
  7. Google
  8. Custom
  9. Click token issue button and complete provider consent.
  10. Verify redirect returns to admin config and token timestamp is set.
  11. Run token validation action.
  12. Send test mail from Global Configuration.
  13. Repeat for at least one additional provider profile.

Expected Result

  • OAuth flow completes only with valid admin session + valid state.
  • Refresh token is saved successfully.
  • Token check reports valid access token response.
  • SMTP test mail works with XOAUTH2 configuration.
  • CI style checks pass.

Actual Result

  • Behavior matches expected result for tested provider configurations.
  • 6.2 PR now uses correct head branch and updated formatting/documentation.

Documentation Changes

This PR description now documents:

  • callback auth/session assumptions
  • state validation behavior
  • required test flow for provider scenarios

AI Disclosure

AI assistance was used to help draft/refine parts of implementation and PR text.
All code, behavior, and security assumptions were manually reviewed and tested by the author before submission.

Comment thread administrator/components/com_config/src/Controller/ApplicationController.php Outdated
@Hackwar

Hackwar commented Apr 23, 2026

Copy link
Copy Markdown
Member

Please fill out the PR form correctly, especially the AI disclaimer. Also please format your text correctly. Right now the description is hardly readable.

Why do you have custom routes for the different providers as legacy fallback, when they never existed in the first place? Your docblocks are incomplete. How do those callbacks against the admin com_config work, when the calling provider is not an authorised user? Seems to me as if that would fail. This needs at least documentation on how to use and test in this PR.

@dawe78

dawe78 commented Apr 23, 2026

Copy link
Copy Markdown
Author

Please fill out the PR form correctly, especially the AI disclaimer. Also please format your text correctly. Right now the description is hardly readable.

Okay, done. Code changes will be pulled soon

Comment thread administrator/components/com_config/forms/application.xml Outdated
Comment thread administrator/components/com_config/forms/application.xml Outdated
Comment thread administrator/components/com_config/forms/application.xml Outdated
Comment thread administrator/components/com_config/src/Helper/ConfigHelper.php Outdated
Comment thread administrator/components/com_config/src/Helper/ConfigHelper.php Outdated
Comment thread administrator/language/en-GB/com_config.ini Outdated
Comment thread administrator/language/en-GB/com_config.ini Outdated
Comment thread administrator/language/en-GB/com_config.ini Outdated
Comment thread libraries/src/Mail/SmtpOAuth2TokenProvider.php Outdated
@dawe78 dawe78 requested review from Hackwar and brianteeman April 23, 2026 12:11
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Model/ApplicationModel.php Outdated
Comment thread administrator/components/com_config/src/Model/ApplicationModel.php Outdated
@dawe78

dawe78 commented May 9, 2026

Copy link
Copy Markdown
Author

Addressed in latest commit; thread outdated.

Comment thread administrator/components/com_config/src/Controller/RequestController.php Outdated
Comment thread administrator/components/com_config/src/Field/Oauth2TokenField.php Outdated
@dawe78

dawe78 commented May 10, 2026

Copy link
Copy Markdown
Author

Added layout file for oauth2token field

Comment thread administrator/components/com_config/src/Helper/ConfigHelper.php Outdated
@dawe78

dawe78 commented May 18, 2026

Copy link
Copy Markdown
Author

All review points addressed, CI green, ready for merge.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@dawe78 dawe78 force-pushed the feature/oauth2-mail-6.2 branch from 8f96f5e to 0593f19 Compare May 27, 2026 12:29
@dawe78

dawe78 commented May 28, 2026

Copy link
Copy Markdown
Author

System tests failed broadly across unrelated areas (Cypress, 36/156). Re-running CI as likely infra/flaky failure.

Comment thread administrator/language/en-GB/com_config.ini
Comment thread administrator/language/en-GB/com_config.ini Outdated
@QuyTon

QuyTon commented May 28, 2026

Copy link
Copy Markdown
Contributor

Missing language strings.

47669-smtp-oauth2-strings 47669-smtp-oauth2-strings2

@brianteeman

Copy link
Copy Markdown
Contributor

numerous codestyle issues with the xml have been marked as resolved but they have not been

- Add missing language strings used by oauth2token layout and application.xml
  (BUTTON_CHECK, BUTTON_ISSUE, BUTTON_REISSUE, OAUTH2_TENANT_MODE_COMMON/TENANT)
- Revert accidental re-sorting of existing language keys; restore deleted
  WEBSERVICES_CORS_OFF_* strings; all new OAuth2 keys inserted at correct
  alphabetical positions within upstream ordering
- Fix XML closing > indentation on oauth2_provider, oauth2_tenant_mode and
  oauth2_smtp_secure fields (3 tabs to match surrounding code style)
- Use Uri::base() instead of hardcoded Uri::root().'administrator/' in
  ConfigHelper::getOAuth2CallbackUrl() to support renamed admin directories
- Remove unused $params variable in RequestController::oauth2auth()
- Replace Factory::getApplication() with $this->app in oauth2callback()
  and remove now-unused Factory import
@dawe78

dawe78 commented May 28, 2026

Copy link
Copy Markdown
Author

Fixed — added COM_CONFIG_MAIL_OAUTH2_BUTTON_CHECK, _BUTTON_ISSUE, _BUTTON_REISSUE, COM_CONFIG_OAUTH2_TENANT_MODE_COMMON and _TENANT.

@dawe78

dawe78 commented May 28, 2026

Copy link
Copy Markdown
Author

numerous codestyle issues with the xml have been marked as resolved but they have not been

Fixed — the closing > on oauth2_provider, oauth2_tenant_mode and oauth2_smtp_secure fields now uses 3-tab indentation consistent with the surrounding code.

@dawe78

dawe78 commented May 28, 2026

Copy link
Copy Markdown
Author

@Hackwar @brianteeman All review findings have been addressed in the latest commits. Could you please take another look?

Summary of changes since last review:

Added missing language strings (BUTTON_CHECK, BUTTON_ISSUE, BUTTON_REISSUE, OAUTH2_TENANT_MODE_COMMON/TENANT)
Reverted accidental re-sorting of existing language keys; restored accidentally deleted WEBSERVICES_CORS_OFF_* strings
Fixed XML closing > indentation (3 tabs) on the 3 new list fields
Replaced hardcoded Uri::root().'administrator/' with Uri::base() in ConfigHelper
Removed unused $params variable and replaced Factory::getApplication() with $this->app
All CI checks pass (Windows integration test flakiness re-triggered via empty commit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Language Change This is for Translators PR-6.2-dev

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants