diff --git a/Sieve.php b/Sieve.php index 26e02f7..44be84d 100644 --- a/Sieve.php +++ b/Sieve.php @@ -101,7 +101,8 @@ class Net_Sieve 'PLAIN' , 'LOGIN', 'GSSAPI', - 'XOAUTH2' + 'XOAUTH2', + 'OAUTHBEARER' ); /** @@ -703,6 +704,9 @@ function _cmdAuthenticate($uid, $pwd, $userMethod = null, $euser = '') case 'XOAUTH2': $result = $this->_authXOAUTH2($uid, $pwd, $euser); break; + case 'OAUTHBEARER': + $result = $this->_authOAUTHBEARER($uid, $pwd, $euser); + break; default : $result = $this->_pear->raiseError( $method . ' is not a supported authentication method' @@ -946,6 +950,29 @@ function _authXOAUTH2($user, $token, $euser) return $this->_sendCmd("AUTHENTICATE \"XOAUTH2\" \"$auth\""); } + /** + * Authenticates the user using the OAUTHBEARER method. + * + * @param string $user The userid to authenticate as. + * @param string $token The token to authenticate with. + * @param string $euser The effective uid to authenticate as. + * + * @return void + * + * @see https://www.rfc-editor.org/rfc/rfc7628.html + * @since 1.4.7 + */ + function _authOAUTHBEARER($user, $token, $euser) + { + // default to $user if $euser is not set + if (! $euser) { + $euser = $user; + } + + $auth = base64_encode("n,a=$euser\001auth=$token\001\001"); + return $this->_sendCmd("AUTHENTICATE \"OAUTHBEARER\" \"$auth\""); + } + /** * Removes a script from the server. *