Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
45.45% |
5 / 11 |
|
28.57% |
2 / 7 |
CRAP | |
0.00% |
0 / 1 |
| BasicType | |
45.45% |
5 / 11 |
|
28.57% |
2 / 7 |
14.95 | |
0.00% |
0 / 1 |
| call | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getTemplate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAuthProperties | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAuthClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getClient | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getInstance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setInstance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * @author Alexander Zagovorichev <olexander.zagovorychev@1pt.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\model\auth; |
| 24 | |
| 25 | use GuzzleHttp\Client; |
| 26 | use oat\tao\helpers\Template; |
| 27 | use Prophecy\Exception\Doubler\MethodNotFoundException; |
| 28 | use Psr\Http\Message\RequestInterface; |
| 29 | |
| 30 | class BasicType extends AbstractAuthType |
| 31 | { |
| 32 | /** |
| 33 | * Call a request through basic client |
| 34 | * |
| 35 | * @param RequestInterface $request |
| 36 | * @param array $clientOptions Http client options |
| 37 | * @return mixed|\Psr\Http\Message\ResponseInterface |
| 38 | * @throws \GuzzleHttp\Exception\GuzzleException |
| 39 | * @throws \common_exception_InvalidArgumentType |
| 40 | */ |
| 41 | public function call(RequestInterface $request, array $clientOptions = []) |
| 42 | { |
| 43 | return $this->getClient($clientOptions)->send( |
| 44 | $request, |
| 45 | ['auth' => array_values($this->getCredentials()), 'verify' => false] |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns template for the current instance (or empty template for the default authorization) with credentials |
| 51 | * |
| 52 | * @return string |
| 53 | * @throws \common_exception_InvalidArgumentType |
| 54 | */ |
| 55 | public function getTemplate() |
| 56 | { |
| 57 | $data = $this->getCredentials(); |
| 58 | return Template::inc('auth/basicAuthForm.tpl', 'tao', $data); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return array|void |
| 63 | */ |
| 64 | public function getAuthProperties() |
| 65 | { |
| 66 | $this->getCredentials(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @param array $clientOptions |
| 71 | * @return \core_kernel_classes_Class|AbstractCredentials|BasicAuthCredentials |
| 72 | * @throws \common_exception_ValidationFailed |
| 73 | */ |
| 74 | public function getAuthClass($clientOptions = []) |
| 75 | { |
| 76 | return new BasicAuthCredentials($clientOptions); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @param $clientOptions |
| 81 | * @return mixed |
| 82 | */ |
| 83 | protected function getClient($clientOptions = []) |
| 84 | { |
| 85 | return new Client($clientOptions); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return \core_kernel_classes_Resource|void |
| 90 | */ |
| 91 | public function getInstance() |
| 92 | { |
| 93 | throw new MethodNotFoundException('getInstance method was deprecated', __CLASS__, __METHOD__); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param \core_kernel_classes_Resource|null $instance |
| 98 | */ |
| 99 | public function setInstance(\core_kernel_classes_Resource $instance = null) |
| 100 | { |
| 101 | throw new MethodNotFoundException('setInstance method was deprecated', __CLASS__, __METHOD__); |
| 102 | } |
| 103 | } |