PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / league / oauth2-client / src / Tool / MacAuthorizationTrait.php

MacAuthorizationTrait.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at vendor_prefixed/league/oauth2-client/src/Tool/MacAuthorizationTrait.php

77 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the league/oauth2-client library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Alex Bilbie <hello@alexbilbie.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 * @link http://thephpleague.com/oauth2-client/ Documentation
12 * @link https://packagist.org/packages/league/oauth2-client Packagist
13 * @link https://github.com/thephpleague/oauth2-client GitHub
14 */
15 namespace YoastSEO_Vendor\League\OAuth2\Client\Tool;
16
17 use YoastSEO_Vendor\League\OAuth2\Client\Token\AccessToken;
18 use YoastSEO_Vendor\League\OAuth2\Client\Token\AccessTokenInterface;
19 /**
20 * Enables `MAC` header authorization for providers.
21 *
22 * @link http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-05 Message Authentication Code (MAC) Tokens
23 */
24 trait MacAuthorizationTrait
25 {
26 /**
27 * Returns the id of this token for MAC generation.
28 *
29 * @param AccessToken $token
30 * @return string
31 */
32 protected abstract function getTokenId(\YoastSEO_Vendor\League\OAuth2\Client\Token\AccessToken $token);
33 /**
34 * Returns the MAC signature for the current request.
35 *
36 * @param string $id
37 * @param integer $ts
38 * @param string $nonce
39 * @return string
40 */
41 protected abstract function getMacSignature($id, $ts, $nonce);
42 /**
43 * Returns a new random string to use as the state parameter in an
44 * authorization flow.
45 *
46 * @param int $length Length of the random string to be generated.
47 * @return string
48 */
49 protected abstract function getRandomState($length = 32);
50 /**
51 * Returns the authorization headers for the 'mac' grant.
52 *
53 * @param AccessTokenInterface|string|null $token Either a string or an access token instance
54 * @return array
55 * @codeCoverageIgnore
56 *
57 * @todo This is currently untested and provided only as an example. If you
58 * complete the implementation, please create a pull request for
59 * https://github.com/thephpleague/oauth2-client
60 */
61 protected function getAuthorizationHeaders($token = null)
62 {
63 if ($token === null) {
64 return [];
65 }
66 $ts = \time();
67 $id = $this->getTokenId($token);
68 $nonce = $this->getRandomState(16);
69 $mac = $this->getMacSignature($id, $ts, $nonce);
70 $parts = [];
71 foreach (\compact('id', 'ts', 'nonce', 'mac') as $key => $value) {
72 $parts[] = \sprintf('%s="%s"', $key, $value);
73 }
74 return ['Authorization' => 'MAC ' . \implode(', ', $parts)];
75 }
76 }
77