4
4
5
5
use \Yii ;
6
6
use yii \i18n \PhpMessageSource ;
7
- use \array_key_exists ;
8
7
use yii \helpers \ArrayHelper ;
9
8
10
9
/**
11
10
* For example,
12
- *
11
+ *
13
12
* ```php
14
13
* 'oauth2' => [
15
14
* 'class' => 'filsh\yii2\oauth2server\Module',
32
31
*/
33
32
class Module extends \yii \base \Module
34
33
{
35
- const VERSION = '2.0.2 ' ;
34
+ const VERSION = '2.0.3 ' ;
36
35
37
36
/**
38
37
* @var array Model's map
@@ -58,10 +57,6 @@ class Module extends \yii\base\Module
58
57
* @var type max access lifetime
59
58
*/
60
59
public $ tokenAccessLifetime ;
61
- /**
62
- * @var whether to use JWT tokens
63
- */
64
- public $ useJwtToken = false ;//ADDED
65
60
66
61
/**
67
62
* @inheritdoc
@@ -74,29 +69,14 @@ public function init()
74
69
75
70
/**
76
71
* Gets Oauth2 Server
77
- *
72
+ *
78
73
* @return \filsh\yii2\oauth2server\Server
79
74
* @throws \yii\base\InvalidConfigException
80
75
*/
81
76
public function getServer ()
82
77
{
83
78
if (!$ this ->has ('server ' )) {
84
79
$ storages = [];
85
-
86
- if ($ this ->useJwtToken )
87
- {
88
- if (!array_key_exists ('access_token ' , $ this ->storageMap ) || !array_key_exists ('public_key ' , $ this ->storageMap )) {
89
- throw new \yii \base \InvalidConfigException ('access_token and public_key must be set or set useJwtToken to false ' );
90
- }
91
- //define dependencies when JWT is used instead of normal token
92
- \Yii::$ container ->clear ('public_key ' ); //remove old definition
93
- \Yii::$ container ->set ('public_key ' , $ this ->storageMap ['public_key ' ]);
94
- \Yii::$ container ->set ('OAuth2\Storage\PublicKeyInterface ' , $ this ->storageMap ['public_key ' ]);
95
-
96
- \Yii::$ container ->clear ('access_token ' ); //remove old definition
97
- \Yii::$ container ->set ('access_token ' , $ this ->storageMap ['access_token ' ]);
98
- }
99
-
100
80
foreach (array_keys ($ this ->storageMap ) as $ name ) {
101
81
$ storages [$ name ] = \Yii::$ container ->get ($ name );
102
82
}
@@ -106,13 +86,13 @@ public function getServer()
106
86
if (!isset ($ storages [$ name ]) || empty ($ options ['class ' ])) {
107
87
throw new \yii \base \InvalidConfigException ('Invalid grant types configuration. ' );
108
88
}
109
-
89
+
110
90
$ class = $ options ['class ' ];
111
91
unset($ options ['class ' ]);
112
-
92
+
113
93
$ reflection = new \ReflectionClass ($ class );
114
94
$ config = array_merge ([0 => $ storages [$ name ]], [$ options ]);
115
-
95
+
116
96
$ instance = $ reflection ->newInstanceArgs ($ config );
117
97
$ grantTypes [$ name ] = $ instance ;
118
98
}
@@ -121,14 +101,13 @@ public function getServer()
121
101
$ this ,
122
102
$ storages ,
123
103
[
124
- 'use_jwt_access_tokens ' => $ this ->useJwtToken ,//ADDED
125
104
'token_param_name ' => $ this ->tokenParamName ,
126
105
'access_lifetime ' => $ this ->tokenAccessLifetime ,
127
106
/** add more ... */
128
107
],
129
108
$ grantTypes
130
109
]);
131
-
110
+
132
111
$ this ->set ('server ' , $ server );
133
112
}
134
113
return $ this ->get ('server ' );
@@ -149,10 +128,10 @@ public function getResponse()
149
128
}
150
129
return $ this ->get ('response ' );
151
130
}
152
-
131
+
153
132
/**
154
133
* Register translations for this module
155
- *
134
+ *
156
135
* @return array
157
136
*/
158
137
public function registerTranslations ()
@@ -167,7 +146,7 @@ public function registerTranslations()
167
146
168
147
/**
169
148
* Translate module message
170
- *
149
+ *
171
150
* @param string $category
172
151
* @param string $message
173
152
* @param array $params
@@ -178,4 +157,4 @@ public static function t($category, $message, $params = [], $language = null)
178
157
{
179
158
return Yii::t ('modules/oauth2/ ' . $ category , $ message , $ params , $ language );
180
159
}
181
- }
160
+ }
0 commit comments