]> git.mxchange.org Git - friendica.git/blob - src/Security/OAuth1/Signature/OAuthSignatureMethod.php
version 2021.03-dev
[friendica.git] / src / Security / OAuth1 / Signature / OAuthSignatureMethod.php
1 <?php
2
3 namespace Friendica\Security\OAuth1\Signature;
4
5 use Friendica\Security\OAuth1\OAuthRequest;
6
7 /**
8  * A class for implementing a Signature Method
9  * See section 9 ("Signing Requests") in the spec
10  */
11 abstract class OAuthSignatureMethod
12 {
13         /**
14          * Needs to return the name of the Signature Method (ie HMAC-SHA1)
15          *
16          * @return string
17          */
18         abstract public function get_name();
19
20         /**
21          * Build up the signature
22          * NOTE: The output of this function MUST NOT be urlencoded.
23          * the encoding is handled in OAuthRequest when the final
24          * request is serialized
25          *
26          * @param OAuthRequest                             $request
27          * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
28          * @param \Friendica\Security\OAuth1\OAuthToken    $token
29          *
30          * @return string
31          */
32         abstract public function build_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, \Friendica\Security\OAuth1\OAuthToken $token = null);
33
34         /**
35          * Verifies that a given signature is correct
36          *
37          * @param OAuthRequest                             $request
38          * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
39          * @param \Friendica\Security\OAuth1\OAuthToken    $token
40          * @param string                                   $signature
41          *
42          * @return bool
43          */
44         public function check_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, $signature, \Friendica\Security\OAuth1\OAuthToken $token = null)
45         {
46                 $built = $this->build_signature($request, $consumer, $token);
47                 return ($built == $signature);
48         }
49 }