Example #1
5
 function google()
 {
     $client = new Google_Client();
     $client->setApplicationName("snmmaurya");
     $client->setClientId(CLIENT_ID);
     $client->setClientSecret(CLIENT_SECRET);
     $client->setRedirectUri(REDIRECT_URI);
     $client->setApprovalPrompt(APPROVAL_PROMPT);
     $client->setAccessType(ACCESS_TYPE);
     $oauth2 = new Google_Oauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['token'] = $client->getAccessToken();
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if (isset($_REQUEST['error'])) {
         echo '<script type="text/javascript">window.close();</script>';
         exit;
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['User'] = $user;
         $_SESSION['token'] = $client->getAccessToken();
     } else {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . $authUrl);
     }
 }
 public function signin()
 {
     $client = new \Google_Client();
     $client->setClientId(Config::get('ntentan:social.google.client_id'));
     $client->setClientSecret(Config::get('ntentan:social.google.client_secret'));
     $client->setRedirectUri(Config::get('ntentan:social.google.redirect_uri'));
     $client->addScope(array('profile', 'email'));
     $oauth2 = new \Google_Service_Oauth2($client);
     if (isset($_REQUEST['logout'])) {
         Session::set('access_token', '');
         $client->revokeToken();
     }
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         Session::set('access_token', $client->getAccessToken());
         Redirect::path(\ntentan\Router::getRoute());
     }
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->isAccessTokenExpired()) {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['token'] = $client->getAccessToken();
         return array('firstname' => $user['given_name'], 'lastname' => $user['family_name'], 'key' => "google_{$user['id']}", 'avatar' => $user['picture'], 'email' => $user['email'], 'email_confirmed' => $user['verified_email']);
     } else {
         header("Location: {$client->createAuthUrl()}");
         die;
     }
     return false;
 }
Example #3
1
 public function testSettersGetters()
 {
     $client = new 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 Google_Auth_Simple($client));
     $client->setAuth(new Google_Auth_OAuth2($client));
     try {
         $client->setAccessToken(null);
         die('Should have thrown an Google_Auth_Exception.');
     } catch (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());
 }
Example #4
1
 public function googleCallbackAction()
 {
     $response = array("status" => 0, "message" => "Thao tác không thành công");
     $code = $this->request->getPost("code", null, false);
     if ($code) {
         $google = new \Google_Client();
         $google->setApplicationName($this->config["GOOGLE_NAME"]);
         $google->setClientId($this->config["GOOGLE_ID"]);
         $google->setClientSecret($this->config["GOOGLE_SECRET"]);
         $google->setRedirectUri('postmessage');
         $scopes = array("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email");
         $google->setScopes($scopes);
         $google->authenticate($code);
         $request = new \Google_Http_Request("https://www.googleapis.com/oauth2/v2/userinfo?alt=json");
         $userinfo = $google->getAuth()->authenticatedRequest($request);
         $response = $userinfo->getResponseBody();
         $userinfo = json_decode($response, true);
         $id = $userinfo["id"];
         $username = explode("@", $userinfo["email"]);
         $username = $username[0] . "_gg_" . $id;
         $data_user = array("email" => $userinfo["email"], "nickname" => $userinfo["name"], "username" => $username, "id" => $id);
         $response = $this->doSocialLogin($data_user);
     }
     echo json_encode($response);
     exit;
 }
Example #5
0
 public function __construct()
 {
     include_once AB_PATH . '/lib/google_api_v3/autoload.php';
     $this->client = new Google_Client();
     $this->client->setClientId(get_option('ab_settings_google_client_id'));
     $this->client->setClientSecret(get_option('ab_settings_google_client_secret'));
 }
 public function __construct($oauthClientId, $oauthClientSecret, $oAuthConfig = array())
 {
     $this->client = new \Google_Client();
     $this->client->setClassConfig('Google_Auth_OAuth2', $oAuthConfig);
     $this->client->setClientId($oauthClientId);
     $this->client->setClientSecret($oauthClientSecret);
 }
