1: <?php
2: /**
3: * PHPMailer - PHP email creation and transport class.
4: * PHP Version 5.4
5: * @package PHPMailer
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.
18: */
19:
20: /**
21: * PHPMailerOAuthGoogle - Wrapper for League OAuth2 Google provider.
22: * @package PHPMailer
23: * @author @sherryl4george
24: * @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
25: * @link https://github.com/thephpleague/oauth2-client
26: */
27: class PHPMailerOAuthGoogle
28: {
29: private $oauthUserEmail = '';
30: private $oauthRefreshToken = '';
31: private $oauthClientId = '';
32: private $oauthClientSecret = '';
33:
34: /**
35: * @param string $UserEmail
36: * @param string $ClientSecret
37: * @param string $ClientId
38: * @param string $RefreshToken
39: */
40: public function __construct(
41: $UserEmail,
42: $ClientSecret,
43: $ClientId,
44: $RefreshToken
45: ) {
46: $this->oauthClientId = $ClientId;
47: $this->oauthClientSecret = $ClientSecret;
48: $this->oauthRefreshToken = $RefreshToken;
49: $this->oauthUserEmail = $UserEmail;
50: }
51:
52: private function getProvider()
53: {
54: return new League\OAuth2\Client\Provider\Google([
55: 'clientId' => $this->oauthClientId,
56: 'clientSecret' => $this->oauthClientSecret
57: ]);
58: }
59:
60: private function getGrant()
61: {
62: return new \League\OAuth2\Client\Grant\RefreshToken();
63: }
64:
65: private function getToken()
66: {
67: $provider = $this->getProvider();
68: $grant = $this->getGrant();
69: return $provider->getAccessToken($grant, ['refresh_token' => $this->oauthRefreshToken]);
70: }
71:
72: public function getOauth64()
73: {
74: $token = $this->getToken();
75: return base64_encode("user=" . $this->oauthUserEmail . "\001auth=Bearer " . $token . "\001\001");
76: }
77: }
78: