Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| LisSignatureValidator | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| validate | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoLti\models\classes\Lis; |
| 24 | |
| 25 | use common_http_InvalidSignatureException; |
| 26 | use IMSGlobal\LTI\OAuth\OAuthConsumer; |
| 27 | use IMSGlobal\LTI\OAuth\OAuthRequest; |
| 28 | use IMSGlobal\LTI\OAuth\OAuthSignatureMethod_HMAC_SHA1; |
| 29 | |
| 30 | class LisSignatureValidator |
| 31 | { |
| 32 | /** |
| 33 | * @param OAuthRequest $oauthRequest |
| 34 | * @param OAuthConsumer $oauthConsumer |
| 35 | * @param string $method |
| 36 | * @param string $url |
| 37 | * |
| 38 | * @return array |
| 39 | * @throws common_http_InvalidSignatureException |
| 40 | */ |
| 41 | public function validate(OAuthRequest $oauthRequest, OAuthConsumer $oauthConsumer, $method, $url) |
| 42 | { |
| 43 | $hmacMethod = new OAuthSignatureMethod_HMAC_SHA1(); |
| 44 | |
| 45 | $oauthReq = OAuthRequest::from_consumer_and_token( |
| 46 | $oauthConsumer, |
| 47 | null, |
| 48 | $method, |
| 49 | $url, |
| 50 | $oauthRequest->get_parameters() |
| 51 | ); |
| 52 | |
| 53 | $oauthReq->sign_request($hmacMethod, $oauthConsumer, null); |
| 54 | |
| 55 | if ($oauthRequest->get_parameter('oauth_signature') !== $oauthReq->get_parameter('oauth_signature')) { |
| 56 | throw new common_http_InvalidSignatureException('Invalid signature.'); |
| 57 | } |
| 58 | |
| 59 | return $oauthReq->get_parameters(); |
| 60 | } |
| 61 | } |