Skip to content

Commit

Permalink
Removed not working OAuth code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Krätzig committed Apr 16, 2020
1 parent bd5fbc5 commit f85a742
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 75 deletions.
4 changes: 1 addition & 3 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@
<code>\random_bytes(20)</code>
<code>\random_bytes(16)</code>
</InvalidArgument>
<PossiblyUnusedMethod occurrences="27">
<code>setOAuthToken</code>
<code>getOAuthToken</code>
<PossiblyUnusedMethod occurrences="25">
<code>setConnectionRetry</code>
<code>setConnectionRetryDelay</code>
<code>setExpungeOnDisconnect</code>
Expand Down
72 changes: 0 additions & 72 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class Mailbox
/** @var string */
protected $imapPassword;

/** @var string|null */
protected $imapOAuthAccessToken = null;

/** @var int */
protected $imapSearchOption = SE_UID;

Expand Down Expand Up @@ -131,41 +128,6 @@ public function __destruct()
$this->disconnect();
}

/**
* Sets / Changes the OAuth Token for the authentication.
*
* @param string $access_token OAuth token from your application (eg. Google Mail)
*
* @return void
*
* @throws InvalidArgumentException If no access token is provided
* @throws Exception If OAuth authentication was unsuccessful
*/
public function setOAuthToken($access_token)
{
if (empty(\trim($access_token))) {
throw new InvalidParameterException('setOAuthToken() requires an access token as parameter!');
}

$this->imapOAuthAccessToken = \trim($access_token);

try {
$this->_oauthAuthentication();
} catch (Exception $ex) {
throw new Exception('Invalid OAuth token provided. Error: '.$ex->getMessage());
}
}

/**
* Gets the OAuth Token for the authentication.
*
* @return string|null $access_token OAuth Access Token
*/
public function getOAuthToken()
{
return $this->imapOAuthAccessToken;
}

/**
* Sets / Changes the path delimiter character (Supported values: '.', '/').
*
Expand Down Expand Up @@ -1632,40 +1594,6 @@ public function appendMessageToMailbox(
);
}

/**
* Builds an OAuth2 authentication string for the given email address and access token.
*
* @return string $access_token Formatted OAuth access token
*/
protected function _constructAuthString()
{
return \base64_encode("user=$this->imapLogin\1auth=Bearer $this->imapOAuthAccessToken\1\1");
}

/**
* Authenticates the IMAP client with the OAuth access token.
*
* @return void
*
* @throws Exception If any error occured
*/
protected function _oauthAuthentication()
{
$oauth_command = 'A AUTHENTICATE XOAUTH2 '.$this->_constructAuthString();

$oauth_result = \fwrite($this->getImapStream(), $oauth_command);

if (false === $oauth_result) {
throw new Exception('Could not authenticate using OAuth!');
}

try {
$this->checkMailbox();
} catch (Throwable $ex) {
throw new Exception('OAuth authentication failed! IMAP Error: '.$ex->getMessage());
}
}

/** @return resource */
protected function initImapStreamWithRetry()
{
Expand Down

0 comments on commit f85a742

Please sign in to comment.