Example #7
0
 /**
  * Google constructor.
  */
 public function __construct()
 {
     $this->_googleClient = new \Google_Client();
     $this->_googleClient->setClientId(KACANA_SOCIAL_GOOGLE_KEY);
     $this->_googleClient->setClientSecret(KACANA_SOCIAL_GOOGLE_SECRET);
     $this->_googleClient->setApplicationName(KACANA_SOCIAL_GOOGLE_APP_NAME);
     $this->_googleClient->setRedirectUri('postmessage');
 }
Example #8
0
 /**
  * @param \Google_Client $client
  */
 public function __construct(\Google_Client $client)
 {
     $this->client = $client;
     $this->client->setClientId(\Config::get('google.client_id'));
     $this->client->setClientSecret(\Config::get('google.client_secret'));
     $this->client->setDeveloperKey(\Config::get('google.api_key'));
     $this->client->setRedirectUri(\Config::get('app.url') . "/loginCallback");
     $this->client->setScopes(['https://www.googleapis.com/auth/youtube']);
     $this->client->setAccessType('offline');
 }
Example #9
0
 /**
  * Google
  * @param $params array - data from config.neon
  * @param $cookieName String cookie name
  * @param Nette\Http\Response $httpResponse
  * @param Nette\Http\Request $httpRequest
  */
 public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest)
 {
     $this->params = $params;
     $this->cookieName = $cookieName;
     $this->httpResponse = $httpResponse;
     $this->httpRequest = $httpRequest;
     $this->client = new \Google_Client();
     $this->client->setClientId($this->params["clientId"]);
     $this->client->setClientSecret($this->params["clientSecret"]);
     $this->client->setRedirectUri($this->params["callbackURL"]);
 }
Example #10
0
 /**
  * Constructor.
  *
  * @param int $repositoryid repository instance id.
  * @param int|stdClass $context a context id or context object.
  * @param array $options repository options.
  * @param int $readonly indicate this repo is readonly or not.
  * @return void
  */
 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
 {
     parent::__construct($repositoryid, $context, $options, $readonly = 0);
     $callbackurl = new moodle_url(self::CALLBACKURL);
     $this->client = get_google_client();
     $this->client->setClientId(get_config('googledocs', 'clientid'));
     $this->client->setClientSecret(get_config('googledocs', 'secret'));
     $this->client->setScopes(array(Google_Service_Drive::DRIVE_READONLY));
     $this->client->setRedirectUri($callbackurl->out(false));
     $this->service = new Google_Service_Drive($this->client);
     $this->check_login();
 }
Example #11
0
 /**
  * Constructor.
  *
  * @param int $repositoryid repository instance id.
  * @param int|stdClass $context a context id or context object.
  * @param array $options repository options.
  * @param int $readonly indicate this repo is readonly or not.
  * @return void
  */
 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
 {
     parent::__construct($repositoryid, $context, $options, $readonly = 0);
     $callbackurl = new moodle_url(self::CALLBACKURL);
     $this->client = new Google_Client();
     $this->client->setClientId(get_config('googledocs', 'clientid'));
     $this->client->setClientSecret(get_config('googledocs', 'secret'));
     $this->client->setScopes(array('https://www.googleapis.com/auth/drive.readonly'));
     $this->client->setRedirectUri($callbackurl->out(false));
     $this->service = new Google_DriveService($this->client);
     $this->check_login();
 }
 /**
  * Google
  * @param $params array - data from config.neon
  * @param $cookieName String cookie name
  * @param Nette\Http\Response $httpResponse
  * @param Nette\Http\Request $httpRequest
  */
 public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest)
 {
     $this->params = $params;
     $this->cookieName = $cookieName;
     $this->httpResponse = $httpResponse;
     $this->httpRequest = $httpRequest;
     $config = new \Google_Config();
     $config->setClassConfig('Google_Cache_File', array('directory' => '/temp/cache'));
     $this->client = new \Google_Client($config);
     $this->client->setClientId($this->params["clientId"]);
     $this->client->setClientSecret($this->params["clientSecret"]);
     $this->client->setRedirectUri($this->params["callbackURL"]);
 }
