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);
     }
 }
Example #2
3
 public function actionToken()
 {
     //$this->checkAccess("token");
     $client = new \Google_Client();
     $client->setClientId(Yii::$app->params['OAUTH2_CLIENT_ID']);
     $client->setClientSecret(Yii::$app->params['OAUTH2_CLIENT_SECRET']);
     $client->setScopes('https://www.googleapis.com/auth/youtube');
     //$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
     $client->setRedirectUri(Yii::$app->params['redirectVideo']);
     if (Yii::$app->request->get('code')) {
         if (strval(Yii::$app->session->get('state')) !== strval(Yii::$app->request->get('state'))) {
             die('The session state did not match.');
         }
         $client->authenticate(Yii::$app->request->get('code'));
         if ($client->getAccessToken()) {
             $token = $this->getToken();
             $token->load(json_decode($client->getAccessToken(), true), "");
             $token->save();
             return ["token_saved" => $token];
         }
         return ["token_not_saved_code" => Yii::$app->request->get('code')];
     }
     if (!$client->getAccessToken()) {
         // If the user hasn't authorized the app, initiate the OAuth flow
         //$state = mt_rand();
         $client->setState(Yii::$app->params['stateVideo']);
         $client->setAccessType("offline");
         $client->setApprovalPrompt("force");
         Yii::$app->session->set('state', Yii::$app->params['stateVideo']);
         $authUrl = $client->createAuthUrl();
         return ["link" => $authUrl];
     }
 }
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
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;
 }
Example #5
0
 /**
  * @param string $clientId
  * @param string $clientSecret
  * @param string $accessType
  */
 public function __construct($clientId, $clientSecret, $accessType = 'offline')
 {
     $client = new \Google_Client();
     // Get your credentials from the APIs Console
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     // Apparently you need to force to get refresh token
     if ($accessType === 'offline') {
         $client->setApprovalPrompt('force');
     } else {
         $client->setApprovalPrompt('auto');
     }
     $client->setAccessType($accessType);
     $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
     $this->client = $client;
 }
Example #6
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 #7
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;
}
Example #8
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 #9
0
 /**
  * Constructor stores the passed Google Client object, sets a bunch of config options from the config file, and also
  * creates and instance of the \Google_Service_YouTube class and stores this for later use.
  *
  * @param \Google_Client $client
  */
 public function __construct(\Google_Client $client)
 {
     $this->client = $client;
     $this->client->setApplicationName(\Config::get('laravel-youtube::application_name'));
     $this->client->setClientId(\Config::get('laravel-youtube::client_id'));
     $this->client->setClientSecret(\Config::get('laravel-youtube::client_secret'));
     $this->client->setScopes(\Config::get('laravel-youtube::scopes'));
     $this->client->setAccessType(\Config::get('laravel-youtube::access_type'));
     $this->client->setApprovalPrompt(\Config::get('laravel-youtube::approval_prompt'));
     $this->client->setRedirectUri(\URL::to(\Config::get('laravel-youtube::redirect_uri')));
     $this->client->setClassConfig('Google_Http_Request', 'disable_gzip', true);
     $this->youtube = new \Google_Service_YouTube($this->client);
     $accessToken = $this->getLatestAccessTokenFromDB();
     if ($accessToken) {
         $this->client->setAccessToken($accessToken);
     }
 }
Example #10
0
 /**
  * @param $staff_id
  * @return string
  */
 public function createAuthUrl($staff_id)
 {
     $this->client->setRedirectUri($this->generateRedirectURI());
     $this->client->addScope('https://www.googleapis.com/auth/calendar');
     $this->client->setState(strtr(base64_encode($staff_id), '+/=', '-_,'));
     $this->client->setApprovalPrompt('force');
     $this->client->setAccessType('offline');
     return $this->client->createAuthUrl();
 }
 /**
  * Returns an authorized API client.
  *
  * @return \Google_Client the authorized client object
  */
 public function getClient()
 {
     $client = new \Google_Client();
     $client->setApplicationName($this->applicationName);
     $client->setScopes(implode(' ', $this->scopes));
     $client->setAuthConfigFile($this->authConfigFile);
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     return $client;
 }
