Skip to content

Commit

Permalink
Merge pull request #11 from EdouardVanbelle/feat/select-oauth-method
Browse files Browse the repository at this point in the history
oauth: add a generic method OAUTH to choose automatically a supported method
  • Loading branch information
alecpl authored Dec 29, 2023
2 parents 9116517 + 80ba726 commit d3c7c6b
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 d3c7c6b

Please sign in to comment.