From a26014064ff72e61832813c8677b6609798e5c6f Mon Sep 17 00:00:00 2001 From: Jeff Standen Date: Fri, 9 May 2025 17:29:17 -0700 Subject: [PATCH] Implemented XOAUTH2 authentication for POP3 --- lib/Horde/Imap/Client/Socket/Pop3.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Horde/Imap/Client/Socket/Pop3.php b/lib/Horde/Imap/Client/Socket/Pop3.php index 68382428d..d5d02f59c 100644 --- a/lib/Horde/Imap/Client/Socket/Pop3.php +++ b/lib/Horde/Imap/Client/Socket/Pop3.php @@ -270,6 +270,12 @@ protected function _login() $auth_mech = array($this->_init['authmethod']); } + // Always try XOAUTH2 first when defined + if (in_array('XOAUTH2', $auth_mech) && $this->getParam('xoauth2_token')) { + $auth_mech = array_diff($auth_mech, ['XOAUTH2']); + array_unshift($auth_mech, 'XOAUTH2'); + } + foreach ($auth_mech as $method) { try { $this->_tryLogin($method); @@ -405,6 +411,18 @@ protected function _tryLogin($method) )); break; + case 'XOAUTH2': + if (!($xoauth2_token = $this->getParam('xoauth2_token'))) + throw new Horde_Imap_Client_Exception("Expected an XOAUTH2 token"); + + /* @var Horde_Imap_Client_Password_Xoauth2 $xoauth2_token */ + + $this->_sendLine('AUTH XOAUTH2'); + $this->_sendLine($xoauth2_token->getPassword(), array( + 'debug' => sprintf('AUTH XOAUTH2 [Auth Response (username: %s)]', $xoauth2_token->username) + )); + break; + case 'APOP': /* If UTF8 (+ USER) is active, and non-ASCII exists, need to apply * SASLprep to username/password. RFC 6856[2.2]. Reject if