|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace SocialConnect\OAuth1\Provider; |
|
9
|
|
|
|
|
10
|
|
|
use SocialConnect\Common\ArrayHydrator; |
|
11
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
|
12
|
|
|
use SocialConnect\Common\Entity\User; |
|
13
|
|
|
|
|
14
|
|
|
class Twitter extends \SocialConnect\OAuth1\AbstractProvider |
|
15
|
|
|
{ |
|
16
|
|
|
const NAME = 'twitter'; |
|
17
|
|
|
|
|
18
|
2 |
|
public function getBaseUri() |
|
19
|
|
|
{ |
|
20
|
2 |
|
return 'https://api.twitter.com/1.1/'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
public function getAuthorizeUri() |
|
24
|
|
|
{ |
|
25
|
1 |
|
return 'https://api.twitter.com/oauth/authenticate'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public function getRequestTokenUri() |
|
29
|
|
|
{ |
|
30
|
1 |
|
return 'https://api.twitter.com/oauth/request_token'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public function getRequestTokenAccessUri() |
|
34
|
|
|
{ |
|
35
|
1 |
|
return 'https://api.twitter.com/oauth/access_token'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function getName() |
|
39
|
|
|
{ |
|
40
|
1 |
|
return self::NAME; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function getIdentity(AccessTokenInterface $accessToken) |
|
47
|
|
|
{ |
|
48
|
1 |
|
$this->consumerToken = $accessToken; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
1 |
|
$result = $this->request( |
|
51
|
1 |
|
'GET', |
|
52
|
1 |
|
'account/verify_credentials.json', |
|
53
|
|
|
[ |
|
54
|
|
|
// String is expected because Twitter is awful |
|
55
|
1 |
|
'include_email' => 'true' |
|
56
|
|
|
], |
|
57
|
|
|
$accessToken |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
1 |
|
$hydrator = new ArrayHydrator([ |
|
61
|
1 |
|
'id' => 'id', |
|
62
|
|
|
'name' => 'fullname', |
|
63
|
|
|
'email' => 'email', |
|
64
|
|
|
'screen_name' => 'username', |
|
65
|
|
|
'profile_image_url_https' => 'pictureURL' |
|
66
|
|
|
]); |
|
67
|
|
|
|
|
68
|
|
|
/** @var User $user */ |
|
69
|
1 |
|
$user = $hydrator->hydrate(new User(), $result); |
|
70
|
|
|
|
|
71
|
|
|
// When set to true email will be returned in the user objects as a string. |
|
72
|
|
|
// If the user does not have an email address on their account, |
|
73
|
|
|
// or if the email address is not verified, null will be returned. |
|
74
|
1 |
|
$user->emailVerified = true; |
|
75
|
|
|
|
|
76
|
1 |
|
return $user; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..