meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:oauth2 [2022/11/19 08:40] – [Logging HTTP requests and responses] duncanc | plugin:oauth2 [2024/11/20 10:11] (current) – [Installation] duncanc | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== OAuth2 plugin ====== | ||
+ | |||
+ | ---- plugin ---- | ||
+ | |||
+ | description: | ||
+ | author | ||
+ | type : | ||
+ | lastupdate : 2022/11/08 21:19 | ||
+ | compatible : | ||
+ | depends | ||
+ | conflicts | ||
+ | similar | ||
+ | tags : | ||
+ | |||
+ | downloadurl: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Purpose ===== | ||
+ | |||
+ | This plugin uses OAuth2 to access the mailbox for processing bounces and for sending email using SMTP. | ||
+ | |||
+ | Currently it supports OAuth2 for Microsoft Office365 / Outlook and for Google Apps/Gmail. | ||
+ | |||
+ | ===== Installation ===== | ||
+ | |||
+ | The plugin requires php version 8 and phpList version 3.6.14 or later. You also need to enable Common Plugin before enabling this plugin. | ||
+ | |||
+ | Install this plugin using the package URL | ||
+ | https:// | ||
+ | |||
+ | |||
+ | ===== Configuration ===== | ||
+ | |||
+ | ==== Changes to config.php ==== | ||
+ | |||
+ | The OAuth2 Redirect URL is used to pass control back to the application, | ||
+ | |||
+ | <code php> | ||
+ | // for OAuth2 plugin | ||
+ | if (isset($_GET[' | ||
+ | ini_set(' | ||
+ | setcookie( | ||
+ | ' | ||
+ | $_COOKIE[' | ||
+ | [' | ||
+ | ); | ||
+ | session_start(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Use IMAP instead of POP3 === | ||
+ | The plugin uses a package, php-imap2, to retrieve emails from the mailbox. Unlike the php IMAP extension the package does not support POP3, only IMAP. Therefore the mailbox connection settings in config.php will probably need to be changed. For example for Gmail use | ||
+ | |||
+ | <code php> | ||
+ | $bounce_mailbox_host = ' | ||
+ | $bounce_mailbox_port = ' | ||
+ | </ | ||
+ | |||
+ | instead of | ||
+ | |||
+ | <code php> | ||
+ | $bounce_mailbox_port = ' | ||
+ | ==== The Settings page ==== | ||
+ | |||
+ | After enabling the plugin there will be an OAuth2 group on the Settings page. You need to enter the fields used when registering the application with Microsoft or Google | ||
+ | |||
+ | * Tenant Id (only for Microsoft) | ||
+ | * Client Id | ||
+ | * Client Secret | ||
+ | * Redirect URl - this needs to be the URL of a specific page provided by the plugin. | ||
+ | |||
+ | |||
+ | If phplist is installed in the default location then the Redirect URL will be similar to this, otherwise adjust for the actual location | ||
+ | https:// | ||
+ | |||
+ | |||
+ | === Redirect URL with Microsoft Azure === | ||
+ | |||
+ | Microsoft has restrictions on whether the redirect URL may contain query parameters, see [[https:// | ||
+ | |||
+ | If your account means query parameters in the redirect URL are not allowed then the default value shown above will be rejected when you try to add it within Azure. You will need to use an htaccess redirect rule to work-around this. | ||
+ | |||
+ | In Azure set the redirect URL to something similar to '' | ||
+ | |||
+ | < | ||
+ | # OAuth2 plugin | ||
+ | RewriteCond %{REQUEST_URI} | ||
+ | RewriteRule ^(.*)$ https:// | ||
+ | </ | ||
+ | |||
+ | === Use Oauth2 when sending using SMTP === | ||
+ | |||
+ | You can select to use OAuth2 verification, | ||
+ | |||
+ | Currently the plugin supports having an access token for only one email address, therefore that email address must be used for both sending and receiving emails if this setting is set to Yes. In the config.php file these two values would need to be the same | ||
+ | <code php> | ||
+ | $bounce_mailbox_user = ' | ||
+ | |||
+ | $phpmailer_smtpuser = ' | ||
+ | </ | ||
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | The plugin adds two pages to the System menu | ||
+ | |||
+ | **OAuth2 access token ** - this page shows an existing access token and its expiry time. You can sign-in to create a new access token or refresh the current token. | ||
+ | When you sign-in it must be with the email address used in config.php '' | ||
+ | |||
+ | **Process bounces using OAuth2** - this page will run the phplist processbounces page but will use the access token instead of a password. The php IMAP extension need not be enabled, although this page should work even when IMAP is enabled. | ||
+ | |||
+ | In the config.php file the value for '' | ||
+ | |||
+ | The page will refresh the access token if it has already expired. | ||
+ | |||
+ | The page can also be run from the command line | ||
+ | |||
+ | php / | ||
+ | | ||
+ | or as a remote page using curl or wget similar to this | ||
+ | |||
+ | curl ' | ||
+ | |||
+ | |||
+ | === Send emails using OAuth2 === | ||
+ | |||
+ | When the configuration setting is enabled, OAuth2 authentication will be used instead of password authentication when sending emails. | ||
+ | |||
+ | ===== Logging HTTP requests and responses ===== | ||
+ | |||
+ | The plugin can log the HTTP requests made and responses received. | ||
+ | |||
+ | Add the following to the config.php file (at the end of the file is ok) | ||
+ | |||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | ];</ | ||
+ | |||
+ | Now requests and responses will be logged to a file in the phplist temporary directory, identfied by the '' | ||
+ | |||
+ | Alternatively you can specify a particular directory for the log file. The directory must be writeable by the web server process. | ||
+ | |||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | ' | ||
+ | ];</ | ||
+ | |||
+ | Each query will be logged similar to this | ||
+ | |||
+ | < | ||
+ | [Fri 18 Nov 2022 15:22:07] [debug] GuzzleHttp\Promise\FulfilledPromise:: | ||
+ | Request GET https:// | ||
+ | [Fri 18 Nov 2022 15:22:07] [debug] GuzzleHttp\Promise\Promise:: | ||
+ | Response 200 {" | ||
+ | |||
+ | </ | ||
+ | |||
+ | To stop logging simply change '' | ||
+ | |||