[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / facteur / phpmailer-php5 / class.phpmaileroauthgoogle.php
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 return new League\OAuth2\Client\Provider\Google([
54 'clientId' => $this->oauthClientId,
55 'clientSecret' => $this->oauthClientSecret
56 ]);
57 }
58
59 private function getGrant()
60 {
61 return new \League\OAuth2\Client\Grant\RefreshToken();
62 }
63
64 private function getToken()
65 {
66 $provider = $this->getProvider();
67 $grant = $this->getGrant();
68 return $provider->getAccessToken($grant, ['refresh_token' => $this->oauthRefreshToken]);
69 }
70
71 public function getOauth64()
72 {
73 $token = $this->getToken();
74 return base64_encode("user=" . $this->oauthUserEmail . "\001auth=Bearer " . $token . "\001\001");
75 }
76 }