public function init() { parent::init(); // api dependencies $client = new Google_Client(); $client->setClassConfig('Google_Cache_File', 'directory', realpath(dirname(__FILE__) . '/../../giga_cache')); $client->setApplicationName($this->app_name); $client->setScopes(Google_Service_Analytics::ANALYTICS); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($this->client_email, array(Google_Service_Analytics::ANALYTICS), file_get_contents($this->keyfile))); $client->setClientID($this->client_id); $this->client = $client; }
public function googleoauth() { $file = File::get(__DIR__ . "/../../.google"); $file_arr = json_decode($file, true); $practice = DB::table('practiceinfo')->where('practice_id', '=', Session::get('practice_id'))->first(); $client_id = $file_arr['web']['client_id']; $client_secret = $file_arr['web']['client_secret']; $url = Request::URL(); $google = new Google_Client(); $google->setRedirectUri($url); $google->setApplicationName('NOSH ChartingSystem'); $google->setClientID($client_id); $google->setClientSecret($client_secret); $google->setAccessType('offline'); $google->setApprovalPrompt('force'); $google->setScopes(array('https://mail.google.com/')); if (isset($_REQUEST["code"])) { $credentials = $google->authenticate($_GET['code']); $result = json_decode($credentials, true); $data['google_refresh_token'] = $result['refresh_token']; DB::table('practiceinfo')->where('practice_id', '=', Session::get('practice_id'))->update($data); return Redirect::intended('/'); } else { $authUrl = $google->createAuthUrl(); header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL)); exit; } }
protected function googleoauth_refresh($practice_id) { $practice = DB::table('practiceinfo')->where('practice_id', '=', $practice_id)->first(); if ($practice->google_refresh_token != '') { $file = File::get(__DIR__ . "/../../.google"); $file_arr = json_decode($file, true); $client_id = $file_arr['web']['client_id']; $client_secret = $file_arr['web']['client_secret']; $google = new Google_Client(); $google->setClientID($client_id); $google->setClientSecret($client_secret); $google->refreshToken($practice->google_refresh_token); $credentials = $google->getAccessToken(); $result = json_decode($credentials, true); $data['smtp_pass'] = $result['access_token']; DB::table('practiceinfo')->where('practice_id', '=', $practice_id)->update($data); return true; } else { return false; } }