Skip to content

Conversation

@hnolde
Copy link

@hnolde hnolde commented Oct 22, 2025

This pull request adds comprehensive support for SMTP OAuth2 (XOAUTH2) authentication, enabling the system to send emails via providers that require OAuth2 (like Gmail). It introduces new configuration options, admin panel endpoints, and user interface controls for managing OAuth2 tokens and authorization flows. The implementation includes secure handling of OAuth2 state for CSRF protection, token caching, and robust validation of configuration parameters.

SMTP OAuth2 (XOAUTH2) Support

  • Added new configuration options for OAuth2, including smtp_oauth2_client_id, smtp_oauth2_client_secret, smtp_oauth2_auth_url, smtp_oauth2_token_url, smtp_oauth2_refresh_token, and smtp_oauth2_scopes. These allow the system to be configured for OAuth2-based SMTP authentication.
  • Implemented validation logic to ensure all required OAuth2 parameters are set and correctly formatted when XOAUTH2 is enabled, including checks for valid URLs and required fields. [1] [2]

Backend OAuth2 Flow and Token Management

  • Introduced OAuth2 authorization endpoints (/admin/oauth2/authorize and /admin/oauth2/callback) and a token refresh endpoint (/admin/test/oauth2) in the admin API, including secure state storage for CSRF protection during the OAuth2 flow. [1] [2] [3] [4]
  • Added logic to exchange authorization codes for refresh tokens, persist them in configuration, and refresh access tokens as needed, with token caching to minimize unnecessary requests. [1] [2]

SMTP Transport and Authentication Logic

  • Modified SMTP transport logic to support OAuth2: when configured, the system uses the OAuth2 access token as the SMTP password, falling back to traditional authentication if necessary, and preferring OAuth2 when both are present. [1] [2]

Admin UI Enhancements

  • Added UI controls and JavaScript handlers to the admin settings page for initiating OAuth2 authorization and refreshing tokens, with checks to prevent actions if unsaved config changes are present. [1] [2]

General Improvements

  • Made update_config_partial public to allow saving OAuth2 tokens from the OAuth2 callback handler.
  • Added a convenience From<&str> implementation for the Error type to simplify error handling.

Copy link
Collaborator

@BlackDex BlackDex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick glance on it and have some notes.
Need to look better at the code, but no time right now.

@hnolde hnolde requested a review from BlackDex October 22, 2025 13:30
@BlackDex
Copy link
Collaborator

Sorry, didn't had much time to check and verify this PR yet in detail. I still have it on my list.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants