1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Passport\Traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Passport\Adaptors\Generic\RedirectUri; |
22
|
|
|
use Limoncello\Passport\Adaptors\Generic\Scope; |
23
|
|
|
use Limoncello\Passport\Contracts\Entities\ClientInterface; |
24
|
|
|
use Limoncello\Passport\Contracts\PassportServerIntegrationInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @package Limoncello\Passport |
28
|
|
|
*/ |
29
|
|
|
trait PassportSeedTrait |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param PassportServerIntegrationInterface $integration |
33
|
|
|
* @param ClientInterface $client |
34
|
|
|
* @param array $scopeDescriptions |
35
|
|
|
* @param string[] $redirectUris |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
1 |
|
protected function seedClient( |
40
|
|
|
PassportServerIntegrationInterface $integration, |
41
|
|
|
ClientInterface $client, |
42
|
|
|
array $scopeDescriptions, |
43
|
|
|
array $redirectUris = [] |
44
|
|
|
): void { |
45
|
1 |
|
$scopeIds = $client->getScopeIdentifiers(); |
46
|
1 |
|
$scopeRepo = $integration->getScopeRepository(); |
47
|
1 |
|
foreach ($scopeDescriptions as $scopeId => $scopeDescription) { |
48
|
1 |
|
$scopeRepo->create( |
49
|
1 |
|
(new Scope()) |
50
|
1 |
|
->setIdentifier($scopeId) |
51
|
1 |
|
->setDescription($scopeDescription) |
52
|
|
|
); |
53
|
1 |
|
$scopeIds[] = $scopeId; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
$integration->getClientRepository()->create($client->setScopeIdentifiers($scopeIds)); |
57
|
|
|
|
58
|
1 |
|
$uriRepo = $integration->getRedirectUriRepository(); |
59
|
1 |
|
foreach ($redirectUris as $uri) { |
60
|
1 |
|
$uriRepo->create( |
61
|
1 |
|
(new RedirectUri()) |
62
|
1 |
|
->setValue($uri) |
63
|
1 |
|
->setClientIdentifier($client->getIdentifier()) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|