예제 #1
0
파일: yahoo.php 프로젝트: utopszkij/keszlet
 public function onSloginAuth()
 {
     $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->app_id, $this->callback);
     # Fetch request token
     $request_token = $oauthapp->getRequestToken($this->callback);
     $session = JFactory::getSession();
     $session->set('request_token', serialize($request_token));
     # Redirect user to authorization url
     $redirect_url = $oauthapp->getAuthorizationUrl($request_token);
     return $redirect_url;
 }
예제 #2
0
 /**
  * connect
  */
 public function connect()
 {
     $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->appId, $this->domain);
     # Fetch request token
     $request_token = $oauthapp->getRequestToken($this->redirect_url);
     $_SESSION['request_token'] = get_object_vars($request_token);
     # Redirect user to authorization url
     $redirect_url = $oauthapp->getAuthorizationUrl($request_token);
     header('Location: ' . $redirect_url);
     exit;
 }
예제 #3
0
파일: yahoo.php 프로젝트: janich/slogin
 public function onSloginAuth()
 {
     if ($this->params->get('allow_remote_check', 1)) {
         $remotelUrl = JURI::getInstance($_SERVER['HTTP_REFERER'])->toString(array('host'));
         $localUrl = JURI::getInstance()->toString(array('host'));
         if ($remotelUrl != $localUrl) {
             die('Remote authorization not allowed');
         }
     }
     $oauthapp = new YahooOAuthApplication($this->key, $this->secret, $this->app_id, $this->callback);
     # Fetch request token
     $request_token = $oauthapp->getRequestToken($this->callback);
     $session = JFactory::getSession();
     $session->set('request_token', serialize($request_token));
     # Redirect user to authorization url
     $redirect_url = $oauthapp->getAuthorizationUrl($request_token);
     return $redirect_url;
 }
예제 #4
0
// 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;
    } else {
예제 #5
0
$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);
    $redirect_url = $oauth_app->getAuthorizationUrl($request_token);
    header("Location: {$redirect_url}");
}