1 | <?php |
||
18 | class Yahoo extends \SocialConnect\OAuth2\AbstractProvider |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | 3 | public function getBaseUri() |
|
24 | { |
||
25 | 3 | return 'https://social.yahooapis.com/v1/'; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 2 | public function getAuthorizeUri() |
|
32 | { |
||
33 | 2 | return 'https://api.login.yahoo.com/oauth2/request_auth'; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 2 | public function getRequestTokenUri() |
|
40 | { |
||
41 | 2 | return 'https://api.login.yahoo.com/oauth2/get_token'; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 3 | public function getName() |
|
48 | { |
||
49 | 3 | return 'yahoo'; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 3 | public function parseToken($body) |
|
56 | { |
||
57 | 3 | $result = json_decode($body, true); |
|
58 | 3 | if ($result) { |
|
59 | 1 | return new AccessToken($result); |
|
60 | } |
||
61 | |||
62 | 2 | throw new InvalidAccessToken('AccessToken is not a valid JSON'); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Retreive userId |
||
67 | */ |
||
68 | 2 | private function getCurrentUserId(AccessTokenInterface $accessToken) |
|
69 | { |
||
70 | 2 | $parameters = []; |
|
71 | 2 | $parameters['format'] = 'json'; |
|
72 | 2 | $response = $this->httpClient->request( |
|
73 | 2 | $this->getBaseUri() . 'me/guid', |
|
74 | 2 | $parameters, |
|
75 | 2 | Client::GET, |
|
76 | [ |
||
77 | 2 | 'Authorization' => 'Bearer ' . $accessToken->getToken(), |
|
78 | ] |
||
79 | 2 | ); |
|
80 | 2 | if (!$response->isSuccess()) { |
|
81 | 1 | throw new InvalidResponse( |
|
82 | 1 | 'API (get guid) response with error code', |
|
83 | $response |
||
84 | 1 | ); |
|
85 | } |
||
86 | |||
87 | 1 | $result = $response->json(); |
|
88 | |||
89 | 1 | if (!$result) { |
|
90 | 1 | throw new InvalidResponse( |
|
91 | 1 | 'API response is not a valid JSON object', |
|
92 | $response |
||
93 | 1 | ); |
|
94 | } |
||
95 | |||
96 | return $result->guid->value; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 2 | public function getIdentity(AccessTokenInterface $accessToken) |
|
167 | } |
||
168 |