GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Phabricator::getDomain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ofbeaton\OAuth2\Client\Provider;
4
5
use Ofbeaton\OAuth2\Client\Provider\Exception\PhabricatorIdentityProviderException;
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Token\AccessToken;
8
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Psr\Http\Message\ResponseInterface;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\Exception\HttpException;
12
13
class Phabricator extends AbstractProvider
14
{
15
    use BearerAuthorizationTrait;
16
17
    /**
18
     * Phabricator API endpoint to retrieve logged in user information.
19
     *
20
     * @var string
21
     */
22
    const PATH_API_USER = '/api/user.whoami';
23
    
24
    /**
25
     * Phabricator OAuth server authorization endpoint.
26
     *
27
     * @var string
28
     */
29
    const PATH_AUTHORIZE = '/oauthserver/auth/';
30
    
31
    /**
32
     * habricator OAuth server token request endpoint.
33
     *
34
     * @var string
35
     */
36
    const PATH_TOKEN = '/oauthserver/token/';
37
38
    /**
39
     * Domain
40
     *
41
     * @var string
42
     */
43
    protected $domain;
44
45
    /**
46
     * @param array $options
47
     * @param array $collaborators
48
     *
49
     * @throws \InvalidArgumentException
50
     */
51 33
    public function __construct($options = [], array $collaborators = [])
52
    {
53 33
        parent::__construct($options, $collaborators);
54 33
        if (empty($options['domain'])) {
55 3
            $message = 'The "domain" option not set. Please set a domain.';
56 3
            throw new \InvalidArgumentException($message);
57
        }
58 33
    }
59
60
    /**
61
     * Get domain.
62
     *
63
     * @return string
64
     */
65 3
    public function getDomain()
66
    {
67 3
        return $this->domain;
68
    }
69
70
    /**
71
     * Get authorization url to begin OAuth flow
72
     *
73
     * @return string
74
     */
75 12
    public function getBaseAuthorizationUrl()
76
    {
77 12
        $url = $this->domain.self::PATH_AUTHORIZE;
78 12
        return $url;
79
    }
80
81
    /**
82
     * Get access token url to retrieve token
83
     *
84
     * @param  array $params
85
     *
86
     * @return string
87
     */
88 18
    public function getBaseAccessTokenUrl(array $params)
89
    {
90 18
        $url = $this->domain.self::PATH_TOKEN;
91 18
        return $url;
92
    }
93
94
    /**
95
     * Get provider url to fetch user details
96
     *
97
     * @param  AccessToken $token
98
     *
99
     * @return string
100
     */
101 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
102
    {
103 6
        $url = $this->domain.self::PATH_API_USER.'?'.$this->buildQueryString(array(
104 6
            'access_token' => $token->getToken(),
105 4
        ));
106 6
        return $url;
107
    }
108
109
    /**
110
     * Get the default scopes used by this provider.
111
     *
112
     * This should not be a complete list of all scopes, but the minimum
113
     * required for the provider user interface!
114
     *
115
     * @return array
116
     */
117 6
    protected function getDefaultScopes()
118 2
    {
119 6
        return [];
120
    }
121
122
    /**
123
     * Check a provider response for errors.
124
     *
125
     * @throws IdentityProviderException
126
     * @param  ResponseInterface $response
127
     * @param  string $data Parsed response data
128
     * @return void
129
     */
130 15
    protected function checkResponse(ResponseInterface $response, $data)
131
    {
132 15
        if ($response->getStatusCode() >= 400) {
133 3
            throw PhabricatorIdentityProviderException::clientException($response, $data);
134 12
        } elseif (isset($data['error']) === true) {
135 3
            throw PhabricatorIdentityProviderException::oauthException($response, $data);
136
        }
137 11
    }
138
139
    /**
140
     * Generate a user object from a successful user details request.
141
     *
142
     * @param array $response
143
     * @param AccessToken $token
144
     * @return Ofbeaton\OAuth2\Client\Provider\ResourceOwnerInterface
145
     */
146 3
    protected function createResourceOwner(array $response, AccessToken $token)
147
    {
148 3
        $user = new PhabricatorResourceOwner($response);
149 3
        $user->setDomain($this->domain);
150 3
        return $user;
151
    }
152
}
153