Example #12
0
 /**
  * @param array $config
  */
 public function __construct(array $config)
 {
     $this->config = $config;
     // create an instance of the google client for OAuth2
     $this->client = new \Google_Client();
     // set application name
     $this->client->setApplicationName(array_get($config, 'application_name', ''));
     // set oauth2 configs
     $this->client->setClientId(array_get($config, 'client_id', ''));
     $this->client->setClientSecret(array_get($config, 'client_secret', ''));
     $this->client->setRedirectUri(array_get($config, 'redirect_uri', ''));
     $this->client->setScopes(array_get($config, 'scopes', []));
     $this->client->setAccessType(array_get($config, 'access_type', 'online'));
     $this->client->setApprovalPrompt(array_get($config, 'approval_prompt', 'auto'));
     // set developer key
     $this->client->setDeveloperKey(array_get($config, 'developer_key', ''));
     // auth for service account
     $this->auth();
 }
 /**
  *
  */
 protected function _setGoogleClient()
 {
     $googleClient = new Google_Client();
     $googleClient->setAuthConfigFile($this->_getConfigFilePath());
     $googleClient->addScope($this->_getScopes());
     $googleClient->setRedirectUri(Router::url(array('plugin' => 'auth_manager', 'controller' => 'media_platform_users', 'action' => 'callback', $this->_getPlatformId()), true));
     // This will force Google to always return the refresh_token.
     $googleClient->setAccessType('offline');
     $googleClient->setApprovalPrompt('force');
     $this->_client = $googleClient;
 }
Example #14
0
 /**
  * @return \Google_Client
  */
 private function getGoogleClient()
 {
     if (null === self::$client) {
         $container = $this->container;
         $client = new \Google_Client();
         $client->setClientId($container->getParameter('google_client_id'));
         $client->setClientSecret($container->getParameter('google_client_secret'));
         $client->setApprovalPrompt('auto');
         self::$client = $client;
     }
     return self::$client;
 }
function getNewToken()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setHostedDomain('email.wosc.edu');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $client->setRedirectUri($GMAIL->callback);
    $auth_url = $client->createAuthUrl();
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
}
 /**
  * Instantiate the Google API and feed provided config values
  * We require a long-lived access token
  */
 function __construct()
 {
     parent::__construct();
     $siteConfig = SiteConfig::current_site_config();
     $appID = $siteConfig->YouTubeFeed_AppID;
     $appSecret = $siteConfig->YouTubeFeed_AppSecret;
     $this->client = new Google_Client();
     $this->client->setScopes('https://www.googleapis.com/auth/youtube');
     $this->client->setAccessType('offline');
     $this->client->setApprovalPrompt('force');
     if (!Director::is_cli()) {
         $this->client->setRedirectUri(Director::absoluteBaseURL() . 'youtube/authenticate');
     }
     if ($appID && $appSecret) {
         $this->client->setClientId($appID);
         $this->client->setClientSecret($appSecret);
         $this->service = new Google_Service_YouTube($this->client);
         if ($accessToken = $this->getConfigToken()) {
             $this->client->setAccessToken($accessToken);
         }
     }
 }
Example #17
0
 private function getGoogleClient()
 {
     if (isset($this->google_client_id) && isset($this->google_client_secret) && isset($this->google_redirect_url) && isset($this->google_developer_key)) {
         $requestVisibleActions = array('http://schemas.google.com/AddActivity', 'http://schemas.google.com/BuyActivity', 'http://schemas.google.com/CheckInActivity', 'http://schemas.google.com/CommentActivity', 'http://schemas.google.com/CreateActivity', 'http://schemas.google.com/DiscoverActivity', 'http://schemas.google.com/ListenActivity', 'http://schemas.google.com/ReserveActivity', 'http://schemas.google.com/ReviewActivity', 'http://schemas.google.com/WantActivity');
         $gClient = new Google_Client();
         $gClient->setApplicationName('Login to ceri2013.cafe24.com');
         $gClient->setClientId($this->google_client_id);
         $gClient->setClientSecret($this->google_client_secret);
         $gClient->setRedirectUri($this->google_redirect_url);
         $gClient->setDeveloperKey($this->google_developer_key);
         $gClient->setRequestVisibleActions($requestVisibleActions);
         $gClient->setApprovalPrompt('auto');
         return $gClient;
     }
 }
