|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* RefreshToken.php |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.6+ |
|
6
|
|
|
* |
|
7
|
|
|
* @author Philippe Gaultier <[email protected]> |
|
8
|
|
|
* @copyright 2010-2017 Philippe Gaultier |
|
9
|
|
|
* @license http://www.sweelix.net/license license |
|
10
|
|
|
* @version 1.1.0 |
|
11
|
|
|
* @link http://www.sweelix.net |
|
12
|
|
|
* @package sweelix\oauth2\server\models |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace sweelix\oauth2\server\models; |
|
16
|
|
|
|
|
17
|
|
|
use sweelix\oauth2\server\behaviors\EmptyArrayBehavior; |
|
18
|
|
|
use sweelix\oauth2\server\interfaces\RefreshTokenModelInterface; |
|
19
|
|
|
use Yii; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* This is the refresh token model |
|
23
|
|
|
* |
|
24
|
|
|
* @author Philippe Gaultier <[email protected]> |
|
25
|
|
|
* @copyright 2010-2017 Philippe Gaultier |
|
26
|
|
|
* @license http://www.sweelix.net/license license |
|
27
|
|
|
* @version 1.1.0 |
|
28
|
|
|
* @link http://www.sweelix.net |
|
29
|
|
|
* @package sweelix\oauth2\server\models |
|
30
|
|
|
* @since 1.0.0 |
|
31
|
|
|
* |
|
32
|
|
|
* @property string $id |
|
33
|
|
|
* @property string $clientId |
|
34
|
|
|
* @property string $userId |
|
35
|
|
|
* @property string $expiry |
|
36
|
|
|
* @property array $scopes |
|
37
|
|
|
*/ |
|
38
|
|
|
class RefreshToken extends BaseModel implements RefreshTokenModelInterface |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritdoc |
|
42
|
|
|
*/ |
|
43
|
7 |
|
public function behaviors() |
|
44
|
|
|
{ |
|
45
|
7 |
|
$behaviors = parent::behaviors(); |
|
46
|
7 |
|
$behaviors['emptyArray'] = [ |
|
47
|
7 |
|
'class' => EmptyArrayBehavior::className(), |
|
48
|
7 |
|
'attributes' => ['scopes'], |
|
49
|
|
|
]; |
|
50
|
7 |
|
return $behaviors; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritdoc |
|
55
|
|
|
*/ |
|
56
|
7 |
|
public function rules() |
|
57
|
|
|
{ |
|
58
|
|
|
return [ |
|
59
|
7 |
|
[['id', 'clientId'], 'string'], |
|
60
|
7 |
|
[['scopes'], 'scope'], |
|
61
|
7 |
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return \sweelix\oauth2\server\interfaces\RefreshTokenServiceInterface |
|
66
|
|
|
*/ |
|
67
|
8 |
|
protected static function getDataService() |
|
68
|
|
|
{ |
|
69
|
8 |
|
return Yii::createObject('sweelix\oauth2\server\interfaces\RefreshTokenServiceInterface'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @inheritdoc |
|
74
|
|
|
*/ |
|
75
|
7 |
|
public function key() |
|
76
|
|
|
{ |
|
77
|
7 |
|
return 'id'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return array definition of model attributes |
|
82
|
|
|
* @since 1.0.0 |
|
83
|
|
|
*/ |
|
84
|
7 |
|
public function attributesDefinition() |
|
85
|
|
|
{ |
|
86
|
|
|
return [ |
|
87
|
7 |
|
'id' => 'string', |
|
88
|
7 |
|
'clientId' => 'string', |
|
89
|
7 |
|
'userId' => 'string', |
|
90
|
7 |
|
'expiry' => 'string', |
|
91
|
7 |
|
'scopes' => 'array', |
|
92
|
7 |
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @inheritdoc |
|
97
|
|
|
*/ |
|
98
|
7 |
|
public static function findOne($id) |
|
99
|
|
|
{ |
|
100
|
7 |
|
return self::getDataService()->findOne($id); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @inheritdoc |
|
105
|
|
|
*/ |
|
106
|
7 |
|
public function save($runValidation = true, $attributes = null) |
|
107
|
|
|
{ |
|
108
|
7 |
|
if ($runValidation && !$this->validate($attributes)) { |
|
109
|
1 |
|
Yii::info('Model not inserted due to validation error.', __METHOD__); |
|
110
|
1 |
|
$result = false; |
|
111
|
1 |
|
} else { |
|
112
|
7 |
|
$result = self::getDataService()->save($this, $attributes); |
|
113
|
|
|
} |
|
114
|
7 |
|
return $result; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @inheritdoc |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function delete() |
|
121
|
|
|
{ |
|
122
|
2 |
|
return self::getDataService()->delete($this); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @inheritdoc |
|
127
|
|
|
*/ |
|
128
|
2 |
|
public static function findAllByUserId($userId) |
|
129
|
|
|
{ |
|
130
|
2 |
|
return self::getDataService()->findAllByUserId($userId); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @inheritdoc |
|
135
|
|
|
*/ |
|
136
|
2 |
|
public static function findAllByClientId($clientId) |
|
137
|
|
|
{ |
|
138
|
2 |
|
return self::getDataService()->findAllByClientId($clientId); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|