public function signin() { $oauthapp = new \YahooOAuthApplication(Ntentan::$config['social.yahoo.consumer_key'], Ntentan::$config['social.yahoo.consumer_secret'], Ntentan::$config['social.yahoo.app_id'], Ntentan::$config['social.yahoo.redirect_uri']); if (!isset($_REQUEST['openid_mode'])) { Ntentan::redirect($oauthapp->getOpenIDUrl($oauthapp->callback_url), true); die; } if ($_REQUEST['openid_mode'] == 'id_res') { $requestToken = new \YahooOAuthRequestToken($_REQUEST['openid_oauth_request_token'], ''); $_SESSION['yahoo_oauth_request_token'] = $requestToken->to_string(); $oauthapp->token = $oauthapp->getAccessToken($requestToken); $_SESSION['yahoo_oauth_access_token'] = $oauthapp->token->to_string(); } $profile = $oauthapp->getProfile()->profile; if (is_object($profile)) { if (is_array($profile->emails)) { foreach ($profile->emails as $email) { if ($email->primary == 'true') { $email = $email->handle; break; } } } return array('firstname' => $profile->givenName, 'lastname' => $profile->familyName, 'key' => "yahoo_{$profile->guid}", 'avatar' => $profile->image->imageUrl, 'email' => $email, 'email_confirmed' => true); } die('Failed'); }
public function authencation() { $obj_token = new stdClass(); $request_token = $_SESSION['request_token']; if ($request_token) { foreach ($request_token as $key => $value) { $obj_token->{$key} = $value; } $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->appId, $this->domain); # Exchange request token for authorized access token $access_token = $oauthapp->getAccessToken($obj_token, $_REQUEST['oauth_verifier']); $profile = $oauthapp->getProfile(); return $profile; } }
public function onSloginCheck() { //получение значений из сессии $session = JFactory::getSession(); $request_token = unserialize($session->get('request_token')); $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->app_id, $this->callback); $input = JFactory::getApplication()->input; $oauth_verifier = $input->getString('oauth_verifier', ''); # Exchange request token for authorized access token $access_token = $oauthapp->getAccessToken($request_token, $oauth_verifier); # update access token $oauthapp->token = $access_token; # fetch user profile $profile = $oauthapp->getProfile(); if (empty($profile)) { die('Error: profile empty'); } //var_dump($profile); /* object(stdClass)#594 (1) { ["profile"]=> object(stdClass)#593 (10) { ["guid"]=> string(26) "YHDVXZ4H4LBJKT6NGXU5JQ537E" ["ageCategory"]=> string(1) "A" ["created"]=> string(20) "2014-11-24T05:48:59Z" ["image"]=> object(stdClass)#592 (4) { ["height"]=> string(3) "192" ["imageUrl"]=> string(56) "https://s.yimg.com/dh/ap/social/profile/profile_b192.png" ["size"]=> string(7) "192x192" ["width"]=> string(3) "192" } ["lang"]=> string(5) "en-US" ["memberSince"]=> string(20) "2014-09-30T12:10:41Z" ["nickname"]=> string(7) "Arkadiy" ["profileUrl"]=> string(51) "http://profile.yahoo.com/YHDVXZ4H4LBJKT6NGXU5JQ537E" ["isConnected"]=> string(5) "false" ["bdRestricted"]=> string(4) "true" } } */ $returnRequest = new SloginRequest(); $returnRequest->first_name = isset($profile->profile->givenName) ? $profile->profile->givenName : $profile->profile->nickname; $returnRequest->last_name = isset($profile->profile->familyName) ? $profile->profile->familyName : ''; $returnRequest->email = isset($profile->profile->emails->handle) ? $profile->profile->emails->handle : ''; $returnRequest->id = isset($profile->profile->guid) ? $profile->profile->guid : ''; $returnRequest->real_name = isset($profile->profile->givenName) ? $profile->profile->givenName : $profile->profile->nickname; $returnRequest->sex = isset($profile->profile->gender) ? $profile->profile->gender : ''; $returnRequest->display_name = $profile->profile->nickname; $returnRequest->all_request = $profile->profile; return $returnRequest; }
<?php require_once 'lib/OAuth/OAuth.php'; require_once 'lib/Yahoo/YahooOAuthApplication.class.php'; //define application key constants define("CONSUMER_KEY", "KEY HERE"); define("SHARED_SECRET", "KEY HERE"); define("APP_ID", "APPID HERE"); //create 3-legged OAuth request $oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID); //make request to YQL to get relationships for current user //will return guid, uri and categories for each $response = $oauthapp->getRelationships(); //for each relationship, obtain the profile and display foreach ($response->relationsWithCategories->relations->relation as $relation) { //get guid of the current relation & then profile using the guid $guid = $relation->guid; $profile = $oauthapp->getProfile($guid); echo "<h1>Profile: {$profile->profile->nickname}</h1>"; //for each profile, display all profile elements foreach ($profile->profile as $key => $value) { echo "{$key}: "; print_r($value); echo '<br />'; } }
* copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. **/ require_once dirname(__FILE__) . '/../common.inc.php'; $oauthapp = new YahooOAuthApplication(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID, OAUTH_DOMAIN); // handle openid/oauth if (isset($_REQUEST['openid_mode'])) { switch ($_REQUEST['openid_mode']) { case 'discover': case 'checkid_setup': case 'checkid_immediate': // handle yahoo simpleauth popup + redirect to yahoo! open id with open app oauth request header('Location: ' . $oauthapp->getOpenIDUrl(isset($_REQUEST['popup']) ? $oauthapp->callback_url . '?close=true' : $oauthapp->callback_url)); exit; break; case 'id_res': // validate claimed open id // extract approved request token from open id response $request_token = new YahooOAuthRequestToken($_REQUEST['openid_oauth_request_token'], ''); $_SESSION['yahoo_oauth_request_token'] = $request_token->to_string();
* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. **/ require_once dirname(__FILE__) . '/common.inc.php'; try { $oauthapp = YahooOAuthApplication::fromYAP(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); } catch (YahooOAuthApplicationException $e) { } ?> <style type="text/css"> div#ydoc { display: block; font-size: 100%; font-family: "Calibri", "Lucida Grande", "Tahoma", Arial; text-align: left; vertical-align: middle; color: #000; background-color: #fff; margin: 0; padding: 0;
$access_token = json_decode($results[0]['token_json']); } // if there's a stored token, check if it's expired, and refresh if it is if ($access_token && $access_token->expire_time < time()) { $oauth_app = new YahooOAuthApplication($oauth_consumer_key, $oauth_consumer_secret, $oauth_application_id); $access_token = $oauth_app->refreshAccessToken($access_token); $access_token->expire_time = time() + $access_token->expires_in; try { $results = $db->query("UPDATE `oauth_tokens` \n SET `token_json` = '%s' \n WHERE `service` = 'yahoo' \n AND `local_user_id` = '%s', \n LIMIT 1;", json_encode($access_token), $local_user_id); } catch (Exception $e) { printf('<pre>%s</pre>', print_r($e, true)); die; } } if ($access_token) { $oauth_app = new YahooOAuthApplication($oauth_consumer_key, $oauth_consumer_secret, null, null, $access_token); //yql is awesome http://developer.yahoo.com/yql/console/?q=select%20*%20from%20social.profile%20where%20guid%3Dme $response = $oauth_app->yql('select * from social.profile where guid=me'); $profile_data = $response->query->results->profile; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" href="stylesheet.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <?php
require_once "Auth/OpenID/SReg.php"; require_once "Auth/OpenID/PAPE.php"; require_once "Auth/OpenID/OAuth.php"; require_once 'OpenSocial/osapi.php'; require_once 'Yahoo/YahooOAuthApplication.class.php'; $error_flag = FALSE; function setSigninCookie($token) { setcookie('signin', $token, time() + 3600 * 24, '/', '.sharethis.com'); } function setSigninFailedCookie() { setcookie('signin', -1, time() + 3600 * 24, '/', '.sharethis.com'); } if (isset($_REQUEST['provider'])) { $oauthapp = new YahooOAuthApplication(YAHOO_OAUTH_CONSUMER_KEY, YAHOO_OAUTH_CONSUMER_SECRET, YAHOO_OAUTH_APP_ID, YAHOO_OAUTH_DOMAIN); if (!isset($_REQUEST['openid_mode'])) { $_REQUEST['openid_mode'] = 'discover'; } $yahoo_feed = ''; if (isset($_REQUEST["yahoo_feed"])) { $yahoo_feed = 1; } // handle openid/oauth if (isset($_REQUEST['openid_mode'])) { switch ($_REQUEST['openid_mode']) { case 'discover': case 'checkid_setup': case 'checkid_immediate': // handle yahoo simpleauth popup + redirect to yahoo! open id with open app oauth request header('Location: ' . $oauthapp->getOpenIDUrl($oauthapp->callback_url . '?provider=yahoo&close=true&yahoo_feed=' . $yahoo_feed));
public function onSloginCheck() { //получение значений из сессии $session = JFactory::getSession(); $request_token = unserialize($session->get('request_token')); $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->app_id, $this->callback); $input = JFactory::getApplication()->input; $oauth_verifier = $input->getString('oauth_verifier', ''); # Exchange request token for authorized access token $access_token = $oauthapp->getAccessToken($request_token, $oauth_verifier); # update access token $oauthapp->token = $access_token; # fetch user profile $profile = $oauthapp->getProfile(); //echo '<pre>'; var_dump($profile); /* object(stdClass)#328 (1) { ["profile"]=> object(stdClass)#327 (18) { ["guid"]=> string(26) "H6KKGGLX5Z4QQFUO6JQGESGWJU" ["aboutMe"]=> string(0) "" ["disclosures"]=> array(2) { [0]=> object(stdClass)#326 (4) { ["acceptance"]=> string(1) "1" ["name"]=> string(2) "bd" ["seen"]=> string(20) "2014-03-31T12:46:55Z" ["version"]=> string(1) "1" } [1]=> object(stdClass)#325 (4) { ["acceptance"]=> string(1) "1" ["name"]=> string(5) "ccard" ["seen"]=> string(20) "2014-03-31T12:46:55Z" ["version"]=> string(1) "1" } } ["emails"]=> object(stdClass)#324 (3) { ["handle"]=> string(28) "*****@*****.**" ["id"]=> string(1) "1" ["type"]=> string(4) "HOME" } ["familyName"]=> string(22) "Седельников" ["gender"]=> string(1) "M" ["givenName"]=> string(14) "Аркадий" ["image"]=> object(stdClass)#323 (4) { ["height"]=> string(3) "192" ["imageUrl"]=> string(80) "https://socialprofiles.zenfs.com/images/ccd1f5680c57f107485ab31ee8eabb08_192.png" ["size"]=> string(7) "192x192" ["width"]=> string(3) "192" } ["interests"]=> array(11) { [0]=> object(stdClass)#322 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(13) "prfFavHobbies" } [1]=> object(stdClass)#321 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(11) "prfFavMusic" } [2]=> object(stdClass)#320 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(12) "prfFavMovies" } [3]=> object(stdClass)#319 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(18) "prfFavFutureMovies" } [4]=> object(stdClass)#318 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(11) "prfFavBooks" } [5]=> object(stdClass)#317 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(17) "prfFavFutureBooks" } [6]=> object(stdClass)#316 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(12) "prfFavQuotes" } [7]=> object(stdClass)#315 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(11) "prfFavFoods" } [8]=> object(stdClass)#314 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(12) "prfFavPlaces" } [9]=> object(stdClass)#313 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(18) "prfFavFuturePlaces" } [10]=> object(stdClass)#312 (2) { ["declaredInterests"]=> string(0) "" ["interestCategory"]=> string(11) "prfFavAelse" } } ["lang"]=> string(5) "en-US" ["location"]=> string(0) "" ["memberSince"]=> string(20) "2014-03-31T08:19:34Z" ["nickname"]=> string(14) "Аркадий" ["phones"]=> object(stdClass)#311 (3) { ["id"]=> string(2) "10" ["number"]=> string(12) "7-9059450590" ["type"]=> string(6) "MOBILE" } ["profileUrl"]=> string(51) "http://profile.yahoo.com/H6KKGGLX5Z4QQFUO6JQGESGWJU" ["timeZone"]=> string(19) "America/Los_Angeles" ["isConnected"]=> string(4) "true" ["bdRestricted"]=> string(4) "true" } } */ if (empty($profile)) { die('Error: profile empty'); } $returnRequest = new SloginRequest(); $returnRequest->first_name = $profile->profile->givenName; $returnRequest->last_name = $profile->profile->familyName; $returnRequest->email = $profile->profile->emails->handle; $returnRequest->id = $profile->profile->guid; $returnRequest->real_name = $profile->profile->givenName . ' ' . $profile->profile->familyName; $returnRequest->sex = $profile->profile->gender; $returnRequest->display_name = $profile->profile->nickname; $returnRequest->all_request = $profile->profile; return $returnRequest; }
<?php // configure common.inc.php with your own app credentials require_once dirname(__FILE__) . "../../common.inc.php"; /* * TODO: Deal with token refreshing */ require_once dirname(__FILE__) . '/../../lib/Yahoo/YahooMeme.class.php'; $action = null; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; } // this URL will be called after user login. Don't forget to exchange the token!!! $callback = 'http://localhost/yos/examples/meme/oAuthExample.php?action=authorized'; $app = new YahooOAuthApplication(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID, OAUTH_DOMAIN); if (!$action || $action == 'request_token') { $request_token = $app->getRequestToken($callback); $_SESSION['request_token_key'] = $request_token->key; $_SESSION['request_token_secret'] = $request_token->secret; $redirect_url = $app->getAuthorizationUrl($request_token); // send user to Yahoo! so he can authorize our example to post on his Meme Header("Location: {$redirect_url}"); } else { if ($action == "authorized") { $request_token = new OAuthConsumer($_SESSION['request_token_key'], $_SESSION['request_token_secret']); $response = $app->getAccessToken($request_token, $_GET['oauth_verifier']); parse_str($response, $params); $access_token = $params['oauth_token']; $access_token_secret = $params['oauth_token_secret']; $_SESSION['ACCESS_TOKEN'] = $access_token; $_SESSION['ACCESS_TOKEN_SECRET'] = $access_token_secret;
<?php // ref http://github.com/yahoo/yos-social-php5 require '../yosdk/yahoo-yos-social-php5-86eef28/lib/OAuth/OAuth.php'; require '../yosdk/yahoo-yos-social-php5-86eef28/lib/Yahoo/YahooOAuthApplication.class.php'; //http://gist.github.com/387056 require 'MysqlUtil.php'; require 'config.php'; // use php5 sdk to simplify oauth dance $oauth_app = new YahooOAuthApplication($oauth_consumer_key, $oauth_consumer_secret, $oauth_application_id, $oauth_callback_uri); // safely fetch input $oauth_verifier = filter_var($_GET['oauth_verifier'], FILTER_SANITIZE_STRING); $local_user_id = filter_var($_COOKIE['local_user_id'], FILTER_SANITIZE_STRING); $request_token = filter_var($_COOKIE[$local_user_id . '_yahoo_rt'], FILTER_SANITIZE_STRING); // if user's not logged in, redirect back to index if (!$local_user_id) { header("Location: index.php?notice=session_required"); } // if verifier & stored token, we're in the redirect back from a successful auth if ($oauth_verifier && $request_token) { // fetch request token (decode html entities from filter), & delete it $request_token = json_decode(stripslashes(html_entity_decode($request_token))); setcookie($local_user_id . '_yahoo_rt', '', time() - 3600); // exchange request token for access token $access_token = $oauth_app->getAccessToken($request_token, $oauth_verifier); // calc time token will expire & add it to token obj $access_token->expire_time = time() + $access_token->expires_in; // a convenience obj for mysql. any persistent storage could be used here $db = new MysqlUtil($db_host, $db_name, $db_user, $db_pass); try { $results = $db->query("INSERT INTO `%s`.`oauth_tokens` (`local_user_id`, `service`, `token_json`) \n VALUES ( '%s', 'yahoo', '%s' );", $db_name, $local_user_id, json_encode($access_token));
$errors = FALSE; $response = array("status" => "FAILURE", "statusMessage" => "POST_YAHOO_UPDATE_SERVICE_FAILED"); $yahoo_token = isset($_REQUEST["yahoo_token"]) ? $_REQUEST["yahoo_token"] : FALSE; $title = isset($_REQUEST["title"]) ? $_REQUEST["title"] : ""; $description = isset($_REQUEST["description"]) ? $_REQUEST["description"] : ""; $link = isset($_REQUEST["link"]) ? $_REQUEST["link"] : ""; $return = isset($_REQUEST["return"]) ? strtolower($_REQUEST["return"]) : "json"; if (empty($yahoo_token)) { $errors = TRUE; $response["statusMessage"] = "MISSING_PARAMETER_YAHOO_TOKEN"; } if (!($return === "json" || $return === "xml" || $return === "php")) { $errors = TRUE; $response["statusMessage"] = "INVALID_RETURN_TYPE"; $return = "json"; } $oauthapp = new YahooOAuthApplication(YAHOO_OAUTH_CONSUMER_KEY, YAHOO_OAUTH_CONSUMER_SECRET, YAHOO_OAUTH_APP_ID, YAHOO_OAUTH_DOMAIN); // restore access token from session $oauthapp->token = YahooOAuthAccessToken::from_string($yahoo_token); $suid = md5($title . $description . $link . time()); $retval = $oauthapp->insertUpdate(null, $description, $title, $link); if ($retval) { $response["data"] = $retval; $response["status"] = "SUCCESS"; $response["statusMessage"] = "SUCCESS"; } // Generate properly encoded return data if ('xml' === $return) { header("Content-Type: text/xml"); } echo formatOutputArray($response, $return);