1 | <?php namespace nyx\auth\id\protocols\oauth2; |
||
21 | abstract class Provider extends auth\id\Provider implements interfaces\Provider |
||
22 | { |
||
23 | /** |
||
24 | * The character separating different scopes in the request. |
||
25 | */ |
||
26 | const SCOPE_SEPARATOR = ','; |
||
27 | |||
28 | /** |
||
29 | * @var array The default access scopes to be requested during the authorization step. |
||
30 | */ |
||
31 | protected $defaultScopes = []; |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | public function authorize(callable $redirect, array $parameters = []) |
||
57 | |||
58 | /** |
||
59 | * Exchanges the given authorization code grant for an Access Token. |
||
60 | * |
||
61 | * @param string $code The authorization code to exchange. |
||
62 | * @return Promise A Promise for an Access Token. |
||
63 | */ |
||
64 | public function exchange(string $code) : Promise |
||
78 | |||
79 | /** |
||
80 | * {@inheritDoc} |
||
81 | */ |
||
82 | public function identify(oauth2\Token $token) : Promise |
||
88 | |||
89 | /** |
||
90 | * {@inheritDoc} |
||
91 | * |
||
92 | * @param oauth2\Token $token |
||
93 | */ |
||
94 | public function request(string $method, string $url, auth\interfaces\Token $token = null, array $options = []) : Promise |
||
104 | |||
105 | /** |
||
106 | * Success callback for self::request(). |
||
107 | * |
||
108 | * Note: Some Providers may return valid HTTP response codes for requests that were actually unsuccessful |
||
109 | * and instead provide arbitrary responses like "ok => false" or "errors => []". Those misbehaving cases should |
||
110 | * be caught within specific Providers. |
||
111 | * |
||
112 | * @param Response $response The Response received to the Request made. |
||
113 | * @param auth\interfaces\Token $token The Access Token that was used to authorize the Request, if applicable. |
||
114 | * @return mixed |
||
115 | */ |
||
116 | protected function onRequestSuccess(Response $response, auth\interfaces\Token $token = null) |
||
120 | |||
121 | /** |
||
122 | * Failure callback for self::request(). |
||
123 | * |
||
124 | * @param \Exception $exception The Exception that occurred during the Request. |
||
125 | * @param auth\interfaces\Token $token The Access Token that was used to authorize the Request, if applicable. |
||
126 | * @throws \Exception Always re-throws the Exception. Child classes may, however, provide |
||
127 | * recovery paths. |
||
128 | * @return mixed |
||
129 | */ |
||
130 | protected function onRequestError(\Exception $exception, auth\interfaces\Token $token = null) |
||
134 | |||
135 | /** |
||
136 | * Returns the default options (in a format recognized by Guzzle) for requests made by this Provider. |
||
137 | * |
||
138 | * @param auth\interfaces\Token $token The Access Token that should be used to authorize the Request. |
||
139 | * @return array |
||
140 | */ |
||
141 | protected function getDefaultRequestOptions(auth\interfaces\Token $token = null) : array |
||
156 | |||
157 | /** |
||
158 | * Creates an OAuth 2.0 Access Token instance based on raw response data. |
||
159 | * |
||
160 | * @param array $data The raw (response) data to base on. |
||
161 | * @return oauth2\Token The resulting OAuth 2.0 Access Token instance. |
||
162 | * @throws \RuntimeException When the data did not contain an access token in a recognized format. |
||
163 | */ |
||
164 | protected function createToken(array $data) : oauth2\Token |
||
191 | |||
192 | /** |
||
193 | * Creates an Identity instance of a type specific to the Provider, using an Access Token and raw data also |
||
194 | * specific to the Provider. |
||
195 | * |
||
196 | * @param oauth2\Token $token The Access Token that had been used to retrieve information about the entity. |
||
197 | * @param array $data The raw data about the entity given by the Provider. |
||
198 | * @return oauth2\Identity The resulting OAuth 2.0 Identity instance. |
||
199 | */ |
||
200 | protected function createIdentity(oauth2\Token $token, array $data) : oauth2\Identity |
||
206 | } |
||
207 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.