1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\AuthClient\Client; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Yii\AuthClient\OAuth1; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Twitter allows authentication via Twitter OAuth. |
11
|
|
|
* |
12
|
|
|
* In order to use Twitter OAuth you must register your application at <https://dev.twitter.com/apps/new>. |
13
|
|
|
* |
14
|
|
|
* > Note: some auth workflows provided by Twitter, such as [application-only authentication](https://dev.twitter.com/oauth/application-only), |
15
|
|
|
* uses OAuth 2 protocol and thus are impossible to be used with this class. You should use {@see TwitterOAuth2} for these. |
16
|
|
|
* |
17
|
|
|
* @see TwitterOAuth2 |
18
|
|
|
* @link https://apps.twitter.com/ |
19
|
|
|
* @link https://dev.twitter.com/ |
20
|
|
|
*/ |
21
|
|
|
final class Twitter extends OAuth1 |
22
|
|
|
{ |
23
|
|
|
protected string $authUrl = 'https://api.twitter.com/oauth/authenticate'; |
24
|
|
|
private string $requestTokenUrl = 'https://api.twitter.com/oauth/request_token'; |
|
|
|
|
25
|
|
|
private string $requestTokenMethod = 'POST'; |
|
|
|
|
26
|
|
|
private string $accessTokenUrl = 'https://api.twitter.com/oauth/access_token'; |
|
|
|
|
27
|
|
|
private string $accessTokenMethod = 'POST'; |
|
|
|
|
28
|
|
|
protected string $endpoint = 'https://api.twitter.com/1.1'; |
29
|
|
|
/** |
30
|
|
|
* @var array list of extra parameters, which should be used, while requesting user attributes from Twitter API. |
31
|
|
|
* For example: |
32
|
|
|
* |
33
|
|
|
* ```php |
34
|
|
|
* [ |
35
|
|
|
* 'include_email' => 'true' |
36
|
|
|
* ] |
37
|
|
|
* ``` |
38
|
|
|
* |
39
|
|
|
* @link https://dev.twitter.com/rest/reference/get/account/verify_credentials |
40
|
|
|
*/ |
41
|
|
|
private array $attributeParams = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string service name. |
45
|
|
|
*/ |
46
|
|
|
public function getName(): string |
47
|
|
|
{ |
48
|
|
|
return 'twitter'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string service title. |
53
|
|
|
*/ |
54
|
|
|
public function getTitle(): string |
55
|
|
|
{ |
56
|
|
|
return 'Twitter'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function initUserAttributes(): array |
60
|
|
|
{ |
61
|
|
|
return $this->api('account/verify_credentials.json', 'GET', $this->attributeParams); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|