|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\controllers\console; |
|
4
|
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\console\base\Oauth2BaseConsoleController; |
|
6
|
|
|
use rhertogh\Yii2Oauth2Server\controllers\console\encryption\Oauth2RotateEncryptionKeysAction; |
|
7
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2EncryptionKeyUsageActionInterface; |
|
8
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2GenerateSecretActionInterface; |
|
9
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2EncryptionControllerInterface; |
|
10
|
|
|
use yii\helpers\ArrayHelper; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Manage Oauth2 Server encryption keys. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Oauth2EncryptionController extends Oauth2BaseConsoleController implements Oauth2EncryptionControllerInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string|null |
|
19
|
|
|
*/ |
|
20
|
|
|
public $keyName = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
public $secretLength = 32; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritDoc |
|
29
|
|
|
*/ |
|
30
|
|
|
public function options($actionID) |
|
31
|
|
|
{ |
|
32
|
|
|
$options = parent::options($actionID); |
|
33
|
|
|
if (in_array($actionID, ['key-usage', 'rotate-keys', 'generate-secret'])) { |
|
34
|
|
|
$options = ArrayHelper::merge($options, [ |
|
35
|
|
|
'keyName', |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
if ($actionID === 'generate-secret') { |
|
39
|
|
|
$options = ArrayHelper::merge($options, [ |
|
40
|
|
|
'secretLength', |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
return $options; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function optionAliases() |
|
47
|
|
|
{ |
|
48
|
|
|
return ArrayHelper::merge(parent::optionAliases(), [ |
|
49
|
|
|
'k' => 'keyName', |
|
50
|
|
|
'l' => 'secretLength', |
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritDoc |
|
56
|
|
|
*/ |
|
57
|
|
|
public function actions() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
'key-usage' => Oauth2EncryptionKeyUsageActionInterface::class, |
|
61
|
|
|
'rotate-keys' => Oauth2RotateEncryptionKeysAction::class, |
|
62
|
|
|
'generate-secret' => Oauth2GenerateSecretActionInterface::class, |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|