composer package updates
[openemr.git] / vendor / phpmailer / phpmailer / src / OAuth.php
blob0bce7e3468c69c458b110178c0988490d747176d
1 <?php
2 /**
3 * PHPMailer - PHP email creation and transport class.
4 * PHP Version 5.5.
6 * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
8 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
9 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
10 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
11 * @author Brent R. Matzelle (original founder)
12 * @copyright 2012 - 2015 Marcus Bointon
13 * @copyright 2010 - 2012 Jim Jagielski
14 * @copyright 2004 - 2009 Andy Prevost
15 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
16 * @note This program is distributed in the hope that it will be useful - WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE.
21 namespace PHPMailer\PHPMailer;
23 use League\OAuth2\Client\Grant\RefreshToken;
24 use League\OAuth2\Client\Provider\AbstractProvider;
25 use League\OAuth2\Client\Token\AccessToken;
27 /**
28 * OAuth - OAuth2 authentication wrapper class.
29 * Uses the oauth2-client package from the League of Extraordinary Packages.
31 * @see http://oauth2-client.thephpleague.com
33 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
35 class OAuth
37 /**
38 * An instance of the League OAuth Client Provider.
40 * @var AbstractProvider
42 protected $provider;
44 /**
45 * The current OAuth access token.
47 * @var AccessToken
49 protected $oauthToken;
51 /**
52 * The user's email address, usually used as the login ID
53 * and also the from address when sending email.
55 * @var string
57 protected $oauthUserEmail = '';
59 /**
60 * The client secret, generated in the app definition of the service you're connecting to.
62 * @var string
64 protected $oauthClientSecret = '';
66 /**
67 * The client ID, generated in the app definition of the service you're connecting to.
69 * @var string
71 protected $oauthClientId = '';
73 /**
74 * The refresh token, used to obtain new AccessTokens.
76 * @var string
78 protected $oauthRefreshToken = '';
80 /**
81 * OAuth constructor.
83 * @param array $options Associative array containing
84 * `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
86 public function __construct($options)
88 $this->provider = $options['provider'];
89 $this->oauthUserEmail = $options['userName'];
90 $this->oauthClientSecret = $options['clientSecret'];
91 $this->oauthClientId = $options['clientId'];
92 $this->oauthRefreshToken = $options['refreshToken'];
95 /**
96 * Get a new RefreshToken.
98 * @return RefreshToken
100 protected function getGrant()
102 return new RefreshToken();
106 * Get a new AccessToken.
108 * @return AccessToken
110 protected function getToken()
112 return $this->provider->getAccessToken(
113 $this->getGrant(),
114 ['refresh_token' => $this->oauthRefreshToken]
119 * Generate a base64-encoded OAuth token.
121 * @return string
123 public function getOauth64()
125 // Get a new token if it's not available or has expired
126 if (null === $this->oauthToken or $this->oauthToken->hasExpired()) {
127 $this->oauthToken = $this->getToken();
130 return base64_encode(
131 'user=' .
132 $this->oauthUserEmail .
133 "\001auth=Bearer " .
134 $this->oauthToken .
135 "\001\001"