forked from xjflyttp/yii2-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
609 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
* Douban OAuth | ||
* @author light <[email protected]> | ||
*/ | ||
class DoubanAuth extends OAuth2 implements IAuth { | ||
class DoubanAuth extends OAuth2 implements IAuth | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
|
@@ -31,25 +32,35 @@ class DoubanAuth extends OAuth2 implements IAuth { | |
*/ | ||
public $scope = 'douban_basic_common'; | ||
|
||
protected function initUserAttributes() | ||
{ | ||
//nothing | ||
return $this->api('v2/user/~me', 'GET'); | ||
} | ||
|
||
/** | ||
* Get authed user info | ||
* | ||
* @return array | ||
* @see http://developers.douban.com/wiki/?title=user_v2#User | ||
*/ | ||
public function getUserInfo() { | ||
return $this->api('v2/user/~me', 'GET'); | ||
public function getUserInfo() | ||
{ | ||
return $this->getUserAttributes(); | ||
} | ||
|
||
protected function defaultName() { | ||
protected function defaultName() | ||
{ | ||
return 'douban'; | ||
} | ||
|
||
protected function defaultTitle() { | ||
protected function defaultTitle() | ||
{ | ||
return 'Douban'; | ||
} | ||
|
||
protected function defaultViewOptions() { | ||
protected function defaultViewOptions() | ||
{ | ||
return [ | ||
'popupWidth' => 800, | ||
'popupHeight' => 500, | ||
|
@@ -60,7 +71,8 @@ protected function defaultViewOptions() { | |
* | ||
* @ineritdoc | ||
*/ | ||
public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = []) { | ||
public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = []) | ||
{ | ||
if (preg_match('/^https?:\\/\\//is', $apiSubUrl)) { | ||
$url = $apiSubUrl; | ||
} else { | ||
|
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 |
---|---|---|
|
@@ -8,13 +8,15 @@ | |
* QQ OAuth | ||
* @author xjflyttp <[email protected]> | ||
*/ | ||
class QqAuth extends OAuth2 implements IAuth { | ||
class QqAuth extends OAuth2 implements IAuth | ||
{ | ||
|
||
public $authUrl = 'https://graph.qq.com/oauth2.0/authorize'; | ||
public $tokenUrl = 'https://graph.qq.com/oauth2.0/token'; | ||
public $apiBaseUrl = 'https://graph.qq.com'; | ||
|
||
public function init() { | ||
public function init() | ||
{ | ||
parent::init(); | ||
if ($this->scope === null) { | ||
$this->scope = implode(',', [ | ||
|
@@ -23,7 +25,8 @@ public function init() { | |
} | ||
} | ||
|
||
protected function initUserAttributes() { | ||
protected function initUserAttributes() | ||
{ | ||
return $this->api('oauth2.0/me', 'GET'); | ||
} | ||
|
||
|
@@ -32,23 +35,27 @@ protected function initUserAttributes() { | |
* @return [] | ||
* @see http://wiki.connect.qq.com/get_user_info | ||
*/ | ||
public function getUserInfo() { | ||
public function getUserInfo() | ||
{ | ||
$openid = $this->getUserAttributes(); | ||
return $this->api("user/get_user_info", 'GET', [ | ||
'oauth_consumer_key' => $openid['client_id'], | ||
'openid' => $openid['openid' | ||
]]); | ||
} | ||
|
||
protected function defaultName() { | ||
protected function defaultName() | ||
{ | ||
return 'QQ'; | ||
} | ||
|
||
protected function defaultTitle() { | ||
protected function defaultTitle() | ||
{ | ||
return 'QQ'; | ||
} | ||
|
||
protected function defaultViewOptions() { | ||
protected function defaultViewOptions() | ||
{ | ||
return [ | ||
'popupWidth' => 800, | ||
'popupHeight' => 500, | ||
|
@@ -62,7 +69,8 @@ protected function defaultViewOptions() { | |
* @throws Exception on failure. | ||
* @return array actual response. | ||
*/ | ||
protected function processResponse($rawResponse, $contentType = self::CONTENT_TYPE_AUTO) { | ||
protected function processResponse($rawResponse, $contentType = self::CONTENT_TYPE_AUTO) | ||
{ | ||
if ($contentType == self::CONTENT_TYPE_AUTO) { | ||
//jsonp to json | ||
if (strpos($rawResponse, "callback") === 0) { | ||
|
Oops, something went wrong.