Example #13
0
 public function initializeClient()
 {
     $this->client = new Client();
     $this->client->setAccessType('offline');
     $this->client->setApplicationName('playlister');
     $this->client->setClientId($this->config->get('services.youtube.client_id'));
     $this->client->setClientSecret($this->config->get('services.youtube.client_secret'));
     $this->client->setRedirectUri($this->config->get('services.youtube.redirect'));
     $this->client->setDeveloperKey($this->config->get('services.youtube.api_key'));
     $this->client->addScope('https://www.googleapis.com/auth/youtube.readonly');
     if ($this->auth->check() && $this->request->session()->has('user.token')) {
         $this->setToken($this->request->session()->get('user.token'));
     }
 }
Example #14
0
 public function googlecallback()
 {
     $ret = null;
     //$google_redirect_url = site_url('user/signup');
     $google_redirect_url = 'http://localhost/punu/punu/index.php/user/signup';
     $client = new Google_Client();
     $client->setClientId($this->google_client_id);
     $client->setClientSecret($this->google_client_secret);
     $client->setDeveloperKey($this->google_api_key);
     $client->setRedirectUri($google_redirect_url);
     $client->addScope($this->google_scope);
     // Send Client Request
     $objOAuthService = new Google_Service_Oauth2($client);
     // Add Access Token to Session
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['google_access_token'] = $client->getAccessToken();
         //header('Location: ' . filter_var($this->google_redirect_url, FILTER_SANITIZE_URL));
     }
     // Set Access Token to make Request
     if (isset($_SESSION['google_access_token']) && $_SESSION['google_access_token']) {
         $client->setAccessToken($_SESSION['google_access_token']);
     }
     // Get User Data from Google and store them in $data
     if ($client->getAccessToken()) {
         $userData = $objOAuthService->userinfo->get();
         //$_SESSION['userData'] = $userData;
         $_SESSION['google_access_token'] = $client->getAccessToken();
         $ret = $userData;
     }
     return $ret;
 }
Example #15
0
 /**
  * Sets the required params for authentication 
  * 
  * @param string $client_id our app's client id
  * @param string $client_secret our app's client secret 
  * @param string $redirect_uri where will the auth server send the client 
  * after generating an authorization code to authenticate
  * @param null|string $token token obtained when a code is authenticated
  * @param null|string $code response code to authenticate
  * @param null|array $scopes array of strings with OAuth2/google scopes 
  * to requested
  * @param null|Google_Client $client
  * @param bool $debug defaults to false
  */
 public function __construct($client_id, $client_secret, $redirect_uri, $token = null, $code = null, $scopes = null, $client = null, $debug = null)
 {
     $this->client_id = $client_id;
     $this->client_secret = $client_secret;
     $this->redirect_uri = $redirect_uri;
     $this->code = $code;
     $this->token = $token;
     if ($scopes !== null) {
         $this->scopes = $scopes;
     }
     if (is_bool($this->debug)) {
         $this->debug = $debug;
     } else {
         $this->debug = false;
     }
     if ($client === null) {
         $this->client = new Google_Client();
         $this->client->setClientId($this->client_id);
         $this->client->setClientSecret($this->client_secret);
         $this->client->setRedirectUri($this->redirect_uri);
         if ($token !== null) {
             $this->client->setAccessToken($token);
         }
         $this->client->setScopes($this->scopes);
     }
 }
 /**
  * Google login method
  * --
  */
 public function flow()
 {
     $client = new Google_Client();
     $client->setClientId($this->client_id);
     $client->setClientSecret($this->client_secret);
     $client->setRedirectUri($this->redirect_url);
     $client->addScope("email");
     $client->addScope("profile");
     $this->context = Context::getContext();
     $this->client = $client;
     $this->service = new Google_Service_Oauth2($this->client);
     if (Tools::getValue('code')) {
         $this->client->authenticate(Tools::getValue('code'));
         $this->context->cookie->__set('googleconnect_access_token', serialize($this->client->getAccessToken()));
         Tools::redirect(filter_var($this->redirect_url, FILTER_SANITIZE_URL));
     } else {
         if ($this->context->cookie->__isset('googleconnect_access_token')) {
             $a_token = unserialize($this->context->cookie->__get('googleconnect_access_token'));
             $this->client->setAccessToken($a_token);
             if (!$this->client->isAccessTokenExpired()) {
                 $this->context->cookie->__unset('googleconnect_access_token');
                 $this->loginToStore();
             } else {
                 $this->setAuthUrl();
             }
         } else {
             $this->setAuthUrl();
         }
     }
 }
