Ejemplo n.º 1
0
 private function reflashToken()
 {
     if (empty($this->m_cfg['username']) || empty($this->m_cfg['password'])) {
         return;
     }
     $this->m_reflash_cookie = tmpDir('reflashsina.cookie');
     if (!file_exists($this->m_reflash_cookie)) {
         touch($this->m_reflash_cookie);
     }
     $loginResult = $this->curlLoginSina($this->m_cfg['username'], $this->m_cfg['password']);
     if (!$loginResult) {
         return $loginResult;
     }
     $callbackUrl = callbackUrl('sina');
     $o = new SaeTOAuthV2($this->m_cfg['key'], $this->m_cfg['secret']);
     $authorizeURL = $o->getAuthorizeURL($callbackUrl);
     $ch = curl_init($authorizeURL);
     $option = array();
     $option[CURLOPT_FOLLOWLOCATION] = 1;
     $option[CURLOPT_RETURNTRANSFER] = 1;
     $option[CURLOPT_COOKIEJAR] = $this->m_reflash_cookie;
     $option[CURLOPT_COOKIEFILE] = $this->m_reflash_cookie;
     $option[CURLOPT_HTTPHEADER] = array('Accept-Language: zh-cn', 'Connection: Keep-Alive', 'Cache-Control: no-cache');
     $option[CURLOPT_USERAGENT] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
     curl_setopt_array($ch, $option);
     curl_exec($ch);
     curl_close($ch);
     unlink($this->m_reflash_cookie);
 }
Ejemplo n.º 2
0
 * @copyright 2012 http://cdbit.com All rights reserved
 * 
 * *********************************************************
 */
if (islocked('sina')) {
    $takedToken = Encryption::unserializeFromFile(tmpDir('sina.oauth'));
    if (!($takedToken['auth_timestamp'] + $takedToken['expires_in'] < time() - 10)) {
        display(_er('E_LOCKED', 'sina', 'sina'), 0);
    }
}
import('/library/saetv2.ex.class.php');
global $cfg_sina;
$o = new SaeTOAuthV2($cfg_sina['key'], $cfg_sina['secret']);
if (!isset($_REQUEST['code'])) {
    display('sina认证失败');
}
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = callbackUrl('sina');
$token = false;
try {
    $token = $o->getAccessToken('code', $keys);
} catch (OAuthException $e) {
    display('sina认证失败:' . $e->getMessage());
}
if ($token) {
    $token['auth_timestamp'] = time();
    Encryption::serializeToFile($token, tmpDir('sina.oauth'));
    lockit('sina');
    display('sina认证成功');
}
$app['debug'] = true;
$app->get('/load', function (Request $request) use($app) {
    $data = verifySignedRequest($request->get('signed_payload'));
    if (empty($data)) {
        return 'Invalid signed_payload.';
    }
    $redis = new Credis_Client('localhost');
    $key = getUserKey($data['store_hash'], $data['user']['email']);
    $user = json_decode($redis->get($key), true);
    if (empty($user)) {
        return 'Invalid user.';
    }
    return 'Welcome ' . json_encode($user);
});
$app->get('/auth/callback', function (Request $request) use($app) {
    $payload = array('client_id' => clientId(), 'client_secret' => clientSecret(), 'redirect_uri' => callbackUrl(), 'grant_type' => 'authorization_code', 'code' => $request->get('code'), 'scope' => $request->get('scope'), 'context' => $request->get('context'));
    $client = new Client(bcAuthService());
    $req = $client->post('/oauth2/token', array(), $payload, array('exceptions' => false));
    $resp = $req->send();
    if ($resp->getStatusCode() == 200) {
        $data = $resp->json();
        list($context, $storeHash) = explode('/', $data['context'], 2);
        $key = getUserKey($storeHash, $data['user']['email']);
        $redis = new Credis_Client('localhost');
        $redis->set($key, json_encode($data['user'], true));
        return 'Hello ' . json_encode($data);
    } else {
        return 'Something went wrong... [' . $resp->getStatusCode() . '] ' . $resp->getBody();
    }
});
function verifySignedRequest($signedRequest)
Ejemplo n.º 4
0
/**
 * *********************************************************
 * 
 * @author cluries
 * @link http://cdbit.com
 * @version 1.0
 * @copyright 2012 http://cdbit.com All rights reserved
 * 
 * *********************************************************
 */
if (islocked('renren')) {
    display(_er('E_LOCKED', 'renren', 'renren'), 0);
}
if (empty($_REQUEST['code'])) {
    display(_er('E_404'), 0);
}
global $cfg_renren;
import('/library/renrenoauth.php');
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = callbackUrl('renren');
try {
    $o = new RenrenOAuth($cfg_renren['key'], $cfg_renren['secret']);
    $token = $o->getAccessToken($_REQUEST['code'], callbackUrl('renren'));
    Encryption::serializeToFile($token, tmpDir('renren.oauth'));
    lockit('renren');
    display('renren认证成功');
} catch (OAuthException $e) {
    display('renren认证失败', 0);
}
Ejemplo n.º 5
0
function doubanJMP__()
{
    import('/library/OAuth.php');
    import('/library/doubanoauth.php');
    $type = 'douban';
    global $cfg_douban;
    $o = new DoubanOAuth($cfg_douban['key'], $cfg_douban['secret']);
    $token = $o->getRequestToken();
    $_SESSION['douban_token'] = $token['oauth_token'];
    $_SESSION['douban_token_secret'] = $token['oauth_token_secret'];
    $authorizeURL = $o->getAuthorizeURL($token, callbackUrl($type));
    header("Location:{$authorizeURL}");
}