Ejemplo n.º 1
0
 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');
 }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
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();
            // exchange request token for access token
            $oauthapp->token = $oauthapp->getAccessToken($request_token);
            // store access token for later
            $_SESSION['yahoo_oauth_access_token'] = $oauthapp->token->to_string();
            break;
        case 'cancel':
            unset($_SESSION['yahoo_oauth_access_token']);
            unset($_REQUEST['openid_mode']);
            header('Location: ' . $oauthapp->callback_url);
            exit;
            // openid cancelled
            break;
        case 'associate':
            // openid associate user
            break;
        default:
    }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
    $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;
    } else {
        if ($action == "post") {
            $token = new OAuthToken($_SESSION['ACCESS_TOKEN'], $_SESSION['ACCESS_TOKEN_SECRET']);
            $app->token = $token;
            /* Congratulations! You've just logged in into Yahoo! and now are able to 
             * post on meme :P' */
            $meme = new MemeRepository();
            $meme->insert($app, $_REQUEST['post_type'], $_REQUEST['content'], isset($_REQUEST['caption']) ? $_REQUEST['caption'] : null);
            print "<h1>CONGRATS! YOU DID IT</h1>";
        }
Ejemplo n.º 7
0
$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));
    } catch (Exception $e) {
        printf('<pre>%s</pre>', print_r($e, true));
        die;
    }
    // redirect back to index w/ success message
    header("Location: home.php?notice=upgrade_success");
} else {
    $request_token = $oauth_app->getRequestToken($oauth_callback_url);
    setcookie($local_user_id . '_yahoo_rt', json_encode($request_token), time() + 600);