3 * PHPMailer - PHP email creation and transport class.
6 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
7 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
8 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
9 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
10 * @author Brent R. Matzelle (original founder)
11 * @copyright 2012 - 2014 Marcus Bointon
12 * @copyright 2010 - 2012 Jim Jagielski
13 * @copyright 2004 - 2009 Andy Prevost
14 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 * @note This program is distributed in the hope that it will be useful - WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE.
21 * PHPMailerOAuthGoogle - Wrapper for League OAuth2 Google provider.
23 * @author @sherryl4george
24 * @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
25 * @link https://github.com/thephpleague/oauth2-client
27 class PHPMailerOAuthGoogle
29 private $oauthUserEmail = '';
30 private $oauthRefreshToken = '';
31 private $oauthClientId = '';
32 private $oauthClientSecret = '';
35 * @param string $UserEmail
36 * @param string $ClientSecret
37 * @param string $ClientId
38 * @param string $RefreshToken
40 public function __construct(
46 $this->oauthClientId
= $ClientId;
47 $this->oauthClientSecret
= $ClientSecret;
48 $this->oauthRefreshToken
= $RefreshToken;
49 $this->oauthUserEmail
= $UserEmail;
52 private function getProvider()
54 return new League\OAuth2\Client\Provider\
Google([
55 'clientId' => $this->oauthClientId
,
56 'clientSecret' => $this->oauthClientSecret
60 private function getGrant()
62 return new \League\OAuth2\Client\Grant\
RefreshToken();
65 private function getToken()
67 $provider = $this->getProvider();
68 $grant = $this->getGrant();
69 return $provider->getAccessToken($grant, ['refresh_token' => $this->oauthRefreshToken
]);
72 public function getOauth64()
74 $token = $this->getToken();
75 return base64_encode("user=" . $this->oauthUserEmail
. "\001auth=Bearer " . $token . "\001\001");