Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support of OAUTHBEARER #10

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Sieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class Net_Sieve
'PLAIN' ,
'LOGIN',
'GSSAPI',
'XOAUTH2'
'XOAUTH2',
'OAUTHBEARER'
);

/**
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.
*
Expand Down