Completed
Push — master ( ad69a5...d98011 )
by Дмитрий
03:25
created

Provider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 62
rs 10
c 2
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 4 1
A getAuthorizeUri() 0 4 1
A getRequestTokenUri() 0 4 1
A getName() 0 4 1
B getIdentity() 0 29 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Facebook;
8
9
use SocialConnect\Auth\Provider\OAuth2\AccessToken;
10
use SocialConnect\Common\Entity\User;
11
use SocialConnect\Common\Http\Client\Client;
12
use SocialConnect\Common\Hydrator\ObjectMap;
13
14
class Provider extends \SocialConnect\Auth\Provider\OAuth2\AbstractProvider
15
{
16
    /**
17
     * By default AbstractProvider use POST method, FB does not accept POST and return HTML page ᕙ(⇀‸↼‶)ᕗ
18
     *
19
     * @var string
20
     */
21
    protected $requestHttpMethod = Client::GET;
22
23
    public function getBaseUri()
24
    {
25
        return 'https://graph.facebook.com/v2.8/';
26
    }
27
28
    public function getAuthorizeUri()
29
    {
30
        return 'https://www.facebook.com/dialog/oauth';
31
    }
32
33
    public function getRequestTokenUri()
34
    {
35
        return 'https://graph.facebook.com/oauth/access_token';
36
    }
37
38
    public function getName()
39
    {
40
        return 'facebook';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getIdentity(AccessToken $accessToken)
47
    {
48
        $response = $this->service->getHttpClient()->request(
49
            $this->getBaseUri() . 'me',
50
            [
51
                'access_token' => $accessToken->getToken(),
52
                'fields' => $this->getFieldsInline()
53
            ]
54
        );
55
56
        $body = $response->getBody();
57
        $result = json_decode($body);
58
59
        $hydrator = new ObjectMap(array(
60
            'id' => 'id',
61
            'first_name' => 'firstname',
62
            'last_name' => 'lastname',
63
            'email' => 'email',
64
            'gender' => 'sex',
65
            'link' => 'url',
66
            'locale' => 'locale',
67
            'name' => 'fullname',
68
            'timezone' => 'timezone',
69
            'updated_time' => 'dateModified',
70
            'verified' => 'verified'
71
        ));
72
73
        return $hydrator->hydrate(new User(), $result);
74
    }
75
}
76