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; }
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; }
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()); }
/** * 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'); }
public function __construct(\Google_Client $googleClient, $clientSecretPath) { $this->_googleClient = $googleClient; $this->_googleClient->setAuthConfigFile($clientSecretPath); $this->_googleClient->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/loginGoogle'); $this->_googleClient->addScope(\Google_Service_Gmail::GMAIL_READONLY); $this->_gmailService = new \Google_Service_Gmail($this->_googleClient); }
/** * @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'); }
/** * 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"]); }
/** * 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(); }
/** * 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(); }
/** * 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"]); }
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')); } }
private function getGoogleClient() { $client = new Google_Client(); $client->setApplicationName($this->__('Login with Google')); $client->setClientId(Mage::getStoreConfig('gomage_social/google/id')); $client->setClientSecret(Mage::getStoreConfig('gomage_social/google/secret')); if ($this->getRequest()->getParam('google_plus', 0) == 1) { $client->setRedirectUri('postmessage'); } else { $callback_params = array('_secure' => true); $callback_url = Mage::getUrl('gomage_social/google/callback', $callback_params); $client->setRedirectUri($callback_url); } $client->setDeveloperKey(Mage::getStoreConfig('gomage_social/google/api')); return $client; }
public function callback() { $client = new Google_Client(); $client->setApplicationName($this->__app_name); $client->setClientId($this->__client_id); $client->setClientSecret($this->__client_secret); $client->setRedirectUri($this->__redirect_uri); $client->setDeveloperKey($this->__develop_key); $client->setScopes('https://www.googleapis.com/auth/calendar'); $client->setAccessType('offline'); if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $_SESSION['token'] = $client->getAccessToken(); $this->Session->delete('HTTP_REFERER'); header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } // 呼び出し先 if (isset($_SESSION['oauth_referer'])) { $url = $_SESSION['oauth_referer']; $this->Session->delete('oauth_referer'); } else { $url = 'index'; } $this->redirect('/'); }
/** * 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(); } } }
function bdn_is_user_auth2() { global $driveService; $current_user_id = get_current_user_id(); $client = new Google_Client(); $client->setRedirectUri(home_url('/')); $driveService = new Google_DriveService($client); $oauth2 = new Google_Oauth2Service($client); if (!isset($_GET['code']) && (!is_user_logged_in() || ($access_token = get_user_meta($current_user_id, '_google_access_token', true)) && $client->setAccessToken($access_token) && !$client->getAccessToken())) { header('Location: ' . $client->createAuthUrl()); exit; } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $user = $oauth2->userinfo->get(); $new_user = get_user_by('email', $user['email']); if (!$current_user_id) { wp_set_current_user($new_user->ID, $new_user->user_login); wp_set_auth_cookie($new_user->ID); do_action('wp_login', $new_user->user_login); } elseif ($new_user->ID == $current_user_id) { update_user_meta($new_user->ID, '_google_access_token', $client->getAccessToken()); } else { die('Sorry, please use your BDN account'); } header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } return $driveService; }
/** * 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']); }
/** * Returns an authorized API client. * @return Google_Client the authorized client object */ function getClient() { $client = new Google_Client(); $client->setApplicationName("Study Group Finder"); $client->setAuthConfigFile(__DIR__ . '/client_secret.json'); $client->addScope(Google_Service_Calendar::CALENDAR); $client->setRedirectUri(current_url()); if (isset($_SESSION["googleauth"])) { $client->setAccessToken($_SESSION["googleauth"]); $_SESSION["googleauth"] = NULL; return $client; } if (!isset($_GET['code'])) { // Request authorization from the user. $authUrl = $client->createAuthUrl(); header("Location: {$authUrl}"); exit(0); } $authCode = $_GET['code']; // Exchange authorization code for an access token. $accessToken = $client->authenticate($authCode); $_SESSION["googleauth"] = $accessToken; header("Location: calendar.php"); exit(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; }
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); }
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)); } }
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); }
public static function getClient() { $creds = GoogleSessionController::getCreds(); $client = new Google_Client(); $env = Config::getEnvironment(); if ($env == 'local' && $creds->oauth_local_path) { $client->setAuthConfigFile($creds->oauth_local_path); } else { if ($creds->oauth_remote_path) { $client->setAuthConfigFile($creds->oauth_remote_path); } else { $client->setApplicationName($creds->app_name); $client->setClientId($creds->client_id); $client->setClientSecret($creds->client_secret); } } $client->setRedirectUri(GoogleSessionController::getRedirectURI()); $hd = Config::get('config.google.hd'); if ($hd) { $client->setHostedDomain($hd); } $client->setAccessType('offline'); $client->addScope("https://www.googleapis.com/auth/userinfo.profile"); $client->addScope("https://www.googleapis.com/auth/userinfo.email"); $client->setScopes($creds->scopes); return $client; }
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; }
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; }
/** * 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); } }
/** * 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); } }
public function index() { // include_once APPPATH . 'libraries/Facebook/facebook.php'; // $facebook = new Facebook([ // 'appId' => '852953064822534', // 'secret' => '29888930212d679180731cc5232732c8' // ]); // $user = $facebook->getUser(); include_once APPPATH . 'libraries/Google/autoload.php'; $client_id = GOOGLE_CLIENT_ID; $client_secret = GOOGLE_CLIENT_SECRET; $redirect_uri = GOOGLE_REDIRECT_URL; // Create Client Request to access Google API $client = new Google_Client(); $client->setApplicationName("PHP Google OAuth Login Example"); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->addScope("https://www.googleapis.com/auth/userinfo.email"); // Send Client Request $objOAuthService = new Google_Service_Oauth2($client); // Add Access Token to Session if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $this->session->set_userdata(array('access_token' => $client->getAccessToken())); // header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); } // Set Access Token to make Request if ($this->session->userdata('access_token') != null) { $client->setAccessToken($this->session->userdata('access_token')); } // Get User Data from Google and store them in $data if ($client->getAccessToken()) { $userData = $objOAuthService->userinfo->get(); $data['userData'] = $userData; $this->session->set_userdata(array('access_token' => $client->getAccessToken())); $ret = $this->User_model->addUser($data['userData']); if ($ret == 'SUSPENDED') { $unset = array('access_token'); $this->session->unset_userdata($unset); $newdata = array('error' => "<font color='red'>Your account has been suspended</font>"); $this->session->set_flashdata($newdata); redirect('signin'); } else { if ($ret == 'FAIL') { $newdata = array('error' => "<font color='red'>Something is issue with login</font>"); $this->session->set_flashdata($newdata); redirect('signin'); } } redirect('dashboard'); } else { $authUrl = $client->createAuthUrl(); $data['authUrl'] = $authUrl; // $data['fbLoginUrl'] = $fbLoginUrl; loadView('signIn', $data); } }
public function __construct(\Google_Client $client) { $client->setApplicationName("magicpi"); $client->setScopes([\Google_Service_Calendar::CALENDAR_READONLY]); $client->setAuthConfigFile(__DIR__ . "/../config/piauth.json"); $client->setAccessType('offline'); $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/auth'); $this->client = $client; }
public function google() { $client = new \Google_Client(); $client->setClientId(\Config::get('google-id')); $client->setClientSecret(\Config::get('google-secret')); $client->setRedirectUri(\URL::route('google-auth')); $client->addScope('https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'); return $client; }