Example #18
0
function googleConnect()
{
    require_once 'lib/Google/autoload.php';
    /* * *********************Google login************************ */
    $client = new Google_Client();
    $client->setClientId(CLIENT_ID);
    $client->setClientSecret(CLIENT_SECRET);
    $client->setRedirectUri(GOOGLE_REDIRECT_URI);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $client->addScope("openid email");
    $client->addScope("https://picasaweb.google.com/data/");
    $client->addScope("https://www.googleapis.com/auth/userinfo.profile");
    return $client;
}
Example #19
0
 public function __construct()
 {
     App::import("Vendor", "GoogleApiClient", array("file" => "google-api-php-client/src/Google_Client.php"));
     App::import("Vendor", "GoogleBigqueryApi", array("file" => "google-api-php-client/src/contrib/Google_BigqueryService.php"));
     $apiClient = new Google_Client();
     $apiClient->setApplicationName("Testing App");
     $apiClient->setClientId("*****@*****.**");
     $apiClient->setClientSecret("dhWNmyamq9LPLfMpWStQbmww");
     $apiClient->setRedirectUri("http://" . $_SERVER['HTTP_HOST'] . "/tester/goog_callback");
     $apiClient->setScopes(array('https://www.googleapis.com/auth/bigquery'));
     $apiClient->setApprovalPrompt("auto");
     $apiClient->setAccessToken($this->accessToken);
     $this->apiClient = $apiClient;
     $this->bq = new Google_BigqueryService($apiClient);
 }
/** 
* Lets first get an authorization URL to our client, it will forward the client to Google's Concent window
* @param String $emailAddress
* @param String $state
* @return String URL to Google Concent screen
*/
function getAuthorizationUrl($emailAddress, $state)
{
    global $CLIENT_ID, $REDIRECT_URI, $SCOPES;
    $client = new Google_Client();
    $client->setClientId($CLIENT_ID);
    $client->setRedirectUri($REDIRECT_URI);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('auto');
    $client->setState($state);
    $client->setScopes($SCOPES);
    $tmpUrl = parse_url($client->createAuthUrl());
    $query = explode('&', $tmpUrl['query']);
    $query[] = 'user_id=' . urlencode($emailAddress);
    return $tmpUrl['scheme'] . '://' . $tmpUrl['host'] . $tmpUrl['path'] . '?' . implode('&', $query);
}
 public static function getClient()
 {
     // $config = self::loadConfig();
     $client = new Google_Client();
     $client->setAuthConfigFile(dirname(__FILE__) . '/client_secret.json');
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . FOLDER_APP);
     $client->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM);
     $client->addScope(Google_Service_Gmail::GMAIL_COMPOSE);
     $client->addScope(Google_Service_Gmail::GMAIL_MODIFY);
     $client->addScope('http://www.google.com/m8/feeds/');
     $client->addScope('https://www.googleapis.com/auth/userinfo.email');
     $client->setIncludeGrantedScopes(true);
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     return $client;
 }
 /**
  * Initialize API to Google and YouTube
  *
  * @param string $oAuthRedirectUrl
  * @throws LiveBroadcastOutputException
  */
 public function initApiClients($oAuthRedirectUrl)
 {
     if (empty($this->clientId) || empty($this->clientSecret)) {
         throw new LiveBroadcastOutputException('The YouTube oAuth settings are not correct.');
     }
     $googleApiClient = new \Google_Client();
     $googleApiClient->setLogger($this->logger);
     $googleApiClient->setClientId($this->clientId);
     $googleApiClient->setClientSecret($this->clientSecret);
     $googleApiClient->setScopes('https://www.googleapis.com/auth/youtube');
     $googleApiClient->setAccessType('offline');
     $googleApiClient->setRedirectUri($oAuthRedirectUrl);
     $googleApiClient->setApprovalPrompt('force');
     $this->googleApiClient = $googleApiClient;
     $this->youTubeApiClient = new \Google_Service_YouTube($googleApiClient);
 }
