Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
8 / 10 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| LisOauthDataStore | |
80.00% |
8 / 10 |
|
66.67% |
4 / 6 |
7.39 | |
0.00% |
0 / 1 |
| lookup_consumer | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| lookup_token | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lookup_nonce | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| new_request_token | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| new_access_token | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLtiProviderService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2019 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoLti\models\classes\Lis; |
| 22 | |
| 23 | use IMSGlobal\LTI\OAuth\OAuthException as LtiOAuthException; |
| 24 | use IMSGlobal\LTI\OAuth\OAuthToken; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\oatbox\service\exception\InvalidService; |
| 27 | use oat\oatbox\service\exception\InvalidServiceManagerException; |
| 28 | use oat\tao\model\oauth\ImsOauthDataStoreInterface; |
| 29 | use oat\tao\model\oauth\nonce\NonceStore; |
| 30 | use oat\taoLti\models\classes\LtiProvider\LtiProviderService; |
| 31 | |
| 32 | /** |
| 33 | * Implementation compatible with |
| 34 | * @see \IMSGlobal\LTI\OAuth\OAuthDataStore |
| 35 | * to be used in |
| 36 | * @see \IMSGlobal\LTI\OAuth\OAuthServer |
| 37 | * Retrieves consumers from LtiProviderService |
| 38 | */ |
| 39 | class LisOauthDataStore extends ConfigurableService implements ImsOauthDataStoreInterface |
| 40 | { |
| 41 | public const OPTION_NONCE_STORE = 'nonce_store'; |
| 42 | |
| 43 | /** |
| 44 | * @inheritDoc |
| 45 | * @throws LtiOAuthException |
| 46 | * |
| 47 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
| 48 | */ |
| 49 | public function lookup_consumer($consumer_key) |
| 50 | { |
| 51 | $provider = $this->getLtiProviderService()->searchByOauthKey($consumer_key); |
| 52 | if ($provider === null) { |
| 53 | throw new LtiOAuthException('LTI provider with given consumer key not found'); |
| 54 | } |
| 55 | return new LisOAuthConsumer($provider, $provider->getCallbackUrl()); |
| 56 | } |
| 57 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
| 58 | |
| 59 | /** |
| 60 | * @inheritDoc |
| 61 | * |
| 62 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
| 63 | */ |
| 64 | public function lookup_token($consumer, $token_type, $token) |
| 65 | { |
| 66 | return new OAuthToken($consumer, ''); |
| 67 | } |
| 68 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
| 69 | |
| 70 | /** |
| 71 | * @inheritDoc |
| 72 | * @throws InvalidService |
| 73 | * @throws InvalidServiceManagerException |
| 74 | * |
| 75 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
| 76 | */ |
| 77 | public function lookup_nonce($consumer, $token, $nonce, $timestamp) |
| 78 | { |
| 79 | /** @var NonceStore $store */ |
| 80 | $store = $this->getSubService(self::OPTION_NONCE_STORE, NonceStore::class); |
| 81 | return !$store->isValid($timestamp . '_' . $consumer->key . '_' . $nonce); |
| 82 | } |
| 83 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
| 84 | |
| 85 | /** |
| 86 | * @inheritDoc |
| 87 | * |
| 88 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
| 89 | */ |
| 90 | public function new_request_token($consumer, $callback = null) |
| 91 | { |
| 92 | return null; |
| 93 | } |
| 94 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
| 95 | |
| 96 | /** |
| 97 | * @inheritDoc |
| 98 | * |
| 99 | * phpcs:disable PSR1.Methods.CamelCapsMethodName |
| 100 | */ |
| 101 | public function new_access_token($token, $consumer, $verifier = null) |
| 102 | { |
| 103 | return null; |
| 104 | } |
| 105 | // phpcs:enable PSR1.Methods.CamelCapsMethodName |
| 106 | |
| 107 | /** |
| 108 | * @return LtiProviderService |
| 109 | */ |
| 110 | private function getLtiProviderService() |
| 111 | { |
| 112 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
| 113 | return $this->getServiceLocator()->get(LtiProviderService::SERVICE_ID); |
| 114 | } |
| 115 | } |