<?php1/**2* PHPMailer - PHP email creation and transport class.3* PHP Version 5.5.4*5* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project6*7* @author Marcus Bointon (Synchro/coolbru) <[email protected]>8* @author Jim Jagielski (jimjag) <[email protected]>9* @author Andy Prevost (codeworxtech) <[email protected]>10* @author Brent R. Matzelle (original founder)11* @copyright 2012 - 2020 Marcus Bointon12* @copyright 2010 - 2012 Jim Jagielski13* @copyright 2004 - 2009 Andy Prevost14* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License15* @note This program is distributed in the hope that it will be useful - WITHOUT16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17* FITNESS FOR A PARTICULAR PURPOSE.18*/1920namespace PHPMailer\PHPMailer;2122use League\OAuth2\Client\Grant\RefreshToken;23use League\OAuth2\Client\Provider\AbstractProvider;24use League\OAuth2\Client\Token\AccessToken;2526/**27* OAuth - OAuth2 authentication wrapper class.28* Uses the oauth2-client package from the League of Extraordinary Packages.29*30* @see http://oauth2-client.thephpleague.com31*32* @author Marcus Bointon (Synchro/coolbru) <[email protected]>33*/34class OAuth35{36/**37* An instance of the League OAuth Client Provider.38*39* @var AbstractProvider40*/41protected $provider;4243/**44* The current OAuth access token.45*46* @var AccessToken47*/48protected $oauthToken;4950/**51* The user's email address, usually used as the login ID52* and also the from address when sending email.53*54* @var string55*/56protected $oauthUserEmail = '';5758/**59* The client secret, generated in the app definition of the service you're connecting to.60*61* @var string62*/63protected $oauthClientSecret = '';6465/**66* The client ID, generated in the app definition of the service you're connecting to.67*68* @var string69*/70protected $oauthClientId = '';7172/**73* The refresh token, used to obtain new AccessTokens.74*75* @var string76*/77protected $oauthRefreshToken = '';7879/**80* OAuth constructor.81*82* @param array $options Associative array containing83* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements84*/85public function __construct($options)86{87$this->provider = $options['provider'];88$this->oauthUserEmail = $options['userName'];89$this->oauthClientSecret = $options['clientSecret'];90$this->oauthClientId = $options['clientId'];91$this->oauthRefreshToken = $options['refreshToken'];92}9394/**95* Get a new RefreshToken.96*97* @return RefreshToken98*/99protected function getGrant()100{101return new RefreshToken();102}103104/**105* Get a new AccessToken.106*107* @return AccessToken108*/109protected function getToken()110{111return $this->provider->getAccessToken(112$this->getGrant(),113['refresh_token' => $this->oauthRefreshToken]114);115}116117/**118* Generate a base64-encoded OAuth token.119*120* @return string121*/122public function getOauth64()123{124// Get a new token if it's not available or has expired125if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {126$this->oauthToken = $this->getToken();127}128129return base64_encode(130'user=' .131$this->oauthUserEmail .132"\001auth=Bearer " .133$this->oauthToken .134"\001\001"135);136}137}138139140