Skip to content
Browse files

add Murmur Pixnet Plurk and updates some others providers

  • Loading branch information...
1 parent fc7b517 commit e7c38cbd4ead409aecd6c1fbcda66c8e23300260 hybridauth committed
View
2 README.md
@@ -1,4 +1,4 @@
-# HybridAuth 2.0.9
+# HybridAuth 2.0.10-dev
HybridAuth enable developers to easily build social applications and tools
to engage websites vistors and customers on a social level by implementing
View
271 additional-providers/hybridauth-qq/Providers/QQ.php
@@ -1,156 +1,197 @@
<?php
-/**
+/*!
* HybridAuth
-*
-* A Social-Sign-On PHP Library for authentication through identity providers like Facebook,
-* Twitter, Google, Yahoo, LinkedIn, MySpace, Windows Live, Tumblr, Friendster, OpenID, PayPal,
-* Vimeo, Foursquare, AOL, Gowalla, and others.
-*
-* Copyright (c) 2009-2011 (http://hybridauth.sourceforge.net)
+* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
+* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
*/
/**
- * QQ Weibo OAuth
+ * QQ OAuth Class
*
- * @ID: QQ
- * @Protocol: OAuth
- * @IDp URL: http://t.qq.com
- * @Keys registeration: http://open.t.qq.com/development/
- * @Dev documentation: http://open.t.qq.com/resource.php?i=1,1
- * @Description:
- * @Author: RB Lin <xtheme=at=gmail-dot-com>
- * @Based on: Project Sirius http://code.google.com/p/sirius/
- * @Version: 1.0
- * @Since: HybridAuth 2.0.6
- * @Wrapper: ./Hybrid/Providers/QQ.php
- * @Required Libs: ./Hybrid/thirdparty/QQ/
- * @URL Start login*: http://mywebsite.com/path_to_hybridauth/?hauth.start=QQ
- * @URL Login done*: http://mywebsite.com/path_to_hybridauth/?hauth.done=QQ
+ * @package HybridAuth additional providers package
+ * @author RB Lin <xtheme@gmail.com>
+ * @version 1.2
+ * @license BSD License
*/
-
+
/**
- * Hybrid_Providers_QQ class, wrapper for QQ
+ * QQ provider adapter based on OAuth1 protocol
+ *
+ * http://hybridauth.sourceforge.net/userguide/IDProvider_info_QQ.html
*/
-class Hybrid_Providers_QQ extends Hybrid_Provider_Model
-{
- /**
- * IDp wrappers initializer
- */
+class Hybrid_Providers_QQ extends Hybrid_Provider_Model_OAuth1
+{
function initialize()
{
+ // Use Beijing Timezone
date_default_timezone_set ('Etc/GMT-8');
- if ( ! $this->config["keys"]["key"] || ! $this->config["keys"]["secret"] )
- {
- throw new Exception( "Your application key and secret are required in order to connect to {$this->providerId}.", 4 );
- }
-
- require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
- require_once Hybrid_Auth::$config["path_libraries"] . "QQ/QQ.php";
+ parent::initialize();
- if( $this->token( "access_token" ) && $this->token( "access_token_secret" ) ) {
- $this->api = new qqOAuth(
- $this->config["keys"]["key"],
- $this->config["keys"]["secret"],
- $this->token("access_token"),
- $this->token("access_token_secret")
- );
- }
+ // Provider api end-points
+ $this->api->api_base_url = 'http://open.t.qq.com/api/';
+ $this->api->authorize_url = 'https://open.t.qq.com/cgi-bin/authorize';
+ $this->api->request_token_url = 'https://open.t.qq.com/cgi-bin/request_token';
+ $this->api->access_token_url = 'https://open.t.qq.com/cgi-bin/access_token';
}
- /**
- * begin login step
+ /**
+ * load the user profile from the IDp api client
*/
- function loginBegin()
+ function getUserProfile()
{
- $this->api = new qqOAuth( $this->config["keys"]["key"], $this->config["keys"]["secret"] );
-
- // Get a new request token
- $token = $this->api->getRequestToken( $this->endpoint );
+ $parameters = array();
+ $parameters['format'] = 'json';
- if ( ! isset( $token ) )
- {
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Request Token.", 5 );
+ $response = $this->api->get('user/info', $parameters);
+
+ // check the last HTTP status code returned
+ if ( $this->api->http_code != 200 ){
+ throw new Exception( 'User profile request failed! ' . $this->providerId . ' returned an error. ' . $this->errorMessageByStatus( $this->api->http_code ), 6 );
}
- $this->token( "request_token" , $token['oauth_token'] );
- $this->token( "request_token_secret" , $token['oauth_token_secret'] );
+ if ( ! is_object( $response ) ){
+ throw new Exception( 'User profile request failed! ' . $this->providerId . ' api returned an invalid response.', 6 );
+ }
+
+ $profile = $response->data;
+
+ $this->user->profile->identifier = @ $profile->name;
+ $this->user->profile->displayName = @ $profile->nick;
+ $this->user->profile->address = @ $profile->location;
+ $this->user->profile->profileURL = @ 'http://t.qq.com/'.$profile->name;
+ $this->user->profile->photoURL = @ $profile->head;
+ $this->user->profile->email = @ $profile->email;
+ $this->user->profile->birthDay = @ $profile->birth_day;
+ $this->user->profile->birthMonth = @ $profile->birth_month;
+ $this->user->profile->birthYear = @ $profile->birth_year;
+ switch ( $profile->sex ) {
+ case '1': $this->user->profile->gender = 'male'; break;
+ case '2': $this->user->profile->gender = 'female'; break;
+ }
- # Build authorize link & redirect user to vimeo authorisation web page
- Hybrid_Auth::redirect( $this->api->getAuthorizeUrl( $token, urlencode( $this->endpoint ) ) );
+ return $this->user->profile;
}
-
- /**
- * finish login step
- */
- function loginFinish()
- {
- $oauth_token = @ $_REQUEST['oauth_token'];
- $oauth_verifier = @ $_REQUEST['oauth_verifier'];
+
+ /**
+ * load the user contacts
+ */
+ function getUserContacts()
+ {
+ $parameters = array();
+ $parameters['format'] = 'json';
+ $parameters['reqnum'] = 10;
+
+ $response = $this->api->get('friends/idollist', $parameters);
- if ( ! $oauth_token || ! $oauth_verifier )
+ if ( $this->api->http_code != 200 )
{
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid OAuth Token and Verifier.", 5 );
+ throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
}
- try {
-
- $this->api = new qqOAuth(
- $this->config["keys"]["key"],
- $this->config["keys"]["secret"],
- $this->token("request_token"),
- $this->token("request_token_secret")
- );
-
- $token = $this->api->getAccessToken( $oauth_verifier );
-
+ if ( !$response->data->info && ( $response->errcode != 0 ) )
+ {
+ return array();
}
- catch( QQAPIException $e ){
- throw new Exception( "Authentification failed! {$this->providerId} returned an error while requesting a request token. $e.", 5 );
+
+ $contacts = array();
+
+ foreach( $response->data->info as $item ) {
+ $uc = new Hybrid_User_Contact();
+
+ $uc->identifier = @ $item->fansnum;
+ $uc->displayName = @ $item->nick;
+ $uc->profileURL = 'http://t.qq.com/' . $item->name;
+ $uc->photoURL = $item->head . '/100';
+
+ $contacts[] = $uc;
}
+
+ return $contacts;
+ }
+
+ /**
+ * update user status
+ */
+ function setUserStatus( $status )
+ {
+ $parameters = array();
+ $parameters['content'] = $status;
+ $parameters['clientip'] = $this->getIP();
+ $parameters['format'] = 'json';
+
- if ( ! isset( $token["oauth_token"] ) )
+ $response = $this->api->post('t/add', $parameters);
+
+ if ( $this->api->http_code != 200 )
{
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Access Token.", 5 );
+ throw new Exception( 'Update user status failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
+ }
+
+ if ( $response->errcode != 0 )
+ {
+ throw new Exception( 'Update user status failed! ' . $this->providerId . ' returned an error: ' . $response->msg );
}
-
- // Store tokens
- $this->token( "access_token" , $token['oauth_token'] );
- $this->token( "access_token_secret" , $token['oauth_token_secret'] );
- $this->token( "access_name" , $token['name'] );
- // set user as logged in
- $this->setUserConnected();
+ return $response;
}
-
- /**
- * load the user profile from the IDp api client
- */
- function getUserProfile()
+
+ /**
+ * load the user latest activity
+ * - timeline : all the stream
+ * - me : the user activity only
+ */
+ function getUserActivity( $stream )
{
- try{
- $profile = $this->api->get('http://open.t.qq.com/api/user/info');
+ $parameters = array();
+ $parameters['reqnum'] = '10';
+
+ if ( $stream == 'me' )
+ {
+ $url = 'statuses/broadcast_timeline';
+ } else {
+ $url = 'statuses/home_timeline';
}
- catch( QQAPIException $e ){
- throw new Exception( "User profile request failed! {$this->providerId} returned an error while requesting the user profile. $e.", 6 );
+
+ $response = $this->api->get($url, $parameters);
+
+ if ( $this->api->http_code != 200 )
+ {
+ throw new Exception( 'User activity stream request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
}
- if ( ! isset( $profile['data']['name'] ) )
- {
- throw new Exception( "User profile request failed! {$this->providerId} api returned an invalid response.", 6 );
+ $activities = array();
+
+ if ( count( $response->data->info ) > 0 && ( $response->errcode != 0 ) )
+ {
+ return array();
}
-
- $this->user->profile->identifier = @ $profile['data']['name'];
- $this->user->profile->displayName = @ $profile['data']['nick'];
- $this->user->profile->address = @ $profile['data']['location'];
- $this->user->profile->profileURL = @ 'http://t.qq.com/'.$profile['data']['name'];
- $this->user->profile->photoURL = @ $profile['data']['head'];
- $this->user->profile->email = @ $profile['data']['email'];
- $this->user->profile->gender = @ $profile['data']['sex']; // 1 Male, 2 Female, 0 Unknow
- $this->user->profile->birthDay = @ $profile['data']['birth_day'];
- $this->user->profile->birthMonth = @ $profile['data']['birth_month'];
- $this->user->profile->birthYear = @ $profile['data']['birth_year'];
-
- return $this->user->profile;
+
+ foreach ( $response->data->info as $item )
+ {
+ $ua = new Hybrid_User_Activity();
+ $ua->id = @ $item->id;
+ $ua->date = @ $item->timestamp;
+ $ua->text = @ $item->origtext;
+ $ua->user->identifier = @ $item->name;
+ $ua->user->displayName = @ $item->nick;
+ $ua->user->profileURL = 'http://t.qq.com/' . $item->name;
+ $ua->user->photoURL = $item->head . '/100';
+
+ $activities[] = $ua;
+ }
+
+ return $activities;
+ }
+
+ function getIP() {
+ if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
+ } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } else {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+ return $ip;
}
}
View
303 additional-providers/hybridauth-qq/thirdparty/QQ/QQ.php
@@ -1,303 +0,0 @@
-<?PHP
-/**
- * QQ Weibo OAuth Class
- *
- * @package sae
- * @author Easy Chen
- * @version 1.0
- * @hacker RB Lin
- */
-class qqOAuth {
- /**
- * Contains the last HTTP status code returned.
- *
- * @ignore
- */
- public $http_code;
- /**
- * Contains the last API call.
- *
- * @ignore
- */
- public $url;
- /**
- * Set up the API root URL.
- *
- * @ignore
- */
- public $host = "https://open.t.qq.com/";
- /**
- * Set timeout default.
- *
- * @ignore
- */
- public $timeout = 60;
- /**
- * Set connect timeout.
- *
- * @ignore
- */
- public $connecttimeout = 60;
- /**
- * Verify SSL Cert.
- *
- * @ignore
- */
- public $ssl_verifypeer = false;
- /**
- * Respons format.
- *
- * @ignore
- */
- public $format = 'json';
- /**
- * Decode returned json data.
- *
- * @ignore
- */
- public $decode_json = true;
- /**
- * Contains the last HTTP headers returned.
- *
- * @ignore
- */
- public $http_info;
-
-
- /**
- * Set API URLS
- */
- /**
- * @ignore
- */
- function accessTokenURL() { return 'https://open.t.qq.com/cgi-bin/access_token'; }
- /**
- * @ignore
- */
- function authorizeURL() { return 'https://open.t.qq.com/cgi-bin/authorize'; }
- /**
- * @ignore
- */
- function requestTokenURL() { return 'https://open.t.qq.com/cgi-bin/request_token'; }
-
-
- /**
- * Debug helpers
- */
- /**
- * @ignore
- */
- function lastStatusCode() { return $this->http_status; }
- /**
- * @ignore
- */
- function lastAPICall() { return $this->last_api_call; }
-
- /**
- * construct WeiboOAuth object
- */
- function __construct($consumer_key, $consumer_secret, $oauth_token = null, $oauth_token_secret = null) {
- $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
- $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
- if (!empty($oauth_token) && !empty($oauth_token_secret)) {
- $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
- } else {
- $this->token = null;
- }
- }
-
-
- /**
- * Get a request_token from Weibo
- *
- * @return array a key/value array containing oauth_token and oauth_token_secret
- */
- function getRequestToken($oauth_callback = null) {
- $parameters = array();
- if (!empty($oauth_callback)) {
- $parameters['oauth_callback'] = $oauth_callback;
- }
-
- $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
- $token = OAuthUtil::parse_parameters($request);
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
- return $token;
- }
-
- /**
- * Get the authorize URL
- *
- * @return string
- */
- function getAuthorizeUrl($token , $url) {
- if (is_array($token)) {
- $token = $token['oauth_token'];
- }
-
- return $this->authorizeURL() . "?oauth_token={$token}&oauth_callback=" . urlencode($url);
- }
-
- /**
- * Exchange the request token and secret for an access token and
- * secret, to sign API calls.
- *
- * @return array array("oauth_token" => the access token,
- * "oauth_token_secret" => the access secret)
- */
- function getAccessToken($oauth_verifier = false, $oauth_token = false) {
- $parameters = array();
- if (!empty($oauth_verifier)) {
- $parameters['oauth_verifier'] = $oauth_verifier;
- }
-
- /*if (!empty($oauth_token)) {
- $parameters['oauth_token'] = $oauth_token;
- }*/
-
- $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
- $token = OAuthUtil::parse_parameters($request);
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
- return $token;
- }
-
- /**
- * GET wrappwer for oAuthRequest.
- *
- * @return mixed
- */
- function get($url, $parameters = array()) {
- $response = $this->oAuthRequest($url, 'GET', $parameters);
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
-
- /**
- * POST wreapper for oAuthRequest.
- *
- * @return mixed
- */
- function post($url, $parameters = array() , $multi = false) {
-
- $response = $this->oAuthRequest($url, 'POST', $parameters , $multi );
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
-
- /**
- * DELTE wrapper for oAuthReqeust.
- *
- * @return mixed
- */
- function delete($url, $parameters = array()) {
- $response = $this->oAuthRequest($url, 'DELETE', $parameters);
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
-
- /**
- * Format and sign an OAuth / API request
- *
- * @return string
- */
- function oAuthRequest($url, $method, $parameters , $multi = false) {
- if (strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0) {
- $url = "{$this->host}{$url}.{$this->format}";
- }
-
- $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
- $request->sign_request($this->sha1_method, $this->consumer, $this->token);
- switch ($method) {
- case 'GET':
- return $this->http($request->to_url(), 'GET');
- //break;
- default:
- return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata($multi) , $multi );
- //break;
- }
- }
-
- /**
- * Make an HTTP request
- *
- * @return string API results
- */
- function http($url, $method, $postfields = null , $multi = false) {
- $this->http_info = array();
- $ci = curl_init();
- /* Curl settings */
- curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
- curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
- curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
- curl_setopt($ci, CURLOPT_HEADER, false);
-
- switch ($method) {
- case 'POST':
- curl_setopt($ci, CURLOPT_POST, true);
- if (!empty($postfields)) {
- curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
- //echo "=====post data======\r\n";
- //echo $postfields;
- }
- break;
- case 'DELETE':
- curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
- if (!empty($postfields)) {
- $url = "{$url}?{$postfields}";
- }
- }
-
- $header_array = array();
-
- $header_array2 = array();
- if ($multi) {
- $header_array2 = array("Content-Type: multipart/form-data; boundary=" . OAuthUtil::$boundary , "Expect: ");
- }
- foreach ($header_array as $k => $v) {
- array_push($header_array2,$k.': '.$v);
- }
- curl_setopt($ci, CURLOPT_HTTPHEADER, $header_array2 );
- curl_setopt($ci, CURLINFO_HEADER_OUT, true );
-
- //echo $url."\r\n\r\n";
-
- curl_setopt($ci, CURLOPT_URL, $url);
-
- $response = curl_exec($ci);
- $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
- $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
- $this->url = $url;
-
- // echo '=====info====='."\r\n";
- // print_r( curl_getinfo($ci) );
-
- // echo '=====$response====='."\r\n";
- // print_r( $response );
-
- curl_close ($ci);
- return $response;
- }
-
- /**
- * Get the header info to store.
- *
- * @return int
- */
- function getHeader($ch, $header) {
- $i = strpos($header, ':');
- if (!empty($i)) {
- $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
- $value = trim(substr($header, $i + 2));
- $this->http_header[$key] = $value;
- }
- return strlen($header);
- }
-}
-?>
View
257 additional-providers/hybridauth-sina/Providers/Sina.php
@@ -1,59 +1,50 @@
<?php
-/**
+/*!
* HybridAuth
-*
-* A Social-Sign-On PHP Library for authentication through identity providers like Facebook,
-* Twitter, Google, Yahoo, LinkedIn, MySpace, Windows Live, Tumblr, Friendster, OpenID, PayPal,
-* Vimeo, Foursquare, AOL, Gowalla, and others.
-*
-* Copyright (c) 2009-2011 (http://hybridauth.sourceforge.net)
+* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
+* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
*/
/**
- * Sina Weibo OAuth
+ * Sina OAuth Class
*
- * @ID: Sina
- * @Protocol: OAuth
- * @IDp URL: http://www.weibo.com/
- * @Keys registeration: http://open.weibo.com/development
- * @Dev documentation: http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2
- * @Description:
- * @Author: RB Lin <xtheme=at=gmail-dot-com>
- * @Based on: Project Sirius http://code.google.com/p/sirius/
- * @Version: 1.0
- * @Since: HybridAuth 2.0.6
- * @Wrapper: ./Hybrid/Providers/Sina.php
- * @Required Libs: ./Hybrid/thirdparty/Sina/
- * @URL Start login*: http://mywebsite.com/path_to_hybridauth/?hauth.start=Sina
- * @URL Login done*: http://mywebsite.com/path_to_hybridauth/?hauth.done=Sina
+ * @package HybridAuth additional providers package
+ * @author RB Lin <xtheme@gmail.com>
+ * @version 1.2
+ * @license BSD License
*/
/**
- * Hybrid_Providers_Sina class, wrapper for Sina
+ * Sina provider adapter based on OAuth1 protocol
+ *
+ * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Sina.html
*/
class Hybrid_Providers_Sina extends Hybrid_Provider_Model
{
- /**
- * IDp wrappers initializer
- */
+ public $user_id;
+
+ /**
+ * IDp wrappers initializer
+ */
function initialize()
{
- //date_default_timezone_set ('Etc/GMT-8');
-
- if ( ! $this->config["keys"]["key"] || ! $this->config["keys"]["secret"] )
+ if ( ! $this->config['keys']['key'] || ! $this->config['keys']['secret'] )
{
- throw new Exception( "Your application key and secret are required in order to connect to {$this->providerId}.", 4 );
+ throw new Exception( 'Your application key and secret are required in order to connect to ' . $this->providerId . '.', 4 );
}
- require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
- require_once Hybrid_Auth::$config["path_libraries"] . "Sina/Sina.php";
+ require_once Hybrid_Auth::$config['path_libraries'] . 'Sina/saetv2.ex.class.php';
- if( $this->token( "access_token" ) && $this->token( "access_token_secret" ) ) {
- $this->api = new WeiboOAuth(
- $this->config["keys"]["key"],
- $this->config["keys"]["secret"],
- $this->token("access_token"),
- $this->token("access_token_secret")
+ if ( $this->token( 'access_token' ) ) {
+ $this->api = new SaeTClientV2 (
+ $this->config['keys']['key'], $this->config['keys']['secret'], $this->token('access_token')
+ );
+
+ $user = $this->api->get_uid();
+ $this->user_id = $user['uid'];
+ } else {
+ $this->api = new SaeTOAuthV2 (
+ $this->config['keys']['key'], $this->config['keys']['secret']
);
}
}
@@ -63,21 +54,7 @@ function initialize()
*/
function loginBegin()
{
- $this->api = new WeiboOAuth( $this->config["keys"]["key"], $this->config["keys"]["secret"] );
-
- // Get a new request token
- $token = $this->api->getRequestToken( $this->endpoint );
-
- if ( ! isset( $token ) )
- {
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Request Token.", 5 );
- }
-
- $this->token( "request_token" , $token['oauth_token'] );
- $this->token( "request_token_secret" , $token['oauth_token_secret'] );
-
- # Build authorize link & redirect user to vimeo authorisation web page
- Hybrid_Auth::redirect( $this->api->getAuthorizeUrl( $token ) );
+ Hybrid_Auth::redirect( $this->api->getAuthorizeURL( $this->endpoint ) );
}
/**
@@ -85,39 +62,24 @@ function loginBegin()
*/
function loginFinish()
{
- $oauth_token = @ $_REQUEST['oauth_token'];
- $oauth_verifier = @ $_REQUEST['oauth_verifier'];
-
- if ( ! $oauth_token || ! $oauth_verifier )
+ if ( ! $_REQUEST['code'] )
{
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid OAuth Token and Verifier.", 5 );
- }
-
- try {
-
- $this->api = new WeiboOAuth(
- $this->config["keys"]["key"],
- $this->config["keys"]["secret"],
- $this->token("request_token"),
- $this->token("request_token_secret")
- );
-
- $token = $this->api->getAccessToken( $oauth_verifier );
-
- }
- catch( SinaAPIException $e ){
- throw new Exception( "Authentification failed! {$this->providerId} returned an error while requesting a request token. $e.", 5 );
+ throw new Exception( 'Authentification failed! ' . $this->providerId . ' returned an invalid OAuth Token and Verifier.', 5 );
}
+
- if ( ! isset( $token["oauth_token"] ) )
- {
- throw new Exception( "Authentification failed! {$this->providerId} returned an invalid Access Token.", 5 );
+ $params = array();
+ $params['code'] = $_REQUEST['code'];
+ $params['redirect_uri'] = $this->endpoint;
+
+ try {
+ $tokz = $this->api->getAccessToken( 'code', $params ) ;
+ } catch (OAuthException $e) {
+ throw new Exception( 'Authentification failed! ' . $this->providerId . ' returned an invalid Access Token.', 5 );
}
// Store tokens
- $this->token( "access_token" , $token['oauth_token'] );
- $this->token( "access_token_secret" , $token['oauth_token_secret'] );
- $this->token( "access_user_id" , $token['user_id'] );
+ $this->token( 'access_token', $tokz['access_token'] );
// set user as logged in
$this->setUserConnected();
@@ -128,30 +90,129 @@ function loginFinish()
*/
function getUserProfile()
{
- try{
- $profile = $this->api->request_with_uid( 'http://api.t.sina.com.cn/users/show.json', $this->token('access_user_id'));
- //$profile = $this->api->request_with_uid( 'https://api.weibo.com/2/account/profile/basic.json', $this->token('access_user_id'));
+ $response = $this->api->show_user_by_id($this->user_id);
+
+ if ( $this->api->oauth->http_code != 200 )
+ {
+ throw new Exception( 'User profile request failed! ' . $this->providerId . ' returned an error: ' . $response['error'], 6 );
+ }
+
+ if ( ! $response )
+ {
+ throw new Exception( 'User profile request failed! ' . $this->providerId . ' api returned an invalid response.', 6 );
}
- catch( SinaAPIException $e ){
- throw new Exception( "User profile request failed! {$this->providerId} returned an error while requesting the user profile. $e.", 6 );
+
+ $this->user->profile->identifier = @ $response['id'];
+ $this->user->profile->displayName = @ $response['screen_name'];
+ $this->user->profile->address = @ $response['location'];
+ $this->user->profile->profileURL = @ 'http://www.weibo.com/u/' . $response['id'];
+ $this->user->profile->photoURL = @ $response['profile_image_url'];
+ $this->user->profile->webSiteURL = @ $response['url'];
+ switch ( $response['gender'] ) {
+ case 'm': $this->user->profile->gender = 'male'; break;
+ case 'f': $this->user->profile->gender = 'female'; break;
}
- if ( ! isset( $profile['id'] ) )
- {
- throw new Exception( "User profile request failed! {$this->providerId} api returned an invalid response.", 6 );
+ return $this->user->profile;
+ }
+
+ /**
+ * load the user contacts
+ */
+ function getUserContacts()
+ {
+ $params = array();
+ $params['uid'] = $this->user_id;
+ $params['cursor'] = 0;
+ $params['count'] = 10;
+
+ $response = $this->api->oauth->get( 'friendships/friends', $params );
+
+ if ( $this->api->oauth->http_code != 200 )
+ {
+ throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $response['error'] );
}
- $this->user->profile->identifier = @ $profile['id'];
- $this->user->profile->displayName = @ $profile['screen_name'];
- $this->user->profile->address = @ $profile['location'];
- $this->user->profile->profileURL = @ 'http://www.weibo.com/u/'.$profile['id'];
- $this->user->profile->photoURL = @ $profile['profile_image_url'];
- $this->user->profile->webSiteURL = @ $profile['url'];
- if( isset( $profile['email'] ) ) {
- $this->user->profile->email = @ $profile['email'];
+ if ( !$response )
+ {
+ return array();
}
- $this->user->profile->gender = @ $profile['gender']; // m Male, f Female
+
+ $contacts = array();
+
+ foreach( $response['users'] as $item ) {
+ $uc = new Hybrid_User_Contact();
- return $this->user->profile;
+ $uc->identifier = @ $item['id'];
+ $uc->displayName = @ $item['name'];
+ $uc->profileURL = @ $item['url'];
+ $uc->photoURL = @ $item['profile_image_url'];
+ $uc->description = @ $item['description'];
+
+ $contacts[] = $uc;
+ }
+
+ return $contacts;
+ }
+
+ /**
+ * update user status
+ */
+ function setUserStatus( $status )
+ {
+ $response = $this->api->update($status);
+
+ if ( $this->api->oauth->http_code != 200 )
+ {
+ throw new Exception( 'Update user status failed! ' . $this->providerId . ' returned an error: ' . $response['error'] );
+ }
+
+ return $response;
+ }
+
+ /**
+ * load the user latest activity
+ * - timeline : all the stream
+ * - me : the user activity only
+ */
+ function getUserActivity( $stream )
+ {
+ $page = 1;
+ $count = 10;
+
+ if ( $stream == 'me' )
+ {
+ $response = $this->api->user_timeline_by_id($this->user_id, $page, $count);
+ } else {
+ $response = $this->api->home_timeline($page, $count);
+ }
+
+ if ( $this->api->oauth->http_code != 200 )
+ {
+ throw new Exception( 'User activity stream request failed! ' . $this->providerId . ' returned an error: ' . $response['error'] );
+ }
+
+ $activities = array();
+
+ if ( $response['total_number'] == 0 )
+ {
+ return $activities;
+ }
+
+ foreach ( $response['statuses'] as $item )
+ {
+ $ua = new Hybrid_User_Activity();
+ $ua->id = @ $item['id'];
+ $ua->date = @ strtotime($item['created_at']);
+ $ua->text = @ $item['text'];
+ $ua->user->identifier = @ $item['user']['id'];
+ $ua->user->displayName = @ $item['user']['screen_name'];
+ $ua->user->profileURL = 'http://www.weibo.com/u/' . $item['user']['id'];
+ $ua->user->photoURL = $item['user']['profile_image_url'];
+
+ $activities[] = $ua;
+ }
+
+ return $activities;
}
}
View
2 hybridauth/Hybrid/Auth.php
@@ -14,7 +14,7 @@
*/
class Hybrid_Auth
{
- public static $version = "2.0.9";
+ public static $version = "2.0.10-dev";
public static $config = array();
View
2 hybridauth/config.php
@@ -11,7 +11,7 @@
return
array(
- "base_url" => "http://localhost/hybridauth-2.0.9/hybridauth/",
+ "base_url" => "http://localhost/hybridauth-git/hybridauth/",
"providers" => array (
// openid providers
View
3 hybridauth/index.php
@@ -125,7 +125,8 @@
// Fix a strange behavior when some provider call back ha endpoint
// with /index.php?hauth.done={provider}?oauth_token={oauth_token}
// By RP Lin
- if ( strrpos( $_REQUEST["hauth_done"], 'oauth_token' ) ) {
+ if ( strrpos( $_REQUEST["hauth_done"], 'oauth_token' ) )
+ {
$arr = explode( 'oauth_token', $_REQUEST["hauth_done"] );
$_REQUEST["hauth_done"] = substr( $arr[0], 0, -1 ); // remove ?
$_REQUEST["oauth_token"] = substr( $arr[1], 1 ); // remove =
View
4 hybridauth/install.php
@@ -70,7 +70,7 @@
}
</style>
<?php
- $HYBRIDAUTH_VERSION = "2.0.9";
+ $HYBRIDAUTH_VERSION = "2.0.10-dev";
$CONFIG_TEMPLATE = "";
/**
@@ -365,7 +365,7 @@ function getCurrentUrl()
<?php endif; ?>
<?php if ( $provider == "Facebook" ) : ?>
- <p>Make sure to put your correct website adress in the "Site Url" field. This adresse must match with the current hostname "<em style="color:#CB4B16;"><?php echo $_SERVER["SERVER_NAME"] ?></em>". - btw, facebook wont work on <em>"http://localhost"</em>.</p>
+ <p>Make sure to put your correct website adress in the "Site Url" field. This adresse must match with the current hostname "<em style="color:#CB4B16;"><?php echo $_SERVER["SERVER_NAME"] ?></em>".</p>
<p>Once you have registered, copy the created application ID and Secret into this setup page.</p>
<?php elseif ( $provider == "Google" ) : ?>
<p>On the <b>"Create Client ID"</b> popup switch to advanced settings by clicking on <b>(more options)</b>.</p>

0 comments on commit e7c38cb

Please sign in to comment.
Something went wrong with that request. Please try again.