/**
  * GetOauth64
  * 
  * encode the user email related to this request along with the token in base64
  * this is used for authentication, in the phpmailer smtp class
  * 
  * @return string
  */
 public function getOauth64()
 {
     $client = GmailXOAuth2::getClient();
     $options = gmail_smtp_get_option();
     if (!empty($options['oauth_access_token'])) {
         $accessToken = $options['oauth_access_token'];
     } else {
         return false;
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         $accessToken = $client->getAccessToken();
         $options['oauth_access_token'] = $accessToken;
         gmail_smtp_update_option($options);
     }
     $offlineToken = GmailXOAuth2::request_offline_token();
     return base64_encode("user="******"auth=Bearer " . $offlineToken . "");
 }
示例#2
0
文件: main.php 项目: jbs321/portfolio
 function plugin_init()
 {
     if (is_admin()) {
         if (isset($_GET['action']) && $_GET['action'] == "oauth_grant") {
             if (isset($_GET['code'])) {
                 $authCode = $_GET['code'];
                 $accessToken = GmailXOAuth2::resetCredentials($authCode);
                 if (isset($accessToken) && !empty($accessToken)) {
                     //echo __('Access Granted Successfully!', 'gmail-smtp');
                     $_GET['gmail_smtp_access_granted'] = "yes";
                 } else {
                     $_GET['gmail_smtp_access_granted'] = "no";
                 }
             } else {
                 // If we don't have an authorization code then get one
                 $authUrl_array = GmailXOAuth2::authenticate();
                 if (isset($authUrl_array['authorization_uri'])) {
                     $authUrl = $authUrl_array['authorization_uri'];
                     wp_redirect($authUrl);
                     exit;
                 }
             }
             // Unix timestamp of when the token will expire, and need refreshing
             //    echo $token->expires;
         }
     }
 }