-
Notifications
You must be signed in to change notification settings - Fork 21
/
Server.php
126 lines (105 loc) · 3.22 KB
/
Server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace SocialiteProviders\Twitter;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use League\OAuth1\Client\Credentials\TokenCredentials;
use SocialiteProviders\Manager\OAuth1\Server as BaseServer;
use SocialiteProviders\Manager\OAuth1\User;
class Server extends BaseServer
{
/**
* {@inheritdoc}
*/
public function urlTemporaryCredentials()
{
return 'https://api.twitter.com/oauth/request_token';
}
/**
* {@inheritdoc}
*/
public function urlAuthorization()
{
return 'https://api.twitter.com/oauth/authenticate';
}
/**
* {@inheritdoc}
*/
public function urlTokenCredentials()
{
return 'https://api.twitter.com/oauth/access_token';
}
/**
* {@inheritdoc}
*/
public function urlUserDetails()
{
return 'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true';
}
/**
* {@inheritdoc}
*/
public function userDetails($data, TokenCredentials $tokenCredentials)
{
$user = new User;
$user->id = $data['id'];
$user->nickname = $data['screen_name'];
$user->name = $data['name'];
$user->location = $data['location'];
$user->description = $data['description'];
$user->avatar = $data['profile_image_url_https'];
$user->email = null;
if (isset($data['email'])) {
$user->email = $data['email'];
}
$used = ['id', 'screen_name', 'name', 'location', 'description', 'profile_image_url_https', 'email'];
$urls = [];
if (isset($data) and ! empty($data)) {
foreach ($data as $key => $value) {
if (str_contains($key, 'url')) {
if (! in_array($key, $used, true)) {
$used[] = $key;
}
$urls[$key] = $value;
}
}
}
$user->urls = $urls;
$user->extra = array_diff_key($data, array_flip($used));
return $user;
}
/**
* {@inheritdoc}
*/
public function userUid($data, TokenCredentials $tokenCredentials)
{
return $data['id'];
}
/**
* {@inheritdoc}
*/
public function userEmail($data, TokenCredentials $tokenCredentials) {}
/**
* {@inheritdoc}
*/
public function userScreenName($data, TokenCredentials $tokenCredentials)
{
return $data['screen_name'];
}
/**
* {@inheritdoc}
*/
public function getAuthorizationUrl($temporaryIdentifier, array $options = [])
{
// Somebody can pass through an instance of temporary
// credentials and we'll extract the identifier from there.
if ($temporaryIdentifier instanceof TemporaryCredentials) {
$temporaryIdentifier = $temporaryIdentifier->getIdentifier();
}
$queryOauthToken = ['oauth_token' => $temporaryIdentifier];
$parameters = (isset($this->parameters))
? array_merge($queryOauthToken, $this->parameters)
: $queryOauthToken;
$url = $this->urlAuthorization();
$queryString = http_build_query($parameters);
return $this->buildUrl($url, $queryString);
}
}