/**
  * 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 . "");
 }
Example #2
0
 function can_grant_permission()
 {
     $options = gmail_smtp_get_option();
     $grant_permission = true;
     if (!isset($options['oauth_client_id']) || empty($options['oauth_client_id'])) {
         $grant_permission = false;
     }
     if (!isset($options['oauth_client_secret']) || empty($options['oauth_client_secret'])) {
         $grant_permission = false;
     }
     if (isset($options['oauth_access_token']) && !empty($options['oauth_access_token'])) {
         $grant_permission = false;
     }
     return $grant_permission;
 }