oauth2

支持国内多家社交平台OAuth2授权的扩展
5 followers

不好意思,之前的代码有点错误

支持:qq、weibo、360、douban、163、renren、kaixin、taobao

Yii::import('ext.oauth2.OAuth2');
 
        $config = require Yii::getPathOfAlias('ext.oauth2') . '/config.php';
 
        if ( ! isset($config[$provider]))
        {
            throw new CHttpException('invalid request.');
        }
 
        try
        {
            $oauth2 = OAuth2::create($provider, $config[$provider]);
        }
        catch (OAuth2_Exception $e)
        {
            throw new CHttpException($e->getMessage());
        }
 
        if( ! isset($_GET['code']))
        {
            $oauth2->redirect();
        }
 
        if ( ! $oauth2->validateState(Yii::app()->request->getQuery('state')))
        {
            throw new CHttpException('invalid request.');
        }
 
        try
        {
            $token = $oauth2->getToken($_GET['code']);
 
            if ( ! $token)
            {
                throw new CHttpException('500', $provider . ' - get token error.');
            }
 
            $userInfo = $oauth2->getUserInfo($token);
 
            if ( ! $userInfo)
            {
                throw new CHttpException('500', $provider . ' - get user info error.');
            }
        }
        catch (OAuth2_Exception $e)
        {
            throw new CHttpException($e->getMessage());
        }
 
        echo '<pre>';
        print_r($userInfo);
        exit();

Total 2 comments

#15363 report it
athurg at 2013/11/01 03:26am
English Description

This is a OAuth2 authenticate extension, which support most SNS platforms in China.

Such as QQ/Weibo(From Sina)/360/douban/163/renren/kaixin/taobao.

And the author also noticed , that the old version has some bugs.

So just skip the old versions, and use the latest.

#14267 report it
trond at 2013/07/31 03:40am
In English please

for the benefit of Yii users who do not understand Chinese, I suggest you translate the description to English. Even if this extension is meant for Chinese users, it will be easier for non Chinese users to determine if this is relevant for them. Thanks.

Leave a comment

Please to leave your comment.

Create extension
Downloads
  • Yii Version:
  • License: New BSD License
  • Developed by: 54xiaosu
  • Category: Auth
  • Votes: -1
  • Downloaded: 747 times
  • Created on: Jul 30, 2013
  • Last updated: Aug 15, 2013
  • Tags: oauth2