Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
RefreshTokenRepository | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
getNewRefreshToken | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
persistNewRefreshToken | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
revokeRefreshToken | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isRefreshTokenRevoked | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * OAuth2 refresh token repository implementation. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2022-2024. |
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\RefreshTokenEntityInterface; |
33 | use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; |
34 | use VuFind\Auth\InvalidArgumentException; |
35 | use VuFind\Db\Service\AccessTokenServiceInterface; |
36 | use VuFind\Db\Service\UserServiceInterface; |
37 | use VuFind\OAuth2\Entity\RefreshTokenEntity; |
38 | |
39 | /** |
40 | * OAuth2 refresh token repository implementation. |
41 | * |
42 | * @category VuFind |
43 | * @package OAuth2 |
44 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
45 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
46 | * @link https://vufind.org Main Site |
47 | */ |
48 | class RefreshTokenRepository extends AbstractTokenRepository implements RefreshTokenRepositoryInterface |
49 | { |
50 | /** |
51 | * Constructor |
52 | * |
53 | * @param array $oauth2Config OAuth2 configuration |
54 | * @param AccessTokenServiceInterface $accessTokenService Access token service |
55 | * @param UserServiceInterface $userService User service |
56 | */ |
57 | public function __construct( |
58 | array $oauth2Config, |
59 | AccessTokenServiceInterface $accessTokenService, |
60 | UserServiceInterface $userService |
61 | ) { |
62 | parent::__construct( |
63 | 'oauth2_refresh_token', |
64 | RefreshTokenEntity::class, |
65 | $oauth2Config, |
66 | $accessTokenService, |
67 | $userService |
68 | ); |
69 | } |
70 | |
71 | /** |
72 | * Create a new refresh token |
73 | * |
74 | * @return RefreshTokenEntityInterface |
75 | */ |
76 | public function getNewRefreshToken() |
77 | { |
78 | return $this->getNew(); |
79 | } |
80 | |
81 | /** |
82 | * Persists a new refresh token to permanent storage. |
83 | * |
84 | * @param RefreshTokenEntityInterface $entity Refresh token entity |
85 | * |
86 | * @return void |
87 | * |
88 | * @throws InvalidArgumentException |
89 | */ |
90 | public function persistNewRefreshToken(RefreshTokenEntityInterface $entity) |
91 | { |
92 | $this->persistNew($entity); |
93 | } |
94 | |
95 | /** |
96 | * Revoke a refresh token. |
97 | * |
98 | * @param string $tokenId Token ID |
99 | * |
100 | * @return void |
101 | */ |
102 | public function revokeRefreshToken($tokenId) |
103 | { |
104 | $this->revoke($tokenId); |
105 | } |
106 | |
107 | /** |
108 | * Check if the refresh token has been revoked. |
109 | * |
110 | * @param string $tokenId Token ID |
111 | * |
112 | * @return bool Return true if this token has been revoked |
113 | */ |
114 | public function isRefreshTokenRevoked($tokenId) |
115 | { |
116 | return $this->isRevoked($tokenId); |
117 | } |
118 | } |