Completed
Push — master ( 90d0db...58a9b3 )
by
unknown
01:36
created

AutoDesk::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Hybridauth
4
 * https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
5
 *  (c) 2020 Hybridauth authors | https://hybridauth.github.io/license.html
6
 */
7
8
namespace Hybridauth\Provider;
9
10
use Hybridauth\Adapter\OAuth2;
11
use Hybridauth\Exception\UnexpectedApiResponseException;
12
use Hybridauth\Data;
13
use Hybridauth\User;
14
15
/**
16
 * AutoDesk OAuth2 provider adapter.
17
 */
18
class AutoDesk extends OAuth2
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected $scope = 'data:read';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $apiBaseUrl = 'https://developer.api.autodesk.com/';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $authorizeUrl
34
        = 'https://developer.api.autodesk.com/authentication/v1/authorize';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected $accessTokenUrl
40
        = 'https://developer.api.autodesk.com/authentication/v1/gettoken';
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected $refreshTokenUrl
46
        = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken';
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected $apiDocumentation
52
        = 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/overview/';
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function initialize()
58
    {
59
        parent::initialize();
60
        
61
        if ($this->isRefreshTokenAvailable()) {
62
            $this->tokenRefreshParameters += [
63
                'client_id'     => $this->clientId,
64
                'client_secret' => $this->clientSecret,
65
                'grant_type'    => 'refresh_token',
66
            ];
67
        }
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     *
73
     * See: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/
74
     */
75
    public function getUserProfile()
76
    {
77
        $response = $this->apiRequest('userprofile/v1/users/@me');
78
79
        $collection = new Data\Collection($response);
80
81
        $userProfile = new User\Profile();
82
83
        $userProfile->identifier = $collection->get('userId');
84
        $userProfile->displayName
85
            = $collection->get('firstName') .' '. $collection->get('lastName');
86
        $userProfile->firstName = $collection->get('firstName');
87
        $userProfile->lastName = $collection->get('lastName');
88
        $userProfile->email = $collection->get('emailId');
89
        $userProfile->language = $collection->get('language');
90
        $userProfile->webSiteURL = $collection->get('websiteUrl');
91
        $userProfile->photoURL
92
            = $collection->filter('profileImages')->get('sizeX360');
93
94
        return $userProfile;
95
    }
96
}
97