public function index() { $this->id = "content"; $this->template = "login/login.tpl"; $this->layout = "common/layout"; $request = Registry::get('request'); $db = Registry::get('db'); $session = Registry::get('session'); $this->load->model('user/auth'); $this->load->model('user/user'); $this->load->model('user/prefs'); $this->load->model('user/google'); $this->load->model('domain/domain'); $this->load->model('folder/folder'); $this->document->title = $this->data['text_login']; $client = new apiClient(); $client->setApplicationName(GOOGLE_APPLICATION_NAME); $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://mail.google.com/')); $client->setClientId(GOOGLE_CLIENT_ID); $client->setClientSecret(GOOGLE_CLIENT_SECRET); $client->setRedirectUri(GOOGLE_REDIRECT_URL); $client->setDeveloperKey(GOOGLE_DEVELOPER_KEY); $oauth2 = new apiOauth2Service($client); if (isset($_GET['code'])) { $client->authenticate(); $session->set("access_token", $client->getAccessToken()); header('Location: ' . GOOGLE_REDIRECT_URL); } if ($session->get("access_token")) { $client->setAccessToken($session->get("access_token")); } if ($client->getAccessToken()) { $session->set("access_token", $client->getAccessToken()); $token = json_decode($session->get("access_token")); if (isset($token->{'access_token'}) && isset($token->{'refresh_token'})) { $account = $oauth2->userinfo->get(); $this->model_user_google->check_for_account($account); $this->model_user_google->update_tokens($account['email'], $account['id'], $token); header("Location: " . SITE_URL . "search.php"); exit; } } $this->render(); }
<?php require_once 'src/apiClient.php'; require_once 'src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Kindle Reader"); $client->setScopes(array('https://www.google.com/reader/api')); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_GET['code'])) { $client->authenticate(); $_SESSION['access_token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['access_token'])) { $client->setAccessToken($_SESSION['access_token']); } if ($client->getAccessToken()) { $_SESSION['access_token'] = $client->getAccessToken(); header('Location: sender.php'); } else { $status = "Logged Out"; $authUrl = $client->createAuthUrl(); header('Location: ' . $authUrl); }
* 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 '../../src/apiClient.php'; defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); $client = new apiClient(); // 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('INSERT_CLIENT_ID'); //$client->setClientSecret('INSERT_CLIENT_SECRET'); $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); $client->setScopes(array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/latitude', 'https://www.googleapis.com/auth/moderator', 'https://www.googleapis.com/auth/tasks', 'https://www.googleapis.com/auth/siteverification', 'https://www.googleapis.com/auth/urlshortener', 'https://www.googleapis.com/auth/adsense.readonly')); $authUrl = $client->createAuthUrl(); print "Please visit:\n{$authUrl}\n\n"; print "Please enter the auth code:\n"; $authCode = trim(fgets(STDIN)); $_GET['code'] = $authCode; $accessToken = $client->authenticate(); var_dump($accessToken);
* Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ // Include the Google API Client library, and the Buzz Service wrapper require_once "google-api-php-client/src/apiClient.php"; require_once "google-api-php-client/src/contrib/apiBuzzService.php"; // Setup the API Client, and create the Buzz client using it $apiClient = new apiClient(); $buzz = new apiBuzzService($apiClient); // If a oauth token was stored in the session, use that- and otherwise go through the oauth dance if (isset($_SESSION['auth_token'])) { $apiClient->setAccessToken($_SESSION['auth_token']); } else { // In a real application this would be stored in a database, and not in the session! $_SESSION['auth_token'] = $apiClient->authenticate(); }
// 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('insert_your_oauth2_client_id'); // $client->setClientSecret('insert_your_oauth2_client_secret'); // $client->setRedirectUri('insert_your_oauth2_redirect_uri'); // $client->setApplicationName("Tasks_Example_App"); $tasksService = new apiTasksService($client); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_SESSION['access_token'])) { $client->setAccessToken($_SESSION['access_token']); } else { $client->setAccessToken($client->authenticate()); $_SESSION['access_token'] = $client->getAccessToken(); } if (isset($_GET['code'])) { header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } ?> <!doctype html> <html> <head> <title>Tasks API Sample</title> <link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Droid+Serif|Droid+Sans:regular,bold' /> <link rel='stylesheet' href='css/style.css' /> </head> <body>
<?php session_start(); require_once "../src/apiClient.php"; require_once "../src/contrib/apiBuzzService.php"; $apiClient = new apiClient(); $buzz = new apiBuzzService($apiClient); //$apiClient->discover('buzz'); if (isset($_SESSION['oauth_access_token'])) { $apiClient->setAccessToken($_SESSION['oauth_access_token']); } else { $token = $apiClient->authenticate(); $_SESSION['oauth_access_token'] = $token; } /* // some day this should just work, however right now JSON-RPC only does unauthenticated requests.. $ret = apiBatch::execute( $apiClient->buzz->activities->list(array('userId' => '@me', 'scope' => '@self'), 'listActivitiesKey'), $apiClient->buzz->people->get(array('userId' => '@me'), 'getPeopleKey') ); echo "<pre>" . print_r($ret, true) . "</pre>"; */ /* $group = $buzz->insertGroups('@me', array('data' => array('title' => 'Test Group'))); echo "<pre>Created initial group:\n" . print_r($group, true) . "</pre>"; $group = $buzz->updateGroups($group['id'], '@me', array('data' => array('title' => 'Updated Group'))); echo "<pre>Updated group:\n" . print_r($group, true) . "</pre>"; echo "getGroups({$group['id']}, '@me');<br>"; $group = $buzz->getGroups($group['id'], '@me');
/** * Exchange an authorization code for OAuth 2.0 credentials. * * @param String $authorizationCode Authorization code to exchange for an * access token and refresh token. The refresh token is only returned by * Google on the very first exchange- when a user explicitly approves * the authorization request. * @return OauthCredentials OAuth 2.0 credentials object */ function GetOAuth2Credentials($authorizationCode) { $client = new apiClient(); $client->setClientId(Config::CLIENT_ID); $client->setClientSecret(Config::CLIENT_SECRET); $client->setRedirectUri(Config::REDIRECT_URI); /** * Ordinarily we wouldn't set the $_GET variable. However, the API library's * authenticate() function looks for authorization code in the query string, * so we want to make sure it is set to the correct value passed into the * function arguments. */ $_GET['code'] = $authorizationCode; $jsonCredentials = json_decode($client->authenticate()); $oauthCredentials = new OauthCredentials($jsonCredentials->access_token, isset($jsonCredentials->refresh_token) ? $jsonCredentials->refresh_token : null, $jsonCredentials->created, $jsonCredentials->expires_in, Config::CLIENT_ID, Config::CLIENT_SECRET); return $oauthCredentials; }
public function test_service() { App::import("Vendor", "GoogleApiClient", array("file" => "google-api-php-client/src/apiClient.php")); App::import("Vendor", "GoogleApiClient", array("file" => "google-api-php-client/src/contrib/apiBigqueryService.php")); $apiClient = new apiClient(); $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->authenticate(); }
public function index() { session_start(); $client = new apiClient(); $redirectUri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $client->setApplicationName('PHP, YouTube, OAuth2, and CodeIgniter Example'); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri($redirectUri); $client->setDeveloperKey(DEVELOPER_KEY); new apiPlusService($client); // Sets the OAuth2 scope. $this->load->library('youtube', array('apikey' => YOUTUBE_API_KEY)); // This example doesn't require authentication: // header("Content-type: text/plain"); // echo "Here is the output:\n"; // echo $this->youtube->getKeywordVideoFeed('pac man'); if (isset($_GET['code'])) { $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); header("Location: {$redirectUri}"); } if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); } if (!$client->getAccessToken()) { $authUrl = $client->createAuthUrl(); echo "<a class='login' href='{$authUrl}'>Connect Me!</a>"; } else { // The access token may have been updated lazily. $_SESSION['token'] = $client->getAccessToken(); header("Content-type: text/plain"); $accessToken = json_decode($_SESSION['token'])->access_token; echo "Here is the output:\n"; echo $this->youtube->getUserUploads('default', array('access_token' => $accessToken, 'prettyprint' => 'true')); } }
public function actionSyncActionsToGoogleCalendar() { $model = Yii::app()->params->profile; if (isset($_POST['ProfileChild'])) { foreach (array_keys($model->attributes) as $field) { if (isset($_POST['ProfileChild'][$field])) { $model->{$field} = $_POST['ProfileChild'][$field]; } } if ($model->syncGoogleCalendarId && isset($_SESSION['token'])) { $token = json_decode($_SESSION['token'], true); $model->syncGoogleCalendarRefreshToken = $token['refresh_token']; // used for accessing this google calendar at a later time $model->syncGoogleCalendarAccessToken = $_SESSION['token']; } $model->update(); } $admin = Yii::app()->params->admin; $googleIntegration = $admin->googleIntegration; // if google integration is activated let user choose if they want to link this calendar to a google calendar if ($googleIntegration) { $timezone = date_default_timezone_get(); require_once "protected/extensions/google-api-php-client/src/apiClient.php"; require_once "protected/extensions/google-api-php-client/src/contrib/apiCalendarService.php"; date_default_timezone_set($timezone); $client = new apiClient(); $syncGoogleCalendarName = null; // name of the Google Calendar that current user's actions are being synced to if it has been set if (isset($_GET['unlinkGoogleCalendar'])) { // user changed thier mind about linking their google calendar unset($_SESSION['token']); $model->syncGoogleCalendarId = null; $model->syncGoogleCalendarRefreshToken = null; // used for accessing this google calendar at a later time $model->syncGoogleCalendarAccessToken = null; $model->update(); $googleCalendarList = null; $client->setApplicationName("Google Calendar Integration"); // Visit https://code.google.com/apis/console?api=calendar to generate your // client id, client secret, and to register your redirect uri. $client->setClientId($admin->googleClientId); $client->setClientSecret($admin->googleClientSecret); $client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl('')); $client->setDeveloperKey($admin->googleAPIKey); $client->setAccessType('offline'); $googleCalendar = new apiCalendarService($client); if (isset($_GET['code'])) { // returning from google with access token $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); $calList = $googleCalendar->calendarList->listCalendarList(); $googleCalendarList = array(); foreach ($calList['items'] as $cal) { $googleCalendarList[$cal['id']] = $cal['summary']; } } else { $googleCalendarList = null; } } else { if ($model->syncGoogleCalendarRefreshToken) { $client->setClientId($admin->googleClientId); $client->setClientSecret($admin->googleClientSecret); $client->setDeveloperKey($admin->googleAPIKey); $client->setAccessToken($model->syncGoogleCalendarAccessToken); $googleCalendar = new apiCalendarService($client); // check if the access token needs to be refreshed // note that the google library automatically refreshes the access token if we need a new one, // we just need to check if this happend by calling a google api function that requires authorization, // and, if the access token has changed, save this new access token $testCal = $googleCalendar->calendars->get($model->syncGoogleCalendarId); if ($model->syncGoogleCalendarAccessToken != $client->getAccessToken()) { $model->syncGoogleCalendarAccessToken = $client->getAccessToken(); $model->update(); } $calendar = $googleCalendar->calendars->get($model->syncGoogleCalendarId); $syncGoogleCalendarName = $calendar['summary']; $calList = $googleCalendar->calendarList->listCalendarList(); $googleCalendarList = array(); foreach ($calList['items'] as $cal) { $googleCalendarList[$cal['id']] = $cal['summary']; } } else { $client->setApplicationName("Google Calendar Integration"); // Visit https://code.google.com/apis/console?api=calendar to generate your // client id, client secret, and to register your redirect uri. $client->setClientId($admin->googleClientId); $client->setClientSecret($admin->googleClientSecret); $client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl('')); $client->setDeveloperKey($admin->googleAPIKey); $client->setAccessType('offline'); $googleCalendar = new apiCalendarService($client); if (isset($_GET['code'])) { // returning from google with access token $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); $calList = $googleCalendar->calendarList->listCalendarList(); $googleCalendarList = array(); foreach ($calList['items'] as $cal) { $googleCalendarList[$cal['id']] = $cal['summary']; } } else { $googleCalendarList = null; } } } } else { $client = null; $googleCalendarList = null; } $this->render('syncActionsToGoogleCalendar', array('model' => $model, 'googleIntegration' => $googleIntegration, 'client' => $client, 'googleCalendarList' => $googleCalendarList, 'syncGoogleCalendarName' => $syncGoogleCalendarName)); }
function gplus_init_auth() { gplus_load(); $client = new apiClient(); $oauth2 = new apiOauth2Service($client); if (isset($_GET['code'])) { $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); } if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); } if ($client->getAccessToken()) { $user = $oauth2->userinfo->get(); $_SESSION['token'] = $client->getAccessToken(); } if (isset($user) && isset($_GET['code'])) { $_SESSION['gplusdata'] = $user; $_SESSION['gplus']['idm'] = $user['id']; $_SESSION['gplus']['pic'] = !empty($user['picture']) ? $user['picture'] : ''; redirectexit('action=gplus;auth=done'); } }
public function index() { $this->load->language('easycheck/auth'); $data['text_heading'] = $this->language->get('text_heading'); $data['text_describe'] = $this->language->get('text_describe'); $data['text_savetime'] = $this->language->get('text_savetime'); $data['text_reg_log'] = $this->language->get('text_reg_log'); $data['text_proceedguest'] = $this->language->get('text_proceedguest'); $data['text_guest'] = $this->language->get('text_guest'); $data['text_or'] = $this->language->get('text_or'); $data['btn_continue'] = $this->language->get('btn_continue'); $data['btn_facebook'] = $this->language->get('btn_facebook'); $data['btn_gplus'] = $this->language->get('btn_gplus'); $data['input_email'] = $this->language->get('input_email'); $data['input_passd'] = $this->language->get('input_passd'); $data['check_availability'] = $this->url->link('easycheck/auth/check_availability'); $data['login'] = $this->url->link('easycheck/auth/login'); $data['guest_login'] = $this->url->link('easycheck/auth/guest_login'); $data['address_url'] = $this->url->link('easycheck/address'); $data['cant_access'] = $this->language->get('cant_access'); $data['forgot_password'] = $this->url->link('account/forgotten', '', 'SSL'); ///////////////////////facebook & google login start//////////////////////////////// $appId = $this->settings['step']['facebook_login']['app_id']; $secret = $this->settings['step']['facebook_login']['app_secret']; $data['appId'] = $appId; $data['secret'] = $secret; //google login settings $this->load->library('googleSetup'); $client = new apiClient(); $redirect_url = HTTP_SERVER . 'index.php?route=easycheck/checkout'; $client->setClientId('702107489335-fsutq69eq4turib43ksldj8t59dsckul.apps.googleusercontent.com'); $client->setClientSecret('vvNUGsKFe3_pA8aK4w-LysBS'); $client->setDeveloperKey('702107489335-fsutq69eq4turib43ksldj8t59dsckul.apps.googleusercontent.com'); $client->setRedirectUri($redirect_url); $client->setApprovalPrompt(false); $oauth2 = new apiOauth2Service($client); $data['client'] = $client; $url = $client->createAuthUrl(); $data['url'] = $url; if (isset($this->request->get['code'])) { $client->authenticate(); $info = $oauth2->userinfo->get(); if (isset($info['given_name']) && $info['given_name'] != "") { $name = $info['given_name']; } else { $name = $info['name']; } $user_table = array('firstname' => $name, 'lastname' => $info['family_name'], 'email' => $info['email'], 'telephone' => '', 'fax' => '', 'password' => substr(md5(uniqid(rand(), true)), 0, 9), 'company' => '', 'company_id' => '', 'tax_id' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'postcode' => '', 'country_id' => '', 'zone_id' => '', 'customer_group_id' => 1, 'status' => 1, 'approved' => 1); $this->load->model('account/customer'); //getting customer info if already exists $users_check = $this->model_account_customer->getCustomerByEmail($info['email']); //adding customer if new if (empty($users_check)) { $this->model_account_customer->addFacebookGoogleCustomer($user_table); } $users_check = $this->model_account_customer->getCustomerByEmail($info['email']); //loging in the customer $users_pass = $this->customer->login($info['email'], '', true); $this->session->data['customer_id'] = $users_check['customer_id']; if ($users_pass == true) { echo '<script>window.opener.location.href ="' . $redirect_url . '"; window.close();</script>'; } else { echo '<script>window.opener.location.href ="' . $redirect_url . '"; window.close();</script>'; } } ///////////////////////facebook & google login start//////////////////////////////// unset($this->session->data['guest']); unset($this->session->data['payment_address']); unset($this->session->data['shipping_address']); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/easycheck/auth.tpl')) { return $this->load->view($this->config->get('config_template') . '/template/easycheck/auth.tpl', $data); } }