1 | <?php namespace nyx\auth\id; |
||
19 | abstract class Provider implements interfaces\Provider |
||
20 | { |
||
21 | /** |
||
22 | * @var credentials\Client The credentials used to identify this consumer with the provider. |
||
23 | */ |
||
24 | protected $consumer; |
||
25 | |||
26 | /** |
||
27 | * @var bool Whether the Provider should attempt to retrieve the email address of an entity when performing |
||
28 | * identify calls. |
||
29 | * |
||
30 | * This is kept as a separate, publicly settable behavioural flag because many Providers make |
||
31 | * the entity's email address(es) available only with special permission scopes and/or at different |
||
32 | * endpoints, meaning simple identify() calls which do not rely on the email being available |
||
33 | * can in those cases be simplified by setting this flag to false. |
||
34 | * |
||
35 | * Some Identity Providers do not provide the entity's email address(es) under any circumstances, |
||
36 | * in which case this flag will have no effect. |
||
37 | */ |
||
38 | protected $shouldProvideEmailAddress = true; |
||
39 | |||
40 | /** |
||
41 | * @var \GuzzleHttp\ClientInterface The underlying HTTP Client used for communicating with the provider. |
||
42 | */ |
||
43 | protected $httpClient; |
||
44 | |||
45 | /** |
||
46 | * Constructs a new Identity Provider instance tied to the given client/consumer/application Credentials. |
||
47 | * |
||
48 | * @param credentials\Client $consumer |
||
49 | */ |
||
50 | public function __construct(credentials\Client $consumer) |
||
54 | |||
55 | /** |
||
56 | * {@inheritDoc} |
||
57 | */ |
||
58 | public function getAuthorizeUrl(array $parameters = []) : string |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | public function getExchangeUrl() : string |
||
70 | |||
71 | /** |
||
72 | * {@inheritDoc} |
||
73 | */ |
||
74 | public function getIdentifyUrl() : string |
||
78 | |||
79 | /** |
||
80 | * Checks whether the Provider should attempt to retrieve the email address of an entity when performing |
||
81 | * identify requests. |
||
82 | * |
||
83 | * @see $shouldProvideEmailAddress |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function shouldProvideEmailAddress() : bool |
||
90 | |||
91 | /** |
||
92 | * Sets whether the Provider should attempt to retrieve the email address of an entity when performing |
||
93 | * identify requests. |
||
94 | * |
||
95 | * @param bool $bool |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setShouldProvideEmailAddress(bool $bool) : Provider |
||
104 | |||
105 | /** |
||
106 | * {@inheritDoc} |
||
107 | */ |
||
108 | public function request(string $method, string $url, auth\interfaces\Token $token = null, array $options = []) : Promise |
||
118 | |||
119 | /** |
||
120 | * Success callback for self::request(). |
||
121 | * |
||
122 | * Note: Some Providers may return valid HTTP response codes for requests that were actually unsuccessful |
||
123 | * and instead provide arbitrary responses like "ok => false" or "errors => []". Those misbehaving cases should |
||
124 | * be caught within specific Providers. |
||
125 | * |
||
126 | * @param Response $response The Response received to the Request made. |
||
127 | * @param auth\interfaces\Token $token The Token that was used to authorize the Request, if applicable. |
||
128 | * @return mixed |
||
129 | */ |
||
130 | protected function onRequestSuccess(Response $response, auth\interfaces\Token $token = null) |
||
134 | |||
135 | /** |
||
136 | * Failure callback for self::request(). |
||
137 | * |
||
138 | * @param \Exception $exception The Exception that occurred during the Request. |
||
139 | * @param auth\interfaces\Token $token The Token that was used to authorize the Request, if applicable. |
||
140 | * @throws \Exception Always re-throws the Exception. Child classes may, however, provide |
||
141 | * recovery paths. |
||
142 | * @return mixed |
||
143 | */ |
||
144 | protected function onRequestError(\Exception $exception, auth\interfaces\Token $token = null) |
||
148 | |||
149 | /** |
||
150 | * Returns the default options (in a format recognized by Guzzle) for requests made by this Provider. |
||
151 | * |
||
152 | * @param auth\interfaces\Token $token The Token that should be used to authorize the Request. |
||
153 | * @return array |
||
154 | */ |
||
155 | protected function getDefaultRequestOptions(auth\interfaces\Token $token = null) : array |
||
163 | |||
164 | /** |
||
165 | * Builds an URL string from the given base URL and optional additional query parameters. |
||
166 | * |
||
167 | * @param string $base The base URL. |
||
168 | * @param array $query Additional query parameters. |
||
169 | * @return string |
||
170 | */ |
||
171 | protected function buildUrl(string $base, array $query = []) : string |
||
175 | |||
176 | /** |
||
177 | * Returns the underlying HTTP Client used for communicating with the provider. Lazily instantiates |
||
178 | * a HTTP Client if none is set yet. |
||
179 | * |
||
180 | * @return \GuzzleHttp\ClientInterface |
||
181 | */ |
||
182 | protected function getHttpClient() : \GuzzleHttp\ClientInterface |
||
186 | |||
187 | /** |
||
188 | * Sets the underlying HTTP Client used for communicating with the provider. |
||
189 | * |
||
190 | * @param \GuzzleHttp\ClientInterface $client |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function setHttpClient(\GuzzleHttp\ClientInterface $client) : Provider |
||
199 | |||
200 | /** |
||
201 | * Creates an Identity instance of a type specific to the Provider, using a Token and raw data also |
||
202 | * specific to the Provider. |
||
203 | * |
||
204 | * @param auth\interfaces\Token $token The Token that had been used to retrieve the data about the entity. |
||
205 | * @param array $data The raw data about the entity given by the Provider. |
||
206 | * @return interfaces\Identity The resulting Identity instance. |
||
207 | */ |
||
208 | protected function createIdentity(auth\interfaces\Token $token, array $data) : interfaces\Identity |
||
214 | } |
||
215 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.