Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OAuth1Consumer | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
authorize | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
getOAuthVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\OAuth\Backend; |
4 | |
5 | use MediaWiki\User\User; |
6 | use MWCryptRand; |
7 | |
8 | /** |
9 | * (c) Dejan Savuljesku 2019, GPL |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License along |
22 | * with this program; if not, write to the Free Software Foundation, Inc., |
23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
24 | * http://www.gnu.org/copyleft/gpl.html |
25 | */ |
26 | |
27 | /** |
28 | * This class mainly exists to enable clean separation |
29 | * of OAuth 1.0a and OAuth 2.0 code |
30 | * |
31 | * Representation of an OAuth 1.0a consumer. |
32 | */ |
33 | class OAuth1Consumer extends Consumer { |
34 | |
35 | /** |
36 | * The user has authorized the request by this consumer, with this request token. Update |
37 | * everything so that the consumer can swap the request token for an access token. Then |
38 | * generate the callback URL where we will redirect our user back to the consumer. |
39 | * |
40 | * @param User $mwUser |
41 | * @param bool $update |
42 | * @param array $grants |
43 | * @param string|null $requestTokenKey |
44 | * @return string |
45 | * @throws MWOAuthException |
46 | */ |
47 | public function authorize( User $mwUser, $update, $grants, $requestTokenKey = null ) { |
48 | $this->conductAuthorizationChecks( $mwUser ); |
49 | |
50 | // Generate and Update the tokens: |
51 | // * Generate a new Verification code, and add it to the request token |
52 | // * Either add or update the authorization |
53 | // ** Generate a new access token if this is a new authorization |
54 | // * Resave request token with the access token |
55 | $verifyCode = MWCryptRand::generateHex( 32 ); |
56 | $store = Utils::newMWOAuthDataStore(); |
57 | $requestToken = $store->lookup_token( $this, 'request', $requestTokenKey ); |
58 | if ( !$requestToken || !( $requestToken instanceof MWOAuthToken ) ) { |
59 | throw new MWOAuthException( 'mwoauthserver-invalid-request-token', [ |
60 | 'consumer' => $this->getConsumerKey(), |
61 | 'consumer_name' => $this->getName(), |
62 | 'token_key' => $requestTokenKey, |
63 | ] ); |
64 | } |
65 | $requestToken->addVerifyCode( $verifyCode ); |
66 | |
67 | $cmra = $this->saveAuthorization( $mwUser, $update, $grants ); |
68 | $accessToken = new MWOAuthToken( $cmra->getAccessToken(), '' ); |
69 | |
70 | $requestToken->addAccessKey( $accessToken->key ); |
71 | $store->updateRequestToken( $requestToken, $this ); |
72 | return $this->generateCallbackUrl( |
73 | $store, $requestToken->getVerifyCode(), $requestTokenKey |
74 | ); |
75 | } |
76 | |
77 | /** |
78 | * @return int |
79 | */ |
80 | public function getOAuthVersion() { |
81 | return static::OAUTH_VERSION_1; |
82 | } |
83 | } |