forked from PHPMailer/PHPMailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ test/testbootstrap.php | |
test/*.pem | ||
.idea | ||
build/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
<?php | ||
/** | ||
* PHPMailer - PHP email creation and transport class. | ||
* PHP Version 5.4 | ||
* @package PHPMailer | ||
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project | ||
* @author Marcus Bointon (Synchro/coolbru) <[email protected]> | ||
* @author Jim Jagielski (jimjag) <[email protected]> | ||
* @author Andy Prevost (codeworxtech) <[email protected]> | ||
* @author Brent R. Matzelle (original founder) | ||
* @copyright 2012 - 2014 Marcus Bointon | ||
* @copyright 2010 - 2012 Jim Jagielski | ||
* @copyright 2004 - 2009 Andy Prevost | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License | ||
* @note This program is distributed in the hope that it will be useful - WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
|
||
class PHPMailer54 extends PHPMailer { | ||
|
||
/** | ||
* PHPMailerOAuth - PHPMailer subclass adding OAuth support. | ||
* @package PHPMailer | ||
* @author @sherryl4george | ||
* @author Marcus Bointon (Synchro/coolbru) <[email protected]> | ||
*/ | ||
class PHPMailerOAuth extends PHPMailer | ||
{ | ||
/** | ||
* The OAuth user's email address | ||
* @type string | ||
*/ | ||
public $oauthUserEmail = ''; | ||
|
||
/** | ||
* The OAuth refresh token | ||
* @type string | ||
*/ | ||
public $oauthRefreshToken = ''; | ||
|
||
/** | ||
* The OAuth client ID | ||
* @type string | ||
*/ | ||
public $oauthClientId = ''; | ||
public $oauthClientSecret = ''; | ||
|
||
/** | ||
* An instance of the SMTP sender class. | ||
* @type SMTP | ||
* @access protected | ||
* The OAuth client secret | ||
* @type string | ||
*/ | ||
protected $oauth = null; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct($exceptions = false); | ||
} | ||
public $oauthClientSecret = ''; | ||
|
||
/** | ||
* Destructor. | ||
* An instance of the OAuth class. | ||
* @type OAuth | ||
* @access protected | ||
*/ | ||
public function __destruct() | ||
{ | ||
//Close any open SMTP connection nicely | ||
parent::__destruct(); | ||
} | ||
protected $oauth = null; | ||
|
||
/** | ||
* Get an instance to use for SMTP operations. | ||
* Override this function to load your own SMTP implementation | ||
* @return SMTP | ||
* Get an OAuth instance to use. | ||
* @return OAuth | ||
*/ | ||
public function getOAUTHInstance() | ||
{ | ||
if (!is_object($this->oauth)) { | ||
$this->oauth = new OAuth($this->oauthUserEmail, | ||
$this->oauthClientSecret, | ||
$this->oauthClientId, | ||
$this->oauthRefreshToken | ||
); | ||
$this->oauth = new OAuth( | ||
$this->oauthUserEmail, | ||
$this->oauthClientSecret, | ||
$this->oauthClientId, | ||
$this->oauthRefreshToken | ||
); | ||
} | ||
return $this->oauth; | ||
} | ||
|
||
|
||
/** | ||
* Initiate a connection to an SMTP server. | ||
* Overrides the original smtpConnect method to add support for OAuth. | ||
* @param array $options An array of options compatible with stream_context_create() | ||
* @uses SMTP | ||
* @access public | ||
* @throws phpmailerException | ||
* @return boolean | ||
*/ | ||
public function smtpConnect($options = array()) | ||
{ | ||
if (is_null($this->smtp)) { | ||
|
@@ -129,11 +166,11 @@ public function smtpConnect($options = array()) | |
} | ||
if ($this->SMTPAuth) { | ||
if (!$this->smtp->authenticate( | ||
$this->Username, | ||
$this->Password, | ||
$this->AuthType, | ||
$this->Realm, | ||
$this->Workstation, | ||
$this->Username, | ||
$this->Password, | ||
$this->AuthType, | ||
$this->Realm, | ||
$this->Workstation, | ||
$this->oauth | ||
) | ||
) { | ||
|
@@ -157,7 +194,4 @@ public function smtpConnect($options = array()) | |
} | ||
return false; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
{ | ||
"name": "phpmailer/phpmailer", | ||
"type": "library", | ||
"description": "PHPMailer is a full-featured email creation and transfer class for PHP", | ||
"authors": [ | ||
"name": "phpmailer/phpmailer", | ||
"type": "library", | ||
"description": "PHPMailer is a full-featured email creation and transfer class for PHP", | ||
"authors": [ | ||
{ | ||
"name": "Marcus Bointon", | ||
"email": "[email protected]" | ||
"name": "Marcus Bointon", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Jim Jagielski", | ||
"email": "[email protected]" | ||
"name": "Jim Jagielski", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Andy Prevost", | ||
"email": "[email protected]" | ||
"name": "Andy Prevost", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Brent R. Matzelle" | ||
"name": "Brent R. Matzelle" | ||
} | ||
], | ||
"require": { | ||
], | ||
"require": { | ||
"php": ">=5.0.0", | ||
"league/oauth2-client": "0.10.*", | ||
"guzzle/guzzle": "~3.7" | ||
}, | ||
"require-dev": { | ||
}, | ||
"require-dev": { | ||
"phpdocumentor/phpdocumentor": "*", | ||
"phpunit/phpunit": "4.3.*" | ||
}, | ||
"autoload": { | ||
"phpunit/phpunit": "4.3.*" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"class.phpmailer.php", | ||
"class.phpmailer54.php", | ||
"class.oauth.php", | ||
"class.smtp.php", | ||
"class.pop3.php", | ||
"extras/EasyPeasyICS.php", | ||
"extras/ntlm_sasl_client.php" | ||
"class.phpmailer.php", | ||
"class.phpmaileroauth.php", | ||
"class.oauth.php", | ||
"class.smtp.php", | ||
"class.pop3.php", | ||
"extras/EasyPeasyICS.php", | ||
"extras/ntlm_sasl_client.php" | ||
] | ||
}, | ||
"license": "LGPL-2.1" | ||
} | ||
}, | ||
"license": "LGPL-2.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,57 @@ | ||
<?php | ||
require './extras/oauth2/vendor/autoload.php'; | ||
/** | ||
* Get an OAuth2 token from Google. | ||
* * Install this script on your server so that it's accessible | ||
* as [https/http]://<yourdomain>/<folder>/get_oauth_token.php | ||
* e.g.: http://localhost/phpmail/get_oauth_token.php | ||
* * Ensure dependencies are installed with 'composer install' | ||
* * Set up an app in your Google developer console | ||
* * Set the script address as the app's redirect URL | ||
* This script requires PHP 5.4 or later | ||
*/ | ||
|
||
require './vendor/autoload.php'; | ||
session_start(); | ||
|
||
$redirectUri = isset($_SERVER['HTTPS'])?'https://':'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; | ||
$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; | ||
|
||
//All Details Obtained by setting up APP in Google Developer Console. | ||
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php | ||
// eg: http://localhost/phpmail/get_oauth_token.php | ||
$provider = new League\OAuth2\Client\Provider\Google ([ | ||
'clientId' => 'RANDOMCHARS----p05gduv1n2.apps.googleusercontent.com', | ||
'clientSecret' => 'RANDOMCHARS----CWufYlGyjPcRtvP', | ||
'redirectUri' => $redirectUri, | ||
'scopes' => ['https://mail.google.com/'], | ||
'accessType' => 'offline' | ||
]); | ||
$provider = new League\OAuth2\Client\Provider\Google ( | ||
[ | ||
'clientId' => 'RANDOMCHARS----p05gduv1n2.apps.googleusercontent.com', | ||
'clientSecret' => 'RANDOMCHARS----CWufYlGyjPcRtvP', | ||
'redirectUri' => $redirectUri, | ||
'scopes' => ['https://mail.google.com/'], | ||
'accessType' => 'offline' | ||
] | ||
); | ||
|
||
if (!isset($_GET['code'])) { | ||
|
||
// If we don't have an authorization code then get one | ||
$authUrl = $provider->getAuthorizationUrl(); | ||
$_SESSION['oauth2state'] = $provider->state; | ||
header('Location: ' . $authUrl); | ||
exit; | ||
// Check given state against previously stored one to mitigate CSRF attack | ||
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { | ||
|
||
unset($_SESSION['oauth2state']); | ||
exit('Invalid state'); | ||
} else { | ||
|
||
$provider->accessType = 'offline'; | ||
// Try to get an access token (using the authorization code grant) | ||
$token = $provider->getAccessToken('authorization_code', [ | ||
'code' => $_GET['code'] | ||
]); | ||
|
||
|
||
// Use this to interact with an API on the users behalf | ||
// echo $token->accessToken.'<br>'; | ||
$token = $provider->getAccessToken( | ||
'authorization_code', | ||
[ | ||
'code' => $_GET['code'] | ||
] | ||
); | ||
// Use this to interact with an API on the users behalf | ||
// echo $token->accessToken.'<br>'; | ||
|
||
// Use this to get a new access token if the old one expires | ||
echo 'Refresh Token: '.$token->refreshToken; | ||
echo 'Refresh Token: ' . $token->refreshToken; | ||
|
||
// Unix timestamp of when the token will expire, and need refreshing | ||
// echo $token->expires; | ||
// Unix timestamp of when the token will expire, and need refreshing | ||
// echo $token->expires; | ||
} | ||
?> |