3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Security\OAuth1\Signature;
24 use Friendica\Security\OAuth1\OAuthRequest;
27 * A class for implementing a Signature Method
28 * See section 9 ("Signing Requests") in the spec
30 abstract class OAuthSignatureMethod
33 * Needs to return the name of the Signature Method (ie HMAC-SHA1)
37 abstract public function get_name();
40 * Build up the signature
41 * NOTE: The output of this function MUST NOT be urlencoded.
42 * the encoding is handled in OAuthRequest when the final
43 * request is serialized
45 * @param OAuthRequest $request
46 * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
47 * @param \Friendica\Security\OAuth1\OAuthToken $token
51 abstract public function build_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, \Friendica\Security\OAuth1\OAuthToken $token = null);
54 * Verifies that a given signature is correct
56 * @param OAuthRequest $request
57 * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
58 * @param \Friendica\Security\OAuth1\OAuthToken $token
59 * @param string $signature
63 public function check_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, $signature, \Friendica\Security\OAuth1\OAuthToken $token = null)
65 $built = $this->build_signature($request, $consumer, $token);
66 return ($built == $signature);