-
Notifications
You must be signed in to change notification settings - Fork 1
/
OAuth2China.php
73 lines (67 loc) · 1.78 KB
/
OAuth2China.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* OAuth2China for Yii
*
* @link http://github.com/tlikai/OAuth2China
* @author likai<[email protected]>
* @license http://www.youyuge.com/license New BSD License
*/
Yii::setPathOfAlias('OAuth2China', __DIR__);
Yii::import('OAuth2China.providers.*');
class OAuth2China extends CComponent
{
/**
* provider configure
*
* @var array
*/
private $_providers;
/**
* supported providers
*
* @var array
*/
public static $supportProviders = array(
'weibo',
'douban',
'renren',
'qq'
);
/**
* initialize providers
*
* @param array
*/
public function __construct($providers)
{
foreach($providers as $name => $provider)
if(in_array($name, self::$supportProviders))
{
if(isset($provider['redirectUri']))
$provider['redirectUri'] = Yii::app()->createAbsoluteUrl($provider['redirectUri'], array('provider' => $name));
else
{
$route = Yii::app()->controller->id . '/' . Yii::app()->controller->action->id;
$provider['redirectUri'] = Yii::app()->createAbsoluteUrl($route, array('provider' => $name));
}
$this->_providers[$name] = $provider;
}
}
/**
* get provider by name
*
* @public
* @param string $name
*
* @return OAuth2China_Provider
*/
public function getProvider($name)
{
if(isset($this->_providers[$name]))
{
$className = 'OAuth2China_Provider_' . ucfirst($name);
return new $className($this->_providers[$name]);
}
throw new CException('OAuth2China: provider does not exist.');
}
}