TwitterOAuth2::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\AuthClient\Client;
6
7
use Psr\Http\Message\RequestInterface;
8
use Yiisoft\Yii\AuthClient\OAuth2;
9
use Yiisoft\Yii\AuthClient\OAuthToken;
10
11
/**
12
 * TwitterOAuth2 allows authentication via Twitter OAuth 2.
13
 *
14
 * Note, that at the time these docs are written, Twitter does not provide full support for OAuth 2 protocol.
15
 * It is supported only for [application-only authentication](https://dev.twitter.com/oauth/application-only) workflow.
16
 * Thus only {@see authenticateClient()} method of this class has a practical usage.
17
 *
18
 * Any authentication attempt on behalf of the end-user will fail for this client. You should use {@see Twitter} class for
19
 * this workflow.
20
 *
21
 * @see Twitter
22
 * @link https://dev.twitter.com/
23
 */
24
final class TwitterOAuth2 extends OAuth2
25
{
26
    protected string $authUrl = 'https://api.twitter.com/oauth2/authenticate';
27
    protected string $tokenUrl = 'https://api.twitter.com/oauth2/token';
28
    protected string $endpoint = 'https://api.twitter.com/1.1';
29
30
    public function applyAccessTokenToRequest(RequestInterface $request, OAuthToken $accessToken): RequestInterface
31
    {
32
        return $request->withHeader('Authorization', 'Bearer ' . $accessToken->getToken());
33
    }
34
35
    /**
36
     * @return string service name.
37
     */
38
    public function getName(): string
39
    {
40
        return 'twitter';
41
    }
42
43
    /**
44
     * @return string service title.
45
     */
46
    public function getTitle(): string
47
    {
48
        return 'Twitter';
49
    }
50
51
    protected function initUserAttributes(): array
52
    {
53
        return $this->api('account/verify_credentials.json', 'GET');
54
    }
55
}
56