コード例 #1
0
 /**
  * (non-PHPdoc)
  *
  * @see PostmanZendModuleTransport::createZendMailTransport()
  */
 public function createZendMailTransport($fakeHostname, $fakeConfig)
 {
     if (PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $this->getAuthenticationType()) {
         $config = PostmanOAuth2ConfigurationFactory::createConfig($this);
     } else {
         $config = PostmanBasicAuthConfigurationFactory::createConfig($this);
     }
     // Google's autoloader will try and load this so we list it first
     require_once 'PostmanGmailApiModuleZendMailTransport.php';
     // Gmail Client includes
     require_once 'google-api-php-client-1.1.2/src/Google/Client.php';
     require_once 'google-api-php-client-1.1.2/src/Google/Service/Gmail.php';
     // build the Gmail Client
     $authToken = PostmanOAuthToken::getInstance();
     $client = new Postman_Google_Client();
     $client->setClientId($this->options->getClientId());
     $client->setClientSecret($this->options->getClientSecret());
     $client->setRedirectUri('');
     // rebuild the google access token
     $token = new stdClass();
     $token->access_token = $authToken->getAccessToken();
     $token->refresh_token = $authToken->getRefreshToken();
     $token->token_type = 'Bearer';
     $token->expires_in = 3600;
     $token->id_token = null;
     $token->created = 0;
     $client->setAccessToken(json_encode($token));
     // We only need permissions to compose and send emails
     $client->addScope("https://www.googleapis.com/auth/gmail.compose");
     $service = new Postman_Google_Service_Gmail($client);
     $config[PostmanGmailApiModuleZendMailTransport::SERVICE_OPTION] = $service;
     return new PostmanGmailApiModuleZendMailTransport(self::HOST, $config);
 }
コード例 #2
0
ファイル: ApiClientTest.php プロジェクト: rapier83/isaebooks
 public function testSettersGetters()
 {
     $client = new Postman_Google_Client();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     $client->setRedirectUri('localhost');
     $client->setApplicationName('me');
     $this->assertEquals('object', gettype($client->getAuth()));
     $this->assertEquals('object', gettype($client->getCache()));
     $this->assertEquals('object', gettype($client->getIo()));
     $client->setAuth(new Postman_Google_Auth_Simple($client));
     $client->setAuth(new Postman_Google_Auth_OAuth2($client));
     try {
         $client->setAccessToken(null);
         die('Should have thrown an Postman_Google_Auth_Exception.');
     } catch (Postman_Google_Auth_Exception $e) {
         $this->assertEquals('Could not json decode the token', $e->getMessage());
     }
     $token = json_encode(array('access_token' => 'token'));
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
コード例 #3
0
ファイル: multi-api.php プロジェクト: rapier83/isaebooks
  ATTENTION: Fill in these values! Make sure
  the redirect URI is to this page, e.g:
  http://localhost:8080/user-example.php
 ************************************************/
$client_id = '<YOUR_CLIENT_ID>';
$client_secret = '<YOUR_CLIENT_SECRET>';
$redirect_uri = '<YOUR_REDIRECT_URI>';
/************************************************
  Make an API request on behalf of a user. In
  this case we need to have a valid OAuth 2.0
  token for the user, so we need to send them
  through a login flow. To do this we need some
  information from our API console project.
 ************************************************/
$client = new Postman_Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/youtube");
/************************************************
  We are going to create both YouTube and Drive
  services, and query both.
 ************************************************/
$yt_service = new Postman_Google_Service_YouTube($client);
$dr_service = new Postman_Google_Service_Drive($client);
/************************************************
  Boilerplate auth management - see
  user-example.php for details.
 ************************************************/
if (isset($_REQUEST['logout'])) {
コード例 #4
0
 /**
  * This is the only place where the Google library is loaded
  *
  * @see PostmanTransport::createZendMailTransport()
  */
 public function createZendMailTransport($hostname, $config)
 {
     // This is where the ZendMail special transport is loaded
     require_once 'PostmanGmailApiModuleZendMailTransport.php';
     // This is the only place where the Google library is loaded
     require_once 'google-api-php-client-1.1.2/src/Google/Client.php';
     require_once 'google-api-php-client-1.1.2/src/Google/Service/Gmail.php';
     // build the Gmail Client
     $options = PostmanOptions::getInstance();
     $authToken = PostmanOAuthToken::getInstance();
     $client = new Postman_Google_Client();
     $client->setClientId($options->getClientId());
     $client->setClientSecret($options->getClientSecret());
     $client->setRedirectUri('');
     // rebuild the google access token
     $token = new stdClass();
     $token->access_token = $authToken->getAccessToken();
     $token->refresh_token = $authToken->getRefreshToken();
     $token->token_type = 'Bearer';
     $token->expires_in = 3600;
     $token->id_token = null;
     $token->created = 0;
     $client->setAccessToken(json_encode($token));
     // We only need permissions to compose and send emails
     $client->addScope("https://www.googleapis.com/auth/gmail.compose");
     $service = new Postman_Google_Service_Gmail($client);
     $config[PostmanGmailApiModuleZendMailTransport::SERVICE_OPTION] = $service;
     return new PostmanGmailApiModuleZendMailTransport($hostname, $config);
 }
コード例 #5
0
ファイル: OAuthHelper.php プロジェクト: rapier83/isaebooks
/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(__FILE__) . '/../autoload.php';
$client = new Postman_Google_Client();
$client->setScopes(array("https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/tasks", "https://www.googleapis.com/auth/adsense", "https://www.googleapis.com/auth/youtube"));
$client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob");
// Visit https://code.google.com/apis/console to
// generate your oauth2_client_id, oauth2_client_secret, and to
// register your oauth2_redirect_uri.
$client->setClientId("");
$client->setClientSecret("");
$authUrl = $client->createAuthUrl();
`open '{$authUrl}'`;
echo "\nPlease enter the auth code:\n";
$authCode = trim(fgets(STDIN));
$accessToken = $client->authenticate($authCode);
echo "\n", 'Add the following to BaseTest.php as the $token value:', "\n\n";
echo $accessToken, "\n\n";