Example #17
0
 public function call_back()
 {
     $config = new Controllers_Api_Google_Config_App();
     $client = new Google_Client();
     $client->setClientId($config->config['client_id']);
     $client->setClientSecret($config->config['client_secret']);
     $client->setRedirectUri($config->config['redirect_uri']);
     $client->addScope("email");
     $client->addScope("profile");
     $service = new Google_Service_Oauth2($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['access_token'] = $client->getAccessToken();
         header('Location: ' . filter_var($config->config['redirect_uri'], FILTER_SANITIZE_URL));
         exit;
     }
     /************************************************
         If we have an access token, we can make
         requests, else we generate an authentication URL.
        ************************************************/
     if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
         $client->setAccessToken($_SESSION['access_token']);
     } else {
         $authUrl = $client->createAuthUrl();
     }
     if (isset($authUrl)) {
         //show login url
         echo json_encode(array('status' => false, 'data' => $authUrl));
     } else {
         $user = $service->userinfo->get();
         //get user info
         echo json_encode(array('status' => true, 'data' => $user));
     }
 }
Example #18
0
 function authorizeGoogleUser($access_code)
 {
     $client = new \Google_Client();
     $google = $this->config->google;
     $client->setApplicationName('Portal da Rede');
     $client->setClientId($google->clientId);
     $client->setClientSecret($google->secret);
     $client->setRedirectUri('postmessage');
     $client->addScope('https://www.googleapis.com/auth/userinfo.profile');
     $client->addScope('https://www.googleapis.com/auth/userinfo.email');
     $client->authenticate($access_code);
     $json_token = $client->getAccessToken();
     $client->setAccessToken($json_token);
     $plus = new \Google_Service_Plus($client);
     $user = $plus->people->get('me');
     if (!$user->emails || !is_array($user->emails)) {
         return;
     }
     $email = $user->emails[0]['value'];
     $user_email = $this->db->user_email->find_one($email);
     if (!$user_email) {
         return;
     }
     $this->login($user_email->user);
 }
Example #19
0
 public function __construct()
 {
     $google = new \Google_Client();
     $google->setClientId(Setting::get('google.clientId'));
     $google->setClientSecret(Setting::get('google.clientSecret'));
     $this->google = $google;
 }
 public function __construct()
 {
     $config_file = $_SERVER['HOME'] . '/' . self::CONFIG_FILE_NAME;
     if (file_exists($config_file)) {
         $config = json_decode(file_get_contents($config_file));
     }
     if (!$config) {
         throw new Exception(sprintf('Could not find or read the config file at ' . '%s. You can use the config.json file in the samples root as a ' . 'template.', $config_file));
     }
     $client = new Google_Client();
     $client->setApplicationName($config->applicationName);
     $client->setClientId($config->clientId);
     $client->setClientSecret($config->clientSecret);
     try {
         $client->refreshToken($config->refreshToken);
     } catch (Google_Auth_Exception $exception) {
         print str_repeat('*', 40);
         print "Your refresh token was missing or invalid, fetching a new one\n";
         $refresh_token = $this->getRefreshToken($client);
         $config->refreshToken = $refresh_token;
         file_put_contents($config_file, json_encode($config));
         print "Refresh token saved to your config file\n";
         print str_repeat('*', 40);
     }
     $this->merchant_id = $config->merchantId;
     $this->service = new Google_Service_ShoppingContent($client);
 }
