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.

Provider::getAccessToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SocialiteProviders\Hitbox;
4
5
use SocialiteProviders\Manager\OAuth2\User;
6
use Laravel\Socialite\Two\ProviderInterface;
7
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
8
9
class Provider extends AbstractProvider implements ProviderInterface
10
{
11
    /**
12
     * Unique Provider Identifier.
13
     */
14
    const IDENTIFIER = 'HITBOX';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $stateless = true;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected function getAuthUrl($state)
25
    {
26
        return $this->buildAuthUrlFromBase('https://api.hitbox.tv/oauth/login', $state);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function getTokenUrl()
33
    {
34
        return 'https://api.hitbox.tv/oauth/exchange';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function getUserByToken($token)
41
    {
42
        $username = $this->getUserNameByToken($token);
43
44
        $response = $this->getHttpClient()->get('https://api.hitbox.tv/user/'.$username, [
45
            'query' => ['authToken' => $token],
46
        ]);
47
48
        return json_decode($response->getBody(), true);
49
    }
50
51
    protected function getUserNameByToken($token)
52
    {
53
        $response = $this->getHttpClient()->get('https://api.hitbox.tv/userfromtoken/'.$token);
54
55
        return array_get(json_decode($response->getBody(), true), 'user_name');
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    protected function mapUserToObject(array $user)
62
    {
63
        return (new User())->setRaw($user)->map([
64
            'id' => array_get($user, 'user_id'),
65
            'nickname' => array_get($user, 'user_name'),
66
            'email' => array_get($user, 'user_email'),
67
            'avatar' => array_get($user, 'user_logo'),
68
        ]);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function getCodeFields($state = null)
75
    {
76
        return ['app_token' => $this->clientId];
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    protected function getCode()
83
    {
84
        return $this->request->input('request_token');
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    protected function getTokenFields($code)
91
    {
92
        return [
93
            'request_token' => $code,
94
            'app_token' => $this->clientId,
95
            'hash' => base64_encode($this->clientId.$this->clientSecret),
96
        ];
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function user()
103
    {
104
        $user = $this->mapUserToObject($this->getUserByToken(
105
            $token = $this->getAccessToken() ?: array_get($this->getAccessTokenResponse($this->getCode()), 'access_token')
0 ignored issues
show
Bug introduced by
It seems like $this->getCode() targeting SocialiteProviders\Hitbox\Provider::getCode() can also be of type array; however, Laravel\Socialite\Two\Ab...etAccessTokenResponse() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
106
        ));
107
108
        return $user->setToken($token);
109
    }
110
111
    protected function getAccessToken()
112
    {
113
        return $this->request->input('authToken');
114
    }
115
}
116