]> git.mxchange.org Git - friendica.git/blob - src/Security/OAuth1/Signature/OAuthSignatureMethod_PLAINTEXT.php
version 2021.03-dev
[friendica.git] / src / Security / OAuth1 / Signature / OAuthSignatureMethod_PLAINTEXT.php
1 <?php
2
3 namespace Friendica\Security\OAuth1\Signature;
4
5 use Friendica\Security\OAuth1\OAuthRequest;
6 use Friendica\Security\OAuth1\OAuthUtil;
7
8 /**
9  * The PLAINTEXT method does not provide any security protection and SHOULD only be used
10  * over a secure channel such as HTTPS. It does not use the Signature Base String.
11  *   - Chapter 9.4 ("PLAINTEXT")
12  */
13 class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod
14 {
15         public function get_name()
16         {
17                 return "PLAINTEXT";
18         }
19
20         /**
21          * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
22          * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
23          * empty. The result MUST be encoded again.
24          *   - Chapter 9.4.1 ("Generating Signatures")
25          *
26          * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
27          * OAuthRequest handles this!
28          *
29          * @param $request
30          * @param $consumer
31          * @param $token
32          *
33          * @return string
34          */
35         public function build_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, \Friendica\Security\OAuth1\OAuthToken $token = null)
36         {
37                 $key_parts = [
38                         $consumer->secret,
39                         ($token) ? $token->secret : "",
40                 ];
41
42                 $key_parts            = OAuthUtil::urlencode_rfc3986($key_parts);
43                 $key                  = implode('&', $key_parts);
44                 $request->base_string = $key;
45
46                 return $key;
47         }
48 }