From 80ba726eca5070691d754dd718d8b23d0f2b4822 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Wed, 27 Dec 2023 00:13:27 +0100 Subject: [PATCH] oauth: add a generic method OAUTH to elect the best method * OAUTH pseudo method will elect either XOAUTH2 or OAUTHBEARER according to server's capabilities Signed-off-by: Edouard Vanbelle --- Sieve.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sieve.php b/Sieve.php index 44be84d..4a713be 100644 --- a/Sieve.php +++ b/Sieve.php @@ -226,7 +226,9 @@ class Net_Sieve * @param string $host Hostname of server. * @param string $port Port of server. * @param string $logintype Type of login to perform (see - * $supportedAuthMethods). + * $supportedAuthMethods), use `OAUTH` and lib + * will choose between OAUTHBEARER or XOAUTH2 + * according the server's capabilities. * @param string $euser Effective user. If authenticating as an * administrator, login as this user. * @param boolean $debug Whether to enable debugging (@see setDebug()). @@ -458,6 +460,17 @@ function login($user, $pass, $logintype = null, $euser = '', $bypassAuth = false } if (!$bypassAuth ) { + // special case of OAUTH, use the supported method + if ($logintype === 'OAUTH') { + $supported_logintypes = $this->_capability['sasl']; + foreach (['OAUTHBEARER', 'XOAUTH2'] as $logintype) { + if (in_array($logintype, $supported_logintypes)) { + break; + } + } + $this->_data['logintype'] = $logintype; + } + $res = $this->_cmdAuthenticate($user, $pass, $logintype, $euser); if (is_a($res, 'PEAR_Error')) { return $res;