Yandex   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 37
ccs 0
cts 13
cp 0
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initUserAttributes() 0 3 1
A applyAccessTokenToRequest() 0 10 2
A getTitle() 0 3 1
A getName() 0 3 1
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
use Yiisoft\Yii\AuthClient\RequestUtil;
11
12
/**
13
 * Yandex allows authentication via Yandex OAuth.
14
 *
15
 * In order to use Yandex OAuth you must register your application at <https://oauth.yandex.ru/client/new>.
16
 *
17
 * @link https://oauth.yandex.ru/client/new
18
 * @link https://api.yandex.ru/login/doc/dg/reference/response.xml
19
 */
20
final class Yandex extends OAuth2
21
{
22
    protected string $authUrl = 'https://oauth.yandex.ru/authorize';
23
    protected string $tokenUrl = 'https://oauth.yandex.ru/token';
24
    protected string $endpoint = 'https://login.yandex.ru';
25
26
    public function applyAccessTokenToRequest(RequestInterface $request, OAuthToken $accessToken): RequestInterface
27
    {
28
        $params = RequestUtil::getParams($request);
29
30
        $paramsToAdd = [];
31
        if (!isset($params['format'])) {
32
            $paramsToAdd['format'] = 'json';
33
        }
34
        $paramsToAdd['oauth_token'] = $accessToken->getToken();
35
        return RequestUtil::addParams($request, $paramsToAdd);
36
    }
37
38
    /**
39
     * @return string service name.
40
     */
41
    public function getName(): string
42
    {
43
        return 'yandex';
44
    }
45
46
    /**
47
     * @return string service title.
48
     */
49
    public function getTitle(): string
50
    {
51
        return 'Yandex';
52
    }
53
54
    protected function initUserAttributes(): array
55
    {
56
        return $this->api('info');
57
    }
58
}
59