Example #23
0
 public function signinPage()
 {
     /* Store values in variables from project created in Google Developer Console */
     $client_id = '420762774972-sng0pvjsvaht2f4aq86qk65j9317qrs7.apps.googleusercontent.com';
     $client_secret = 'jFJJi-BKnEwKUcA6jaCglXq4';
     $redirect_uri = 'http://localhost/rentrmnl/';
     $simple_api_key = 'AIzaSyBWWornRguaHPgQJFRn74qHQD3ZxbelM_Q';
     /* Create Client Request to access Google API */
     $client = new Google_Client();
     $client->setApplicationName("renTRMNL");
     $client->setClientId($client_id);
     $client->setClientSecret($client_secret);
     $client->setRedirectUri($redirect_uri);
     $client->setDeveloperKey($simple_api_key);
     $client->addScope("https://www.googleapis.com/auth/userinfo.email");
     $client->setApprovalPrompt('auto');
     /* Send Client Request */
     $objOAuthService = new Google_Service_Oauth2($client);
     /* Add Access Token to Session */
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         /* Get User Data from Google  */
         $user = $objOAuthService->userinfo->get();
         $result = $this->Lessee->googleLogin($user);
         if (is_array($result)) {
             $userdata = array('lessee_id' => $result['lessee_id'], 'username' => $result['username'], 'lessee_fname' => $result['lessee_fname'], 'lessee_lname' => $result['lessee_lname'], 'lessee_email' => $result['lessee_email'], 'lessee_phoneno' => $result['lessee_phoneno'], 'image' => $user['picture'], 'access_token' => $client->getAccessToken(), 'logged_in' => TRUE);
         } else {
             $userdata = array('lessee_id' => $result, 'username' => $user['id'], 'lessee_fname' => $user['givenName'], 'lessee_lname' => $user['familyName'], 'lessee_email' => $user['email'], 'lessee_phoneno' => "", 'image' => $user['picture'], 'access_token' => $client->getAccessToken(), 'logged_in' => TRUE);
         }
         $this->session->set_userdata($userdata);
         redirect('lessee/dashboard');
     }
     /* Set Access Token to make Request */
     if ($this->session->has_userdata('access_token')) {
         $client->setAccessToken($this->session->userdata('access_token'));
     }
     if ($client->getAccessToken()) {
         $this->session->set_userdata('access_token', $client->getAccessToken());
         redirect('lessee/dashboard');
     }
     $authUrl = $client->createAuthUrl();
     $content['authUrl'] = $authUrl;
     $content['action'] = site_url('lessees/signin');
     $data['content'] = $this->load->view('pages/signin', $content, TRUE);
     $data['title'] = 'SIGN IN';
     $this->load->view('common/plain', $data);
 }
Example #24
0
 public static function getClient()
 {
     $config = self::loadConfig();
     $client = new \Google_Client();
     $client->setApplicationName('Rapid Web Google Contacts API');
     $client->setScopes(array('https://www.google.com/m8/feeds/'));
     $client->setClientId($config->clientID);
     $client->setClientSecret($config->clientSecret);
     $client->setRedirectUri($config->redirectUri);
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     $client->setDeveloperKey($config->developerKey);
     if (isset($config->refreshToken) && $config->refreshToken) {
         $client->refreshToken($config->refreshToken);
     }
     return $client;
 }
