1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\migrations; |
4
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcScopeInterface; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ScopeInterface; |
7
|
|
|
use rhertogh\Yii2Oauth2Server\migrations\base\Oauth2BaseMigration; |
8
|
|
|
use yii\helpers\ArrayHelper; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps |
12
|
|
|
* phpcs:disable Generic.Files.LineLength.TooLong |
13
|
|
|
*/ |
14
|
|
|
abstract class Oauth2_00002_InsertOpenIdConnectScopesMigration extends Oauth2BaseMigration |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritDoc |
18
|
|
|
*/ |
19
|
2 |
|
public static function generationIsActive($module) |
20
|
|
|
{ |
21
|
2 |
|
return $module->enableOpenIdConnect; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Default value for Scope's `required_on_authorization`. |
26
|
|
|
* @var bool |
27
|
|
|
* @since 1.0.0 |
28
|
|
|
*/ |
29
|
|
|
public $scopeRequiredOnAuthorization = true; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Default description for OpenID Connect scopes |
33
|
|
|
* @var array[] |
34
|
|
|
*/ |
35
|
|
|
protected $openIdConnectScopes = [ |
36
|
|
|
[ |
37
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_OPENID, |
38
|
|
|
'description' => 'OpenID Connect scope', |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_PROFILE, |
42
|
|
|
'description' => 'OpenID Connect profile scope', |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_EMAIL, |
46
|
|
|
'description' => 'OpenID Connect email scope', |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_ADDRESS, |
50
|
|
|
'description' => 'OpenID Connect address scope', |
51
|
|
|
], |
52
|
|
|
[ |
53
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_PHONE, |
54
|
|
|
'description' => 'OpenID Connect phone scope', |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
'identifier' => Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_OFFLINE_ACCESS, |
58
|
|
|
'description' => 'OpenID Offline Access scope', |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
1 |
|
public function safeUp() |
66
|
|
|
{ |
67
|
1 |
|
$tableName = $this->getTableName(Oauth2ScopeInterface::class); |
68
|
1 |
|
foreach ($this->openIdConnectScopes as $scope) { |
69
|
1 |
|
$this->insert($tableName, ArrayHelper::merge([ |
70
|
1 |
|
'required_on_authorization' => (int)$this->scopeRequiredOnAuthorization, |
71
|
1 |
|
'created_at' => time(), |
72
|
1 |
|
'updated_at' => time(), |
73
|
1 |
|
], $scope)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritDoc |
79
|
|
|
*/ |
80
|
1 |
|
public function safeDown() |
81
|
|
|
{ |
82
|
1 |
|
$tableName = $this->getTableName(Oauth2ScopeInterface::class); |
83
|
1 |
|
$openIdConnectScopeIdentifiers = array_column($this->openIdConnectScopes, 'identifier'); |
84
|
1 |
|
$this->delete($tableName, ['identifier' => $openIdConnectScopeIdentifiers]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|