wordpress-seo
/
vendor_prefixed
/
league
/
oauth2-client
/
src
/
OptionProvider
/
HttpBasicAuthOptionProvider.php
HttpBasicAuthOptionProvider.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at vendor_prefixed/league/oauth2-client/src/OptionProvider/HttpBasicAuthOptionProvider.php
| 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\OptionProvider; |
| 16 | |
| 17 | use InvalidArgumentException; |
| 18 | /** |
| 19 | * Add http basic auth into access token request options |
| 20 | * @link https://tools.ietf.org/html/rfc6749#section-2.3.1 |
| 21 | */ |
| 22 | class HttpBasicAuthOptionProvider extends \YoastSEO_Vendor\League\OAuth2\Client\OptionProvider\PostAuthOptionProvider |
| 23 | { |
| 24 | /** |
| 25 | * @inheritdoc |
| 26 | */ |
| 27 | public function getAccessTokenOptions($method, array $params) |
| 28 | { |
| 29 | if (empty($params['client_id']) || empty($params['client_secret'])) { |
| 30 | throw new \InvalidArgumentException('clientId and clientSecret are required for http basic auth'); |
| 31 | } |
| 32 | $encodedCredentials = \base64_encode(\sprintf('%s:%s', $params['client_id'], $params['client_secret'])); |
| 33 | unset($params['client_id'], $params['client_secret']); |
| 34 | $options = parent::getAccessTokenOptions($method, $params); |
| 35 | $options['headers']['Authorization'] = 'Basic ' . $encodedCredentials; |
| 36 | return $options; |
| 37 | } |
| 38 | } |
| 39 |