Skip to content

Commit

Permalink
oauth: add a generic method OAUTH to elect the best method
Browse files Browse the repository at this point in the history
   * OAUTH pseudo method will elect either XOAUTH2 or OAUTHBEARER according to server's capabilities

Signed-off-by: Edouard Vanbelle <[email protected]>
  • Loading branch information
EdouardVanbelle committed Dec 27, 2023
1 parent 9116517 commit 80ba726
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()).
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 80ba726

Please sign in to comment.