Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Murmur Pixnet Plurk and updates some others providers
- Loading branch information
hybridauth
committed
Nov 30, 2011
1 parent
fc7b517
commit e7c38cb
Showing
8 changed files
with
322 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.