Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ClientEntity | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
5 | |||
setName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * OAuth2 client entity 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\Entity; |
31 | |
32 | use League\OAuth2\Server\Entities\ClientEntityInterface; |
33 | use League\OAuth2\Server\Entities\Traits\ClientTrait; |
34 | use League\OAuth2\Server\Entities\Traits\EntityTrait; |
35 | use VuFind\Exception\BadConfig as BadConfigException; |
36 | |
37 | /** |
38 | * OAuth2 client entity implementation. |
39 | * |
40 | * @category VuFind |
41 | * @package OAuth2 |
42 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org Main Site |
45 | */ |
46 | class ClientEntity implements ClientEntityInterface |
47 | { |
48 | use EntityTrait; |
49 | use ClientTrait; |
50 | |
51 | /** |
52 | * Constructor |
53 | * |
54 | * @param array $config Client configuration |
55 | */ |
56 | public function __construct(array $config) |
57 | { |
58 | foreach (['identifier', 'name', 'redirectUri'] as $required) { |
59 | if (!isset($config[$required])) { |
60 | throw new BadConfigException( |
61 | "OAuth2 client config missing '$required'" |
62 | ); |
63 | } |
64 | } |
65 | $this->setIdentifier($config['identifier']); |
66 | $this->setName($config['name']); |
67 | $this->redirectUri = $config['redirectUri']; |
68 | $this->isConfidential = (bool)($config['isConfidential'] ?? false); |
69 | if (!$this->isConfidential && !empty($config['secret'])) { |
70 | throw new BadConfigException( |
71 | 'OAuth2 client config must not specify a secret for a' |
72 | . ' non-confidential client' |
73 | ); |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * Set the client's name. |
79 | * |
80 | * @param string $name Name |
81 | * |
82 | * @return void |
83 | */ |
84 | public function setName($name) |
85 | { |
86 | $this->name = $name; |
87 | } |
88 | } |