| 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 <[email protected]> |
| 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\Grant; |
| 16 |
|
| 17 |
use YoastSEO_Vendor\League\OAuth2\Client\Tool\RequiredParameterTrait; |
| 18 |
/** |
| 19 |
* Represents a type of authorization grant. |
| 20 |
* |
| 21 |
* An authorization grant is a credential representing the resource |
| 22 |
* owner's authorization (to access its protected resources) used by the |
| 23 |
* client to obtain an access token. OAuth 2.0 defines four |
| 24 |
* grant types -- authorization code, implicit, resource owner password |
| 25 |
* credentials, and client credentials -- as well as an extensibility |
| 26 |
* mechanism for defining additional types. |
| 27 |
* |
| 28 |
* @link http://tools.ietf.org/html/rfc6749#section-1.3 Authorization Grant (RFC 6749, §1.3) |
| 29 |
*/ |
| 30 |
abstract class AbstractGrant |
| 31 |
{ |
| 32 |
use RequiredParameterTrait; |
| 33 |
/** |
| 34 |
* Returns the name of this grant, eg. 'grant_name', which is used as the |
| 35 |
* grant type when encoding URL query parameters. |
| 36 |
* |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
protected abstract function getName(); |
| 40 |
/** |
| 41 |
* Returns a list of all required request parameters. |
| 42 |
* |
| 43 |
* @return array |
| 44 |
*/ |
| 45 |
protected abstract function getRequiredRequestParameters(); |
| 46 |
/** |
| 47 |
* Returns this grant's name as its string representation. This allows for |
| 48 |
* string interpolation when building URL query parameters. |
| 49 |
* |
| 50 |
* @return string |
| 51 |
*/ |
| 52 |
public function __toString() |
| 53 |
{ |
| 54 |
return $this->getName(); |
| 55 |
} |
| 56 |
/** |
| 57 |
* Prepares an access token request's parameters by checking that all |
| 58 |
* required parameters are set, then merging with any given defaults. |
| 59 |
* |
| 60 |
* @param array $defaults |
| 61 |
* @param array $options |
| 62 |
* @return array |
| 63 |
*/ |
| 64 |
public function prepareRequestParameters(array $defaults, array $options) |
| 65 |
{ |
| 66 |
$defaults['grant_type'] = $this->getName(); |
| 67 |
$required = $this->getRequiredRequestParameters(); |
| 68 |
$provided = \array_merge($defaults, $options); |
| 69 |
$this->checkRequiredParameters($required, $provided); |
| 70 |
return $provided; |
| 71 |
} |
| 72 |
} |
| 73 |
|