public static function getTokenCredentials() { $result = array(); try { $access_token_url = \Fuel\Core\Config::get('evernote.evernote_server') . '/oauth'; $oauth_verifier = \Fuel\Core\Session::get('oauthVerifier'); $oauth = new \OAuth(\Fuel\Core\Config::get('evernote.consumer_key'), \Fuel\Core\Config::get('evernote.consumer_secret')); $request_token = \Fuel\Core\Session::get('requestToken'); $request_token_secret = \Fuel\Core\Session::get('requestTokenSecret'); $oauth->setToken($request_token, $request_token_secret); $access_token_info = $oauth->getAccessToken($access_token_url, null, $oauth_verifier); if ($access_token_info) { $result['status'] = 'success'; $result['access_token'] = $access_token_info['oauth_token']; $result['access_token_secret'] = $access_token_info['oauth_token_secret']; $result['shard_id'] = $access_token_info['edam_shard']; $result['user_id'] = $access_token_info['edam_userId']; } else { $result['status'] = 'failure'; } } catch (\OAuthException $e) { $result['status'] = 'failure'; } return $result; }
/** * Call Twitter API methods * * @param string $method * @param array $accessToken * @param OAuth $oauth * @param array $params (include oauth_method = POST/GET if need to override) * @return string */ public static function call($method, $accessToken = null, OAuth $oauth, $params = array()) { $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']); $resource = sprintf('%s/%s.json', 'https://api.twitter.com/1.1', $method); // POST or GET $method = OAUTH_HTTP_METHOD_GET; if (isset($params['oauth_method'])) { if ('POST' == strtoupper($params['oauth_method'])) { $method = OAUTH_HTTP_METHOD_POST; } } else { // If resource contains update, retweet (not retweets), filter, destroy, new, create - then POST not GET foreach (array('update', 'retweet/', 'filter', 'destroy', 'new', 'create') as $resourcePart) { if (false !== strpos($resource, $resourcePart)) { $method = OAUTH_HTTP_METHOD_POST; break; } } } if ($method == OAUTH_HTTP_METHOD_GET) { if (count($params)) { $resource = sprintf('%s?%s', $resource, http_build_query($params)); } $params = null; } // Get back bad response if don't specify method where needs to be POST if ($oauth->fetch($resource, $params, $method)) { return $oauth->getLastResponse(); } else { return null; } }
function twitter_post($text, $short_url) { global $globals; if (!class_exists("OAuth")) { syslog(LOG_NOTICE, "Meneame: pecl/oauth is not installed"); return; } if (!$globals['twitter_consumer_key'] || !$globals['twitter_consumer_secret'] || !$globals['twitter_token'] || !$globals['twitter_token_secret']) { syslog(LOG_NOTICE, "Meneame: consumer_key, consumer_secret, token, or token_secret not defined"); return; } $maxlen = 140 - 24; //strlen($short_url); $msg = mb_substr(text_to_summary(html_entity_decode($text), $maxlen), 0, $maxlen) . ' ' . $short_url; $req_url = 'https://api.twitter.com/oauth/request_token'; $acc_url = 'https://api.twitter.com/oauth/access_token'; $authurl = 'https://api.twitter.com/oauth/authorize'; $api_url = 'https://api.twitter.com/1.1/statuses/update.json'; $oauth = new OAuth($globals['twitter_consumer_key'], $globals['twitter_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->debug = 1; $oauth->setToken($globals['twitter_token'], $globals['twitter_token_secret']); $api_args = array("status" => $msg, "empty_param" => NULL); /* No using geo yet if (isset($entry['lat'])) { $api_args['lat'] = $entry['lat']; $api_args['long'] = $entry['long']; } */ try { $oauth->fetch($api_url, $api_args, OAUTH_HTTP_METHOD_POST, array("User-Agent" => "pecl/oauth")); } catch (Exception $e) { syslog(LOG_INFO, 'Menéame, Twitter caught exception: ' . $e->getMessage() . " in " . basename(__FILE__) . "\n"); } }
/** * Retrive Twitter auth data in Cookie set by Twitter JSSDK. * * @param CakeRequest $request Request object. * @return mixed Either false or an object of user information of Twitter */ public function getUser(CakeRequest $request) { $api = Configure::read('SocialSignIn.API.Twitter'); // $request_token_url = 'http://api.twitter.com/oauth/request_token'; // $access_token_url = "http://twitter.com/oauth/access_token"; // $authorize_url="http://twitter.com/oauth/authorize"; $session_name = $this->settings['session']; $s = SessionComponent::read($session_name); // if already authenticated, user object is stored in the session if (isset($s['User']) && is_object($s['User'])) { return $s['User']; } if (isset($request->query['oauth_token']) && isset($s['secret'])) { $oauth = new OAuth($this->settings['consumer_key'], $this->settings['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->setToken($request->query['oauth_token'], $s['secret']); $access_token_info = $oauth->getAccessToken($api['access_token_url']); if ($access_token_info['oauth_token']) { $oauth->setToken($access_token_info['oauth_token'], $access_token_info['oauth_token_secret']); $data = $oauth->fetch($api['fetch_url']); $user = json_decode($oauth->getLastResponse()); return $user; } } return false; }
protected function getUserDetailsAndLoginUser() { $this->oauth->setToken($this->getSession('oauth')->token, $this->getSession('oauth')->secret); //fetch user datail XML $this->oauth->fetch(self::API_URL . "user/details"); $user_details = $this->oauth->getLastResponse(); $xml = simplexml_load_string($user_details); $user = array('id' => $xml->user['id'], 'username' => $xml->user['display_name'], 'account_created' => $xml->user['account_created'], 'img' => $xml->user->img['href'], 'changesets' => $xml->user->changesets['count'], 'traces' => $xml->user->traces['count'], 'description' => $xml->user->description, 'home_lat' => $xml->user->home['lat'], 'home_lon' => $xml->user->home['lon'], 'last_login' => date("Y-m-d H:i:s")); // convert xml-nodes to strings foreach ($user as &$val) { $val = strval($val); } // update db $row = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']); if ($row) { //better dont change usernames, we use it as primary key unset($user['username']); dibi::query('UPDATE users SET ', $user, ' WHERE id = %i', $user['id']); } else { $user['first_login'] = new DateTime(); dibi::query('INSERT INTO users ', $user); } // load complete row from db $dbuser = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']); if ($dbuser['webpages'] != 'admin' and $dbuser['webpages'] != 'all') { $dbuser['webpages'] = '14' . ($dbuser['webpages'] ? ',' : '') . $dbuser['webpages']; } $this->user->login(new Identity($dbuser['username'], array($dbuser['webpages'] == 'admin' ? 'admin' : 'user'), $dbuser)); // remove all tokens - TODO if tokens to be used, save them in DB $this->redirectUrl('//' . $_SERVER['HTTP_HOST'] . $this->getSession('oauth')->back_url); }
function getTwitterFriendIds($user) { $cacheExpire = 24 * 60 * 60; $POD = $user->POD; $key = $POD->libOptions('twitter_api'); $secret = $POD->libOptions('twitter_secret'); $friends = array(); if ($user->get('twitter_token')) { if ($user->get('twitter_list') != '' && time() - $user->get('twitter_list_generated') < $cacheExpire) { $twoots = json_decode($user->get('twitter_list')); foreach ($twoots as $f) { $friends[] = $f; } } else { try { $oauth = new OAuth($key, $secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->enableDebug(); // This will generate debug output in your error_log $oauth->setToken($user->get('twitter_token'), $user->get('twitter_secret')); $oauth->fetch('https://twitter.com/friends/ids.json?cursor=-1&user_id=' . $user->get('twitter_id')); $json = json_decode($oauth->getLastResponse()); } catch (Exception $e) { } // contains the first 5000 twitter friends foreach ($json->ids as $id) { $friends[] = $id; } $user->addMeta('twitter_list', json_encode($friends)); $user->addMeta('twitter_list_generated', time()); } } return $friends; }
public static function authorize($consumer_key, $consumer_secret, $request_token, $request_secret) { $oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM); $oauth->setToken($request_token, $request_secret); $access_token_info = $oauth->getAccessToken(GOOGLE_OAUTH_ACCESS_TOKEN_API); return array("access_token" => $access_token_info["oauth_token"], "access_secret" => $access_token_info["oauth_token_secret"]); }
/** * @return Response */ protected function getResponse() { $responseInfo = $this->oAuthClient->getLastResponseInfo(); $response = Response::createFromRaw($responseInfo['headers_recv']); $response->appendContent($this->oAuthClient->getLastResponse()); return $response; }
public function testHttpBuildQuery() { $input = array('Name' => 'Gareth Wylie', 'Age' => 24, 'Formula' => 'a + b == 13%!'); $expect = 'Name=Gareth%20Wylie&Age=24&Formula=a%20%2B%20b%20%3D%3D%2013%25%21'; $oauth = new OAuth('foo', 'bar'); self::assertEquals($expect, $oauth->http_build_query($input)); }
function authorize() { $oauth = new OAuth(Config::get('TWITTER_CONSUMER_KEY'), Config::get('TWITTER_CONSUMER_SECRET'), OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->enableDebug(); try { $request_token = $oauth->getRequestToken($this->request_token_url); } catch (OAuthException $e) { debug($oauth->debugInfo); } $url = $this->authorize_url . '?' . http_build_query(array('oauth_token' => $request_token['oauth_token'], 'callback_url')); print 'Authorize: ' . $url . "\n"; system(sprintf('open %s', escapeshellarg($url))); fwrite(STDOUT, "Enter the PIN: "); $verifier = trim(fgets(STDIN)); //$oauth->setToken($token, $request_token['oauth_token_secret']); //$access_token = $oauth->getAccessToken($this->access_token_url); $oauth->setToken($request_token['oauth_token'], $request_token['oauth_token_secret']); try { $access_token = $oauth->getAccessToken($this->access_token_url, NULL, $verifier); } catch (OAuthException $e) { debug($oauth->debugInfo); } printf("'TWITTER_TOKEN' => '%s',\n'TWITTER_TOKEN_SECRET' => '%s',\n", $access_token['oauth_token'], $access_token['oauth_token_secret']); exit; }
/** * @return Response */ protected function getResponse() { $responseHeaders = $this->oAuthClient->getLastResponseHeaders(); $response = Response::createFromRaw($responseHeaders); $response->appendContent($this->oAuthClient->getLastResponse()); return $response; }
function do_recharge_request($param) { $random_number = rand(5, 10); $transaction_id = "abc" . $random_number; // string. Number not allowed //$db->insert("recharge_test_table",array("trans_id" => $transaction_id,"time"=>time())); $oauth_consumer_key = $client_id = $consumer_key = "spacepoint_nigeria_demo_user1"; $oauth_consumer_secret = $client_secret = $consumer_secret = "wltJSD3ztLKfBQmIW32iSGfcrwe3okS0"; $username = "******"; // $msisdn = "2348059827239"; // mobile number +234-8059827239 // $msisdn = "2340123456789"; $msisdn = "234" . $param['mobile_no']; // $face_value = 5000; $face_value = (int) $param['amount']; //$face_value *= 100; $supplier_api = "ttdemo_v1"; $product_info = array("product" => "airtime"); // echo $face_value; // echo " "; // echo $msisdn;exit; try { $params = array("username" => $username, "msisdn" => $msisdn, "transaction_id" => $transaction_id, "face_value" => $face_value, "supplier_api" => $supplier_api, "product_info" => $product_info); $request = new OAuth($oauth_consumer_key, $oauth_consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); //print_r($request); $request->disableSSLChecks(); $request->fetch("https://hsc16.miranetworks.net:16000/v1/recharge", json_encode($params), OAUTH_HTTP_METHOD_POST, array("Content-Type" => "application/json")); return $response = $request->getLastResponse(); //echo $response; // echo "<pre>"; // print_r($response); // return $response; } catch (Exception $e) { return 'Message: ' . $e->getMessage(); } }
public function getAccessToken($oauthToken, $oauthTokenSecret, $oauthVerifier) { $oauth = new \OAuth($this->consumerKey, $this->consumerSecret); $oauth->setToken($oauthToken, $oauthTokenSecret); $accessToken = $oauth->getAccessToken($this->getEndpoint('oauth'), null, $oauthVerifier); $this->token = $accessToken['oauth_token']; return $accessToken; }
function getUserInfo($token, $secret) { $oauth = new OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->setToken($token, $secret); $oauth->fetch('http://twitter.com/account/verify_credentials.json'); $buf = $oauth->getLastResponse(); return json_decode($buf, true); }
function ilost_get_fanauthorize() { $o = new OAuth(fan_akey, fan_skey); $keys = $o->getRequestToken(); $aurl = $o->getAuthorizeURL($keys['oauth_token'], false, fan_callback); $_SESSION['temp'] = $keys; return $aurl; }
public function __construct($consumer_key, $consumer_secret, $signature_method = OAUTH_SIG_METHOD_HMACSHA1, $auth_type = 0) { if (!class_exists('OAuth')) { return ar_error::raiseError('OAuth PECL extension not installed', ar_exceptions::CONFIGURATION_ERROR); } $oauth = new OAuth($consumer_key, $consumer_secret, $signature_method, $auth_type); $oauth->setRequestEngine(OAUTH_REQENGINE_STREAMS); parent::__construct($oauth); }
public function testError() { $oauth = new OAuth('wx229aa24fa4a2xxxx', 'error_secret'); $oauth->getAccessToken('code', 'error_authorization_code'); $this->assertStringStartsWith('get access token failed: system error', $oauth->error()); $oauth = new OAuth('wx229aa24fa4a2xxxx', 'error_secret', 'error_access_token'); $oauth->api('sns/userinfo', array('openid' => 'error_openid')); $this->assertStringStartsWith('request failed: invalid credential, access_token is invalid or not latest', $oauth->error()); }
/** * Calls Netflix API methods * * @static * @param $method * @param null $accessToken * @param OAuth $oauth * @param array $params * @return string */ public static function call($method, $accessToken = null, OAuth $oauth, $params = array()) { $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']); $resource = sprintf('%s/%s?output=json', 'http://api.netflix.com', $method); if (count($params)) { $resource = sprintf('%s&%s', $resource, http_build_query($params)); } if ($oauth->fetch($resource)) { return $oauth->getLastResponse(); } }
/** * Send a POST request to the specified URL with the specified payload. * @param string $url * @param string $data * @return string Remote data **/ public function sendPOST($url, $data = array()) { $data['_fake_status'] = '200'; // Send the actual request. try { $this->instance->fetch($url, $data, OAUTH_HTTP_METHOD_POST, array('User-Agent' => sprintf(Imgur::$user_agent, Imgur::$key))); } catch (OAuthException $e) { throw new Imgur_Exception("Could not successfully do a sendPOST: " . $e->getMessage(), null, $e); } return $this->instance->getLastResponse(); }
private function _getOAuth() { $oauth = new OAuth($this->key, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM); if (isset($_SESSION['access_key']) && isset($_SESSION['access_secret'])) { $oauth->setToken($_SESSION['access_key'], $_SESSION['access_secret']); } else { if (isset($_SESSION['request_key']) && isset($_SESSION['request_secret'])) { $oauth->setToken($_SESSION['request_key'], $_SESSION['request_secret']); } } return $oauth; }
/** * Calls Vimeo methods: * @see http://vimeo.com/api/docs/methods * * @param String $method = Vimeo method to be called * @param Array $accessToken * @param OAuth $oauth * @param Array $params - additional parameters required for Vimeo method * @return String Json string */ public static function call($method, $accessToken = null, OAuth $oauth, $params = array()) { if ($accessToken) { $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']); } $resource = sprintf('%s?method=%s&format=json', 'http://vimeo.com/api/rest/v2/', $method); if (count($params)) { $resource = sprintf('%s&%s', $resource, http_build_query($params)); } if ($oauth->fetch($resource)) { return $oauth->getLastResponse(); } }
function call($command) { session_start(); if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) { $_SESSION['state'] = 0; } try { $oauth = new \OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->enableDebug(); if (!isset($_GET['oauth_token']) && !$_SESSION['state']) { $request_token_info = $oauth->getRequestToken($this->request_url); $_SESSION['secret'] = $request_token_info['oauth_token_secret']; $_SESSION['state'] = 1; header('Location: ' . $this->authorize_url . '?oauth_token=' . $request_token_info['oauth_token']); exit; } else { if ($_SESSION['state'] == 1) { $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']); $access_token_info = $oauth->getAccessToken($this->access_token_url); error_log("acc token info " . $access_token_info, 1, "*****@*****.**"); $_SESSION['state'] = 2; $_SESSION['token'] = $access_token_info['oauth_token']; $_SESSION['secret'] = $access_token_info['oauth_token_secret']; } } $oauth->setToken($_SESSION['token'], $_SESSION['secret']); $oauth->fetch("{$this->api_url}{$command}"); $json = json_decode($oauth->getLastResponse()); } catch (\OAuthException $E) { return $E->lastResponse; } return $json; }
function twitter_post($auth, $text, $short_url, $image = false) { global $globals; if (empty($auth['twitter_token']) || empty($auth['twitter_token_secret']) || empty($auth['twitter_consumer_key']) || empty($auth['twitter_consumer_secret'])) { return false; } if (!class_exists("OAuth")) { syslog(LOG_NOTICE, "Meneame: pecl/oauth is not installed"); return; } if (!$auth['twitter_consumer_key'] || !$auth['twitter_consumer_secret'] || !$auth['twitter_token'] || !$auth['twitter_token_secret']) { syslog(LOG_NOTICE, "Meneame: consumer_key, consumer_secret, token, or token_secret not defined"); return; } $req_url = 'https://api.twitter.com/oauth/request_token'; $acc_url = 'https://api.twitter.com/oauth/access_token'; $authurl = 'https://api.twitter.com/oauth/authorize'; $api_url = 'https://api.twitter.com/1.1/statuses/update.json'; $api_media_url = 'https://api.twitter.com/1.1/statuses/update_with_media.json'; $api_args = array("empty_param" => NULL); $maxlen = 140 - 24; // minus the url length if ($image) { $maxlen -= 24; echo "Adding image: {$image}\n"; $api_args['@media[]'] = '@' . $image; $url = $api_media_url; } else { $url = $api_url; } $msg = mb_substr(text_to_summary(html_entity_decode($text), $maxlen), 0, $maxlen); $msg_full = $msg . ' ' . $short_url; $api_args["status"] = $msg_full; $oauth = new OAuth($auth['twitter_consumer_key'], $auth['twitter_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->debug = 1; $oauth->setRequestEngine(OAUTH_REQENGINE_CURL); // For posting images $oauth->setToken($auth['twitter_token'], $auth['twitter_token_secret']); try { $oauth->fetch($url, $api_args, OAUTH_HTTP_METHOD_POST, array("User-Agent" => "pecl/oauth")); } catch (Exception $e) { syslog(LOG_INFO, 'Menéame, Twitter caught exception: ' . $e->getMessage() . " in " . basename(__FILE__) . "\n"); echo "Twitter post failed: {$msg} " . mb_strlen($msg) . "\n"; return false; } // $response_info = $oauth->getLastResponseInfo(); // echo $oauth->getLastResponse() . "\n"; return true; }
public function run() { $model = new OAuth(); //条件 $criteria = new CDbCriteria(); $apiname = trim(Yii::app()->request->getParam('apiname')); $apiname && $criteria->addSearchCondition('apiname', $apiname); $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); $result = $model->findAll($criteria); $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages)); }
public function loginWithFacebook() { // get data from input $code = Input::get('code'); // get fb service $fb = OAuth::consumer('Facebook'); // check if code is valid // if code is provided get user data and sign in if (!empty($code)) { // This was a callback request from facebook, get the token $token = $fb->requestAccessToken($code); // Send a request with it $result = json_decode($fb->request('/me'), true); $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name']; echo $message . "<br/>"; //Var_dump //display whole array(). dd($result); } else { // get fb authorization $url = $fb->getAuthorizationUri(); // return to facebook login url return Redirect::to((string) $url); } }
function Tencent() { require_once APP_ROOT_PATH . 'system/api_login/Tencent/Tencent.php'; OAuth::init($GLOBALS['m_config']['tencent_app_key'], $GLOBALS['m_config']['tencent_app_secret']); $openid = trim($GLOBALS['request']['openid']); $openkey = trim($GLOBALS['request']['openkey']); if ($GLOBALS['m_config']['tencent_bind_url'] == "") { $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Tencent"; } else { $app_url = $GLOBALS['m_config']['tencent_bind_url']; } $access_token = trim($GLOBALS['request']['access_token']); es_session::set("t_access_token", $access_token); es_session::set("t_openid", $openid); es_session::set("t_openkey", $openkey); if (es_session::get("t_access_token") || es_session::get("t_openid") && es_session::get("t_openkey")) { $r = Tencent::api('user/info'); $r = json_decode($r, true); $name = $r['data']['name']; if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "user where tencent_id = '" . $name . "'") == 0) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set t_access_token ='" . $access_token . "',t_openkey = '" . $openkey . "',t_openid = '" . $openid . "', tencent_id = '" . $name . "' where id =" . intval($GLOBALS['user_info']['id'])); } elseif (intval($GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user where tencent_id = '" . $name . "'")) == intval($GLOBALS['user_info']['id'])) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set t_access_token ='" . $access_token . "',t_openkey = '" . $openkey . "',t_openid = '" . $openid . "', tencent_id = '" . $name . "' where id =" . intval($GLOBALS['user_info']['id'])); } else { $root['return'] = 0; $root['info'] = "该微博帐号已被其他会员绑定"; output($root); } } $root['return'] = 1; $root['info'] = "绑定成功"; $root['login_type'] = "Tencent"; output($root); }
public function RegisterWithGoogle() { $code = Input::get('code'); $googleService = OAuth::consumer('Google'); if (!empty($code)) { $token = $googleService->requestAccessToken($code); $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); $user = User::firstOrCreate(array('email' => $result['email'])); if ($user != null) { $user->nombre = $result['name']; $user->avatar = $result['picture']; $user->save(); Auth::login($user, false); Session::flash('message', "<img src='" . $user->avatar . "' height='70' alt=''> Registrado con Facebook <br> Bienvenido " . $result['name']); if (Auth::user()->residencia_id == null) { return Redirect::to("register/completar-registro"); } else { return Redirect::to("/"); } } else { Session::flash('message', "Error al Crear usuario"); return Redirect::to("/"); } } else { $url = $googleService->getAuthorizationUri(); return Redirect::to((string) $url); } }
public function shouquan($code, $openid, $openkey, $redirect_uri) { OAuth::init($this->client_id, $this->client_secret); Tencent::$debug = $this->debug; $callback = $redirect_uri; //回调url if ($code) { //已获得code //获取授权token $url = OAuth::getAccessToken($code, $callback); $r = Http::request($url); parse_str($r, $out); //存储授权数据 if (@$out['access_token']) { $_SESSION['t_access_token'] = $out['access_token']; $_SESSION['t_refresh_token'] = $out['refresh_token']; $_SESSION['t_expire_in'] = $out['expires_in']; $_SESSION['t_code'] = $code; $_SESSION['t_openid'] = $openid; $_SESSION['t_openkey'] = $openkey; //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { //echo('<h3>授权成功!!!</h3><br>'); //print_r($r);exit; //header('Location: ' . $callback);//刷新页面 return $r; } else { exit('<h3>授权失败,请重试</h3>'); } } else { exit($r); } } }
public function linkedin() { $oauth = new OAuth("772ot2tfqntox5", "Y6kUKUlWcWc6yDkd"); $oauth->setToken("94616be2-c292-472d-9f45-dfad9b78f2ef", "cdf34568-ed5f-4a27-a15d-4c8bf276fb4d"); $params = array(); $headers = array(); $method = OAUTH_HTTP_METHOD_GET; $url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,picture-url,location:(name))?format=json"; $oauth->fetch($url, $params, $method, $headers); $result = json_decode($oauth->getLastResponse(), true); $this->info['nombre'] = $result['firstName']; $this->info['apellido'] = $result['lastName']; $this->info['foto'] = $result['pictureUrl']; $this->info['ubicacion'] = $result['location']['name']; $this->info['industria'] = $result['industry']; }
public function getAuthorizationUrl() { $requestToken = $this->oauth->getRequestToken(self::URL_REQUEST); Session::set('Twitter_TokenSecret', $requestToken['oauth_token_secret']); # Session::set('Twitter_State', self::STATE_AUTH); return self::URL_AUTHORIZE . '?oauth_token=' . $requestToken['oauth_token']; }