Completed
Push — master ( 4c303e...0095fb )
by Дмитрий
03:38
created

GitHub::getRequestTokenUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\OAuth2\Provider;
8
9
use SocialConnect\Provider\AccessTokenInterface;
10
use SocialConnect\Provider\Exception\InvalidResponse;
11
use SocialConnect\Common\Entity\User;
12
use SocialConnect\Common\Hydrator\ObjectMap;
13
14
class GitHub extends \SocialConnect\OAuth2\AbstractProvider
15
{
16 1
    public function getBaseUri()
17
    {
18 1
        return 'https://api.github.com/';
19
    }
20
21 2
    public function getAuthorizeUri()
22
    {
23 2
        return 'https://github.com/login/oauth/authorize';
24
    }
25
26 1
    public function getRequestTokenUri()
27
    {
28 1
        return 'https://github.com/login/oauth/access_token';
29
    }
30
31 2
    public function getName()
32
    {
33 2
        return 'github';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getIdentity(AccessTokenInterface $accessToken)
40
    {
41
        $response = $this->httpClient->request(
42
            $this->getBaseUri() . 'user',
43
            [
44
                'access_token' => $accessToken->getToken()
45
            ]
46
        );
47
48
        if (!$response->isSuccess()) {
49
            throw new InvalidResponse(
50
                'API response with error code',
51
                $response
52
            );
53
        }
54
55
        $body = $response->getBody();
56
        $result = json_decode($body);
57
58
        $hydrator = new ObjectMap(
59
            [
60
                'id' => 'id',
61
                'login' => 'username',
62
                'email' => 'email',
63
            ]
64
        );
65
66
        return $hydrator->hydrate(new User(), $result);
67
    }
68
}
69