Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiSecurePollAuth | |
0.00% |
0 / 33 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getAllowedParams | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
mustBePosted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isInternal | |
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 modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
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 along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | */ |
21 | |
22 | namespace MediaWiki\Extension\SecurePoll\Api; |
23 | |
24 | use ApiBase; |
25 | use ApiMain; |
26 | use MediaWiki\Extension\SecurePoll\Context; |
27 | use MediaWiki\Extension\SecurePoll\User\LocalAuth; |
28 | use MediaWiki\Extension\SecurePoll\User\RemoteMWAuth; |
29 | use MediaWiki\User\UserFactory; |
30 | use Wikimedia\ParamValidator\ParamValidator; |
31 | |
32 | /** |
33 | * API module to authenticate jump-wiki user. |
34 | * |
35 | * @ingroup API |
36 | */ |
37 | class ApiSecurePollAuth extends ApiBase { |
38 | /** @var UserFactory */ |
39 | private $userFactory; |
40 | |
41 | public function __construct( |
42 | ApiMain $mainModule, |
43 | $moduleName, |
44 | UserFactory $userFactory |
45 | ) { |
46 | parent::__construct( $mainModule, $moduleName ); |
47 | $this->userFactory = $userFactory; |
48 | } |
49 | |
50 | public function execute() { |
51 | $params = $this->extractRequestParams(); |
52 | |
53 | $user = $this->userFactory->newFromId( $params['id'] ); |
54 | if ( !$user->isRegistered() ) { |
55 | $this->dieWithError( |
56 | 'securepoll-api-no-user' |
57 | ); |
58 | } |
59 | $token = RemoteMWAuth::encodeToken( $user->getToken() ); |
60 | if ( !hash_equals( $params['token'], $token ) ) { |
61 | $this->dieWithError( |
62 | 'securepoll-api-token-mismatch' |
63 | ); |
64 | } |
65 | |
66 | $context = new Context(); |
67 | /** @var LocalAuth $auth */ |
68 | $auth = $context->newAuth( 'local' ); |
69 | $result = $auth->getUserParams( $user ); |
70 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
71 | } |
72 | |
73 | public function getAllowedParams() { |
74 | return [ |
75 | 'token' => [ |
76 | ParamValidator::PARAM_TYPE => 'string', |
77 | ParamValidator::PARAM_REQUIRED => true, |
78 | ], |
79 | 'id' => [ |
80 | ParamValidator::PARAM_TYPE => 'integer', |
81 | ParamValidator::PARAM_REQUIRED => true, |
82 | ], |
83 | ]; |
84 | } |
85 | |
86 | protected function getExamplesMessages() { |
87 | return [ |
88 | 'action=securepollauth&token=123ABC&id=1&format=json' => |
89 | 'apihelp-securepollauth-example-auth', |
90 | ]; |
91 | } |
92 | |
93 | public function mustBePosted() { |
94 | return true; |
95 | } |
96 | |
97 | public function isInternal() { |
98 | return true; |
99 | } |
100 | } |