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.
Completed
Push — master ( 012605...863ffb )
by Jared
02:17
created

OAuth::requestAccessToken()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 12/2/16
6
 * Time: 4:25 PM
7
 */
8
9
namespace JCFirebase;
10
11
use Firebase\JWT\JWT;
12
use Requests;
13
14
class OAuth
15
{
16
    /*
17
     * token life time in second
18
     * */
19
    public $tokenLifeTime;
20
    public $key;
21
    public $iss;
22
23
    protected $expireTimestamp;
24
    protected $accessToken;
25
26
    /**
27
     * OAuth constructor.
28
     * @param $key
29
     * @param $iss
30
     */
31
    public function __construct($key, $iss, $tokenLifeTime = 3600)
32
    {
33
        $this->key = $key;
34
        $this->iss = $iss;
35
        $this->tokenLifeTime = $tokenLifeTime;
36
    }
37
38
    protected function requestAccessToken()
39
    {
40
        $currentTimestamp = time();
41
        $this->expireTimestamp = $currentTimestamp + $this->tokenLifeTime;
42
        $jsonToken = array(
43
            "iss" => $this->iss,
44
            "scope" => "https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email",
45
            "aud" => "https://www.googleapis.com/oauth2/v4/token",
46
            "exp" => $this->expireTimestamp,
47
            "iat" => $currentTimestamp
48
        );
49
        $jwt = JWT::encode($jsonToken, $this->key, 'RS256');
50
51
        $OAuthResponse = Requests::post('https://www.googleapis.com/oauth2/v4/token', array(), array(
52
            'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
53
            'assertion' => $jwt
54
        ));
55
56
        if ($OAuthResponse->status_code == 200) {
57
            $this->accessToken = json_decode($OAuthResponse->body)->access_token;
58
            return true;
59
        }
60
        return false;
61
    }
62
63
    public function getAccessToken()
64
    {
65
        $startTime = time();
66
        $this->requestAccessToken();
67
        $endTime = time();
68
        $this->expireTimestamp -= ($endTime - $startTime);
69
        return $this->accessToken;
70
    }
71
}