Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ScopeRepository | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScopeEntityByIdentifier | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
finalizeScopes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * OAuth2 scope repository implementation. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2022. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package OAuth2 |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\OAuth2\Repository; |
31 | |
32 | use League\OAuth2\Server\Entities\ClientEntityInterface; |
33 | use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; |
34 | use VuFind\OAuth2\Entity\ScopeEntity; |
35 | |
36 | /** |
37 | * OAuth2 scope repository implementation. |
38 | * |
39 | * @category VuFind |
40 | * @package OAuth2 |
41 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org Main Site |
44 | */ |
45 | class ScopeRepository implements ScopeRepositoryInterface |
46 | { |
47 | /** |
48 | * OAuth2 server configuration |
49 | * |
50 | * @var array |
51 | */ |
52 | protected $oauth2Config = []; |
53 | |
54 | /** |
55 | * Constructor |
56 | * |
57 | * @param array $config OAuth2 configuration |
58 | */ |
59 | public function __construct(array $config) |
60 | { |
61 | $this->oauth2Config = $config; |
62 | } |
63 | |
64 | /** |
65 | * Return information about a scope. |
66 | * |
67 | * @param string $identifier The scope identifier |
68 | * |
69 | * @return ScopeEntityInterface|null |
70 | */ |
71 | public function getScopeEntityByIdentifier($identifier) |
72 | { |
73 | if (!isset($this->oauth2Config['Scopes'][$identifier])) { |
74 | return null; |
75 | } |
76 | $config = $this->oauth2Config['Scopes'][$identifier]; |
77 | $config['identifier'] = $identifier; |
78 | return new ScopeEntity($config); |
79 | } |
80 | |
81 | /** |
82 | * Given a client, grant type and optional user identifier validate the set of |
83 | * scopes requested are valid and optionally append additional scopes or remove |
84 | * requested scopes. |
85 | * |
86 | * @param ScopeEntityInterface[] $scopes Scopes |
87 | * @param string $grantType Grant type |
88 | * @param ClientEntityInterface $clientEntity Client |
89 | * @param null|string $userIdentifier User ID |
90 | * |
91 | * @return ScopeEntityInterface[] |
92 | * |
93 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
94 | */ |
95 | public function finalizeScopes( |
96 | array $scopes, |
97 | $grantType, |
98 | ClientEntityInterface $clientEntity, |
99 | $userIdentifier = null |
100 | ) { |
101 | return $scopes; |
102 | } |
103 | } |