Example #21
0
 function onNextendYoutube(&$google, &$youtube)
 {
     $config = new NextendData();
     $config->loadJson(NextendSmartSliderStorage::get(self::$_group));
     if (!class_exists('Google_Client')) {
         require_once dirname(__FILE__) . '/googleclient/Google_Client.php';
     }
     if (!class_exists('Google_YouTubeService')) {
         require_once dirname(__FILE__) . '/googleclient/contrib/Google_YouTubeService.php';
     }
     $google = new Google_Client();
     $google->setClientId($config->get('apikey', ''));
     $google->setClientSecret($config->get('apisecret', ''));
     $token = $config->get('token', null);
     if ($token) {
         $google->setAccessToken($token);
     }
     $youtube = new Google_YouTubeService($google);
     if ($google->isAccessTokenExpired()) {
         $token = json_decode($google->getAccessToken(), true);
         if (isset($token['refresh_token'])) {
             $google->refreshToken($token['refresh_token']);
             $config->set('token', $google->getAccessToken());
             NextendSmartSliderStorage::set(self::$_group, $config->toJSON());
         }
     }
 }
Example #22
0
 /**
  * Login to facebook and get the associated cloudrexx user.
  */
 public function login()
 {
     $client = new \Google_Client();
     $client->setApplicationName('Contrexx Login');
     $client->setClientId($this->applicationData[0]);
     $client->setClientSecret($this->applicationData[1]);
     $client->setRedirectUri(\Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER));
     $client->setDeveloperKey($this->applicationData[2]);
     $client->setUseObjects(true);
     $client->setApprovalPrompt('auto');
     $client->setScopes(self::$scopes);
     self::$google = new \Google_Oauth2Service($client);
     self::$googleplus = new \Google_PlusService($client);
     if (isset($_GET['code'])) {
         try {
             $client->authenticate();
         } catch (\Google_AuthException $e) {
         }
     }
     if (!$client->getAccessToken()) {
         \Cx\Core\Csrf\Controller\Csrf::header('Location: ' . $client->createAuthUrl());
         exit;
     }
     self::$userdata = $this->getUserData();
     $this->getContrexxUser(self::$userdata['oauth_id']);
 }
Example #23
0
 public function index()
 {
     //Config items added to global config file
     $clientId = $this->config->item('clientId');
     $clientSecret = $this->config->item('clientSecret');
     $redirectUrl = $this->config->item('redirectUrl');
     #session_start();
     $client = new Google_Client();
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     $client->setRedirectUri($redirectUrl);
     #$client->setScopes(array('https://spreadsheets.google.com/feeds'));
     $client->addScope(array('https://spreadsheets.google.com/feeds'));
     $client->addScope('email');
     $client->addScope('profile');
     $client->setApprovalPrompt('force');
     //Useful if you had already granted access to this application.
     $client->setAccessType('offline');
     //Needed to get a refresh_token
     $data['base_url'] = $this->config->item('base_url');
     $data['auth_url'] = $client->createAuthUrl();
     //Set canonical URL
     $data['canonical'] = $this->config->item('base_url') . 'docs';
     $this->load->view('docs', $data);
 }
Example #24
0
 /**
  * Initializes the Google Drive connection
  *
  * @param   array   $params  Any connection params needed
  * @return  object
  **/
 public static function init($params = [])
 {
     // Get the params
     $pparams = Plugin::params('filesystem', 'googledrive');
     $app_id = isset($params['app_id']) && $params['app_id'] != '' ? $params['app_id'] : $pparams->get('app_id');
     $app_secret = isset($params['app_secret']) && $params['app_secret'] != '' ? $params['app_secret'] : $pparams->get('app_secret');
     $client = new \Google_Client();
     $client->setClientId($app_id);
     $client->setClientSecret($app_secret);
     $client->addScope(Google_Service_Drive::DRIVE);
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     $client->setIncludeGrantedScopes(true);
     if (isset($params['app_token'])) {
         $accessToken = $params['app_token'];
         // json encode turned our array into an object, we need to undo that
         $accessToken = (array) $accessToken;
     } else {
         \Session::set('googledrive.app_id', $app_id);
         \Session::set('googledrive.app_secret', $app_secret);
         \Session::set('googledrive.connection_to_set_up', Request::getVar('connection', 0));
         // Set upp a return and redirect to Google for auth
         $return = Request::getVar('return') ? Request::getVar('return') : Request::current(true);
         $return = base64_encode($return);
         $redirectUri = trim(Request::root(), '/') . '/developer/callback/googledriveAuthorize';
         $client->setRedirectUri($redirectUri);
         Session::set('googledrive.state', $return);
         App::redirect($client->createAuthUrl());
     }
     $client->setAccessToken($accessToken);
     $service = new \Google_Service_Drive($client);
     $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, 'root');
     return $adapter;
 }
 private function createClient()
 {
     $options = ['auth' => 'google_auth', 'exceptions' => false];
     if ($proxy = getenv('HTTP_PROXY')) {
         $options['proxy'] = $proxy;
         $options['verify'] = false;
     }
     // adjust constructor depending on guzzle version
     if (!$this->isGuzzle6()) {
         $options = ['defaults' => $options];
     }
     $httpClient = new GuzzleHttp\Client($options);
     $client = new Google_Client();
     $client->setApplicationName('google-api-php-client-tests');
     $client->setHttpClient($httpClient);
     $client->setScopes(["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", "https://www.googleapis.com/auth/drive"]);
     if ($this->key) {
         $client->setDeveloperKey($this->key);
     }
     list($clientId, $clientSecret) = $this->getClientIdAndSecret();
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     $client->setCache($this->getCache());
     return $client;
 }
