Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Plaintext | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
buildSignature | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @section LICENSE |
4 | * Copyright (c) 2007 Andy Smith |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining |
7 | * a copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including without |
9 | * limitation the rights to use, copy, modify, merge, publish, distribute, |
10 | * sublicense, and/or sell copies of the Software, and to permit persons to |
11 | * whom the Software is furnished to do so, subject to the following |
12 | * conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | * DEALINGS IN THE SOFTWARE. |
24 | * |
25 | * @file |
26 | */ |
27 | |
28 | namespace MediaWiki\OAuthClient\SignatureMethod; |
29 | |
30 | use MediaWiki\OAuthClient\Consumer; |
31 | use MediaWiki\OAuthClient\Request; |
32 | use MediaWiki\OAuthClient\SignatureMethod; |
33 | use MediaWiki\OAuthClient\Token; |
34 | use MediaWiki\OAuthClient\Util; |
35 | |
36 | /** |
37 | * The PLAINTEXT method does not provide any security protection and SHOULD |
38 | * only be used over a secure channel such as HTTPS. It does not use the |
39 | * Signature Base String. |
40 | * - Chapter 9.4 ("PLAINTEXT") |
41 | */ |
42 | class Plaintext extends SignatureMethod { |
43 | |
44 | /** |
45 | * @return string |
46 | */ |
47 | public function getName() { |
48 | return 'PLAINTEXT'; |
49 | } |
50 | |
51 | /** |
52 | * oauth_signature is set to the concatenated encoded values of the Consumer |
53 | * Secret and Token Secret, separated by a '&' character (ASCII code 38), |
54 | * even if either secret is empty. The result MUST be encoded again. |
55 | * - Chapter 9.4.1 ("Generating Signatures") |
56 | * |
57 | * Please note that the second encoding MUST NOT happen in the |
58 | * SignatureMethod, as Request handles this! |
59 | * @param Request $request |
60 | * @param Consumer $consumer |
61 | * @param Token|null $token |
62 | * @return string |
63 | */ |
64 | public function buildSignature( |
65 | Request $request, |
66 | Consumer $consumer, |
67 | Token $token = null |
68 | ) { |
69 | $key_parts = [ |
70 | $consumer->secret, |
71 | $token ? $token->secret : '' |
72 | ]; |
73 | |
74 | $key_parts = Util::urlencode( $key_parts ); |
75 | $key = implode( '&', $key_parts ); |
76 | $request->base_string = $key; |
77 | |
78 | return $key; |
79 | } |
80 | } |