PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
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 / Provider / GenericProvider.php

GenericProvider.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at vendor_prefixed/league/oauth2-client/src/Provider/GenericProvider.php

191 lines 5.5 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\Provider;
16
17 use InvalidArgumentException;
18 use YoastSEO_Vendor\League\OAuth2\Client\Provider\Exception\IdentityProviderException;
19 use YoastSEO_Vendor\League\OAuth2\Client\Token\AccessToken;
20 use YoastSEO_Vendor\League\OAuth2\Client\Tool\BearerAuthorizationTrait;
21 use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
22 /**
23 * Represents a generic service provider that may be used to interact with any
24 * OAuth 2.0 service provider, using Bearer token authentication.
25 */
26 class GenericProvider extends \YoastSEO_Vendor\League\OAuth2\Client\Provider\AbstractProvider
27 {
28 use BearerAuthorizationTrait;
29 /**
30 * @var string
31 */
32 private $urlAuthorize;
33 /**
34 * @var string
35 */
36 private $urlAccessToken;
37 /**
38 * @var string
39 */
40 private $urlResourceOwnerDetails;
41 /**
42 * @var string
43 */
44 private $accessTokenMethod;
45 /**
46 * @var string
47 */
48 private $accessTokenResourceOwnerId;
49 /**
50 * @var array|null
51 */
52 private $scopes = null;
53 /**
54 * @var string
55 */
56 private $scopeSeparator;
57 /**
58 * @var string
59 */
60 private $responseError = 'error';
61 /**
62 * @var string
63 */
64 private $responseCode;
65 /**
66 * @var string
67 */
68 private $responseResourceOwnerId = 'id';
69 /**
70 * @param array $options
71 * @param array $collaborators
72 */
73 public function __construct(array $options = [], array $collaborators = [])
74 {
75 $this->assertRequiredOptions($options);
76 $possible = $this->getConfigurableOptions();
77 $configured = \array_intersect_key($options, \array_flip($possible));
78 foreach ($configured as $key => $value) {
79 $this->{$key} = $value;
80 }
81 // Remove all options that are only used locally
82 $options = \array_diff_key($options, $configured);
83 parent::__construct($options, $collaborators);
84 }
85 /**
86 * Returns all options that can be configured.
87 *
88 * @return array
89 */
90 protected function getConfigurableOptions()
91 {
92 return \array_merge($this->getRequiredOptions(), ['accessTokenMethod', 'accessTokenResourceOwnerId', 'scopeSeparator', 'responseError', 'responseCode', 'responseResourceOwnerId', 'scopes']);
93 }
94 /**
95 * Returns all options that are required.
96 *
97 * @return array
98 */
99 protected function getRequiredOptions()
100 {
101 return ['urlAuthorize', 'urlAccessToken', 'urlResourceOwnerDetails'];
102 }
103 /**
104 * Verifies that all required options have been passed.
105 *
106 * @param array $options
107 * @return void
108 * @throws InvalidArgumentException
109 */
110 private function assertRequiredOptions(array $options)
111 {
112 $missing = \array_diff_key(\array_flip($this->getRequiredOptions()), $options);
113 if (!empty($missing)) {
114 throw new \InvalidArgumentException('Required options not defined: ' . \implode(', ', \array_keys($missing)));
115 }
116 }
117 /**
118 * @inheritdoc
119 */
120 public function getBaseAuthorizationUrl()
121 {
122 return $this->urlAuthorize;
123 }
124 /**
125 * @inheritdoc
126 */
127 public function getBaseAccessTokenUrl(array $params)
128 {
129 return $this->urlAccessToken;
130 }
131 /**
132 * @inheritdoc
133 */
134 public function getResourceOwnerDetailsUrl(\YoastSEO_Vendor\League\OAuth2\Client\Token\AccessToken $token)
135 {
136 return $this->urlResourceOwnerDetails;
137 }
138 /**
139 * @inheritdoc
140 */
141 public function getDefaultScopes()
142 {
143 return $this->scopes;
144 }
145 /**
146 * @inheritdoc
147 */
148 protected function getAccessTokenMethod()
149 {
150 return $this->accessTokenMethod ?: parent::getAccessTokenMethod();
151 }
152 /**
153 * @inheritdoc
154 */
155 protected function getAccessTokenResourceOwnerId()
156 {
157 return $this->accessTokenResourceOwnerId ?: parent::getAccessTokenResourceOwnerId();
158 }
159 /**
160 * @inheritdoc
161 */
162 protected function getScopeSeparator()
163 {
164 return $this->scopeSeparator ?: parent::getScopeSeparator();
165 }
166 /**
167 * @inheritdoc
168 */
169 protected function checkResponse(\YoastSEO_Vendor\Psr\Http\Message\ResponseInterface $response, $data)
170 {
171 if (!empty($data[$this->responseError])) {
172 $error = $data[$this->responseError];
173 if (!\is_string($error)) {
174 $error = \var_export($error, \true);
175 }
176 $code = $this->responseCode && !empty($data[$this->responseCode]) ? $data[$this->responseCode] : 0;
177 if (!\is_int($code)) {
178 $code = \intval($code);
179 }
180 throw new \YoastSEO_Vendor\League\OAuth2\Client\Provider\Exception\IdentityProviderException($error, $code, $data);
181 }
182 }
183 /**
184 * @inheritdoc
185 */
186 protected function createResourceOwner(array $response, \YoastSEO_Vendor\League\OAuth2\Client\Token\AccessToken $token)
187 {
188 return new \YoastSEO_Vendor\League\OAuth2\Client\Provider\GenericResourceOwner($response, $this->responseResourceOwnerId);
189 }
190 }
191