Example #26
0
function getClient()
{
    $config = (include __DIR__ . '/ini.php');
    $client = new Google_Client();
    $client->setApplicationName("Webkameleon");
    $client->setClientId($config['oauth2_client_id']);
    $client->setClientSecret($config['oauth2_client_secret']);
    $client->setRedirectUri($config['oauth2_redirect_uri']);
    $client->setScopes($config['oauth2_scopes']);
    $client->setState('offline');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        die($client->getAccessToken());
    } elseif (!isset($config['token'])) {
        Header('Location: ' . $client->createAuthUrl());
    } else {
        $client->setAccessToken($config['token']);
        if ($client->isAccessTokenExpired()) {
            $token = json_decode($config['token'], true);
            $client->refreshToken($token['refresh_token']);
        }
    }
    return $client;
}
 public static function revokeAccessToken()
 {
     $xmpData = erLhcoreClassModelChatConfig::fetch('xmp_data');
     $data = (array) $xmpData->data;
     try {
         if (isset($data['gtalk_client_token']) && $data['gtalk_client_token'] != '') {
             require_once 'lib/core/lhxmp/google/Google_Client.php';
             $client = new Google_Client();
             $client->setApplicationName('Live Helper Chat');
             $client->setScopes(array("https://www.googleapis.com/auth/googletalk", "https://www.googleapis.com/auth/userinfo.email"));
             $client->setClientId($data['gtalk_client_id']);
             $client->setClientSecret($data['gtalk_client_secret']);
             $client->setAccessType('offline');
             $client->setApprovalPrompt('force');
             $token = $data['gtalk_client_token'];
             $client->setAccessToken($data['gtalk_client_token']);
             // Refresh token if it's
             if ($client->isAccessTokenExpired()) {
                 $tokenData = json_decode($token);
                 $client->refreshToken($tokenData->refresh_token);
                 $accessToken = $client->getAccessToken();
             }
             if ($accessToken = $client->getAccessToken()) {
                 $client->revokeToken();
             }
             unset($data['gtalk_client_token']);
             $xmpData->value = serialize($data);
             $xmpData->saveThis();
         }
         return true;
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * @throws MissingConfigurationException
  * @return \Google_Client
  */
 public function create()
 {
     $client = new \Google_Client();
     $requiredAuthenticationSettings = array('applicationName', 'clientId', 'clientSecret', 'developerKey');
     foreach ($requiredAuthenticationSettings as $key) {
         if (!isset($this->authenticationSettings[$key])) {
             throw new MissingConfigurationException(sprintf('Missing setting "TYPO3.Neos.GoogleAnalytics.authentication.%s"', $key), 1415796352);
         }
     }
     $client->setApplicationName($this->authenticationSettings['applicationName']);
     $client->setClientId($this->authenticationSettings['clientId']);
     $client->setClientSecret($this->authenticationSettings['clientSecret']);
     $client->setDeveloperKey($this->authenticationSettings['developerKey']);
     $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
     $client->setAccessType('offline');
     $accessToken = $this->tokenStorage->getAccessToken();
     if ($accessToken !== NULL) {
         $client->setAccessToken($accessToken);
         if ($client->isAccessTokenExpired()) {
             $refreshToken = $this->tokenStorage->getRefreshToken();
             $client->refreshToken($refreshToken);
         }
     }
     return $client;
 }
 /**
  * Return Google Content Client Instance
  *
  * @param int  $storeId
  * @param bool $noAuthRedirect
  *
  * @return bool|Google_Client
  */
 public function getClient($storeId, $noAuthRedirect = false)
 {
     if (isset($this->_client)) {
         if ($this->_client->isAccessTokenExpired()) {
             return $this->redirectToAuth($storeId, $noAuthRedirect);
         }
         return $this->_client;
     }
     $clientId = $this->getConfig()->getConfigData('client_id', $storeId);
     $clientSecret = $this->getConfig()->getClientSecret($storeId);
     $accessToken = $this->_getAccessToken($storeId);
     if (!$clientId || !$clientSecret) {
         Mage::getSingleton('adminhtml/session')->addError("Please specify Google Content API access data for this store!");
         return false;
     }
     if (!isset($accessToken) || empty($accessToken)) {
         return $this->redirectToAuth($storeId, $noAuthRedirect);
     }
     $this->_client = new Google_Client();
     $this->_client->setApplicationName(self::APPNAME);
     $this->_client->setClientId($clientId);
     $this->_client->setClientSecret($clientSecret);
     $this->_client->setScopes('https://www.googleapis.com/auth/content');
     $this->_client->setAccessToken($accessToken);
     if ($this->_client->isAccessTokenExpired()) {
         return $this->redirectToAuth($storeId, $noAuthRedirect);
     }
     if ($this->getConfig()->getIsDebug($storeId)) {
         $this->_client->setLogger(Mage::getModel('gshoppingv2/logger', $this->_client)->setStoreID($storeId));
     }
     return $this->_client;
 }
Example #30
-1
 function setAppConfig($approval = 'auto')
 {
     $this->client = new Google_Client();
     /* Set Retries */
     $this->client->setClassConfig('Google_Task_Runner', 'retries', 5);
     $this->userInfoService = new Google_Service_Oauth2($this->client);
     $this->googleDriveService = new Google_Service_Drive($this->client);
     $this->googleUrlshortenerService = new Google_Service_Urlshortener($this->client);
     if (!empty($this->settings['googledrive_app_client_id']) && !empty($this->settings['googledrive_app_client_secret'])) {
         $this->client->setClientId($this->settings['googledrive_app_client_id']);
         $this->client->setClientSecret($this->settings['googledrive_app_client_secret']);
     } else {
         $this->client->setClientId('538839470620-fvjmtsvik53h255bnu0qjmbr8kvd923i.apps.googleusercontent.com');
         $this->client->setClientSecret('UZ1I3I-D4rPhXpnE8T1ggGhE');
     }
     $this->client->setRedirectUri('http://www.florisdeleeuw.nl/use-your-drive/index.php');
     $this->client->setApprovalPrompt($approval);
     $this->client->setAccessType('offline');
     $this->client->setScopes(array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/urlshortener'));
     $page = isset($_GET["page"]) ? '?page=' . $_GET["page"] : '';
     $location = get_admin_url(null, 'admin.php' . $page);
     $this->client->setState(strtr(base64_encode($location), '+/=', '-_~'));
     /* Logger */
     $this->client->setClassConfig('Google_Logger_File', array('file' => USEYOURDRIVE_CACHEDIR . '/log', 'mode' => 0640, 'lock' => true));
     $this->client->setClassConfig('Google_Logger_Abstract', array('level' => 'debug', 'log_format' => "[%datetime%] %level%: %message% %context%\n", 'date_format' => 'd/M/Y:H:i:s O', 'allow_newlines' => true));
     /* Uncomment the following line to log communcations.
      * The log is located in /cache/log
      */
     //$this->client->setLogger(new Google_Logger_File($this->client));
     return true;
 }