Example #25
0
function nextend_api_auth_flow()
{
    $api_key = NextendRequest::getVar('api_key');
    $api_secret = NextendRequest::getVar('api_secret');
    $redirect_uri = NextendRequest::getVar('redirect_uri');
    if (session_id() == "") {
        @session_start();
    }
    if (!$api_key || !$api_secret || !$redirect_uri) {
        $api_key = isset($_SESSION['api_key']) ? $_SESSION['api_key'] : null;
        $api_secret = isset($_SESSION['api_secret']) ? $_SESSION['api_secret'] : null;
        $redirect_uri = isset($_SESSION['redirect_uri']) ? $_SESSION['redirect_uri'] : null;
    } else {
        $_SESSION['api_key'] = $api_key;
        $_SESSION['api_secret'] = $api_secret;
        $_SESSION['redirect_uri'] = $redirect_uri;
    }
    if ($api_key && $api_secret) {
        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';
        }
        $client = new Google_Client();
        $client->setClientId($api_key);
        $client->setClientSecret($api_secret);
        $client->setRedirectUri($redirect_uri);
        $client->setApprovalPrompt('auto');
        $client->setAccessType('offline');
        $youtube = new Google_YouTubeService($client);
        if (isset($_GET['code'])) {
            $client->authenticate($_GET['code']);
            $accessToken = $client->getAccessToken();
            unset($_SESSION['api_key']);
            unset($_SESSION['api_secret']);
            unset($_SESSION['redirect_uri']);
            echo '<script type="text/javascript">';
            echo 'window.opener.setToken(\'' . $accessToken . '\');';
            echo '</script>';
        } else {
            $authUrl = $client->createAuthUrl();
            header('LOCATION: ' . $authUrl);
        }
    }
}
Example #26
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', 'email', 'profile'));
     //$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
     //Check for token
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $accessToken = json_decode($client->getAccessToken(), true);
         $google_id = $this->logged_in($client);
         if (is_numeric($google_id) && $google_id != 0) {
             //Check that we have created the user
             //if we have a token do something
             $this->save_token($google_id, $accessToken['access_token'], $accessToken['refresh_token']);
         } else {
             $data['base_url'] = $this->config->item('base_url');
             $data['auth_url'] = $client->createAuthUrl();
             //Set canonical URL
             $data['canonical'] = $this->config->item('base_url');
             $this->load->view('half_login', $data);
         }
     } else {
         $data['base_url'] = $this->config->item('base_url');
         $data['auth_url'] = $client->createAuthUrl();
         //Set canonical URL
         $data['canonical'] = $this->config->item('base_url');
         $this->load->view('home', $data);
     }
 }
 public function index()
 {
     ini_set("display_errors", 1);
     $youtubeClientIdAry = $this->M_Configuration->getConfigurationDetails('youtube_clientId');
     $youtubeClientSecretAry = $this->M_Configuration->getConfigurationDetails('youtube_clientSecret');
     $OAUTH2_CLIENT_ID = $youtubeClientIdAry->configuration_data;
     $OAUTH2_CLIENT_SECRET = $youtubeClientSecretAry->configuration_data;
     if (isset($_GET['code'])) {
         $url = 'https://accounts.google.com/o/oauth2/token';
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_FAILONERROR, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         $code = $_GET['code'];
         curl_setopt($ch, CURLOPT_POSTFIELDS, 'code=' . $code . '&' . 'client_id=' . $OAUTH2_CLIENT_ID . '&' . 'client_secret=' . $OAUTH2_CLIENT_SECRET . '&' . 'redirect_uri=' . urlencode('http://mystory.buzz/admin/getRefreshToken') . '&' . 'grant_type=' . 'authorization_code');
         $output = curl_exec($ch);
         curl_close($ch);
         echo $output;
         $obj = json_decode($output);
         $token = $obj->{'refresh_token'};
         $insertVal = array('youtube_refreshToken' => $token);
         $result = $this->M_Configuration->saveDetails($insertVal);
         exit;
     }
     $client = new Google_Client();
     $client->setClientId($OAUTH2_CLIENT_ID);
     //$client->setClientSecret($OAUTH2_CLIENT_SECRET);
     //$client->refreshToken('1/ZniNI97r2y14HXQzW15JC-3VeaMCjVFXIbOCFRjVPEUMEudVrK5jSpoR30zcRFq6');
     $client->setScopes('https://gdata.youtube.com');
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     $redirect = filter_var('http://mystory.buzz/admin/getRefreshToken', FILTER_SANITIZE_URL);
     $client->setRedirectUri($redirect);
     // If the user hasn't authorized the app, initiate the OAuth flow
     $state = mt_rand();
     $client->setState($state);
     $_SESSION['state'] = $state;
     $authUrl = $client->createAuthUrl();
     $data['authUrl'] = $authUrl;
     $this->load->view('configuration/v_refreshToken', $data);
 }
 public function google_login()
 {
     $this->autoRender = false;
     //      require_once '../Config/google_login.php';
     $client = new Google_Client();
     $client->setScopes(array('https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me'));
     $client->setApprovalPrompt('auto');
     $plus = new Google_PlusService($client);
     $oauth2 = new Google_Oauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate();
         // Authenticate
         //            $_SESSION['access_token'] = $client->getAccessToken(); // get the access token here
     }
     //var_dump('aaaa');
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->getAccessToken()) {
         $_SESSION['access_token'] = $client->getAccessToken();
         $user = $oauth2->userinfo->get();
         // var_dump($user);
         // exit;
         if (!empty($user)) {
             //すでに登録済みかどうか
             $result = $this->Snsuser->getItemBySNSid($user['id'], GOOGLEKEY);
             //登録済みログイン
             if (!empty($result)) {
                 $bid = $result['Snsuser']['beautyid'];
             } else {
                 //新規登録ログイン
                 $this->redirect(array('controller' => 'Regist', 'action' => 'input', '?' => array('sns_id' => $user['id'], 'sns' => GOOGLEKEY, 'username' => $user['name'], 'email' => $user['email'])));
             }
             $this->Cookie->write(SESSIONNAME, $bid, false, LOGINTIME);
             $this->redirect(REDIRECTURL);
         } else {
             //認証失敗indexに戻る
         }
     }
     exit;
 }
Example #29
0
function googleClient($redirect_uri)
{
    $ci = get_instance();
    require_once 'Google/autoload.php';
    $ci->load->config('config');
    $client_id = $ci->config->item('app_cid');
    $client_secret = $ci->config->item('app_secret');
    if (empty($client_id)) {
        return false;
    }
    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    $client->addScope('email');
    $client->addScope('https://mail.google.com');
    $client->addScope('https://www.googleapis.com/auth/calendar');
    $client->addScope('https://www.googleapis.com/auth/drive');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    return $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;
 }