1 | <?php |
||
19 | class Authenticator |
||
20 | { |
||
21 | /** |
||
22 | * The application ID. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $appId; |
||
27 | |||
28 | /** |
||
29 | * The application secret. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $appSecret; |
||
34 | |||
35 | /** |
||
36 | * A storage to use to store data between requests. |
||
37 | * |
||
38 | * @var DataStorageInterface storage |
||
39 | */ |
||
40 | private $storage; |
||
41 | |||
42 | /** |
||
43 | * @var RequestManager |
||
44 | */ |
||
45 | private $requestManager; |
||
46 | |||
47 | /** |
||
48 | * @param RequestManager $requestManager |
||
49 | * @param string $appId |
||
50 | * @param string $appSecret |
||
51 | */ |
||
52 | public function __construct(RequestManager $requestManager, $appId, $appSecret) |
||
58 | |||
59 | /** |
||
60 | * Tries to get a new access token from data storage or code. If it fails, it will return null. |
||
61 | * |
||
62 | * @param LinkedInUrlGeneratorInterface $urlGenerator |
||
63 | * |
||
64 | * @return AccessToken|null A valid user access token, or null if one could not be fetched. |
||
65 | * |
||
66 | * @throws LinkedInException |
||
67 | */ |
||
68 | public function fetchNewAccessToken(LinkedInUrlGeneratorInterface $urlGenerator) |
||
95 | |||
96 | /** |
||
97 | * Retrieves an access token for the given authorization code |
||
98 | * (previously generated from www.linkedin.com on behalf of |
||
99 | * a specific user). The authorization code is sent to www.linkedin.com |
||
100 | * and a legitimate access token is generated provided the access token |
||
101 | * and the user for which it was generated all match, and the user is |
||
102 | * either logged in to LinkedIn or has granted an offline access permission. |
||
103 | * |
||
104 | * @param LinkedInUrlGeneratorInterface $urlGenerator |
||
105 | * @param string $code An authorization code. |
||
106 | * |
||
107 | * @return AccessToken An access token exchanged for the authorization code. |
||
108 | * |
||
109 | * @throws LinkedInException |
||
110 | */ |
||
111 | protected function getAccessTokenFromCode(LinkedInUrlGeneratorInterface $urlGenerator, $code) |
||
151 | |||
152 | /** |
||
153 | * Generate a login url. |
||
154 | * |
||
155 | * @param LinkedInUrlGeneratorInterface $urlGenerator |
||
156 | * @param array $options |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = array()) |
||
190 | |||
191 | /** |
||
192 | * Get the authorization code from the query parameters, if it exists, |
||
193 | * and otherwise return null to signal no authorization code was |
||
194 | * discovered. |
||
195 | * |
||
196 | * @return string|null The authorization code, or null if the authorization code not exists. |
||
197 | * |
||
198 | * @throws LinkedInException on invalid CSRF tokens |
||
199 | */ |
||
200 | protected function getCode() |
||
233 | |||
234 | /** |
||
235 | * Lays down a CSRF state token for this process. |
||
236 | */ |
||
237 | protected function establishCSRFTokenState() |
||
244 | |||
245 | /** |
||
246 | * Clear the storage. |
||
247 | * |
||
248 | * @return $this |
||
249 | */ |
||
250 | public function clearStorage() |
||
256 | |||
257 | /** |
||
258 | * @return DataStorageInterface |
||
259 | */ |
||
260 | protected function getStorage() |
||
268 | |||
269 | /** |
||
270 | * @param DataStorageInterface $storage |
||
271 | * |
||
272 | * @return $this |
||
273 | */ |
||
274 | public function setStorage(DataStorageInterface $storage) |
||
280 | |||
281 | /** |
||
282 | * @return RequestManager |
||
283 | */ |
||
284 | protected function getRequestManager() |
||
288 | } |
||
289 |