Skip to content

Commit

Permalink
OAUTHBEARER Support (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Dec 9, 2023
2 parents d7a431d + d2a17b8 commit 9116517
Showing 1 changed file with 28 additions and 1 deletion.
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

1 comment on commit 9116517

@Neustradamus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alecpl, @ashnazg: Can you add "Issues" section for this repository?

Please sign in to comment.