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.
Test Setup Failed
Push — master ( 500279...2f8c13 )
by
unknown
02:35
created

Token::getRequest()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 24
nc 6
nop 2
dl 0
loc 41
rs 9.2248
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Security\Authentication\Oauth;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Psr\Http\Server\MethodInterface;
0 ignored issues
show
Bug introduced by
The type O2System\Psr\Http\Server\MethodInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use O2System\Security\Encoders\Base64;
20
use O2System\Security\Encoders\Json;
21
use O2System\Security\Generators\Signature;
22
use O2System\Spl\Traits\Collectors\ErrorCollectorTrait;
23
24
/**
25
 * Class Token
26
 * @package O2System\Security\Authentication\Oauth
27
 */
28
class Token implements MethodInterface
29
{
30
    use ErrorCollectorTrait;
31
32
    protected $consumer;
33
34
    public function __construct(Consumer $consumer)
35
    {
36
        $this->consumer = $consumer;
37
    }
38
39
    // ------------------------------------------------------------------------
40
41
    /**
42
     * Token::getVerifier
43
     *
44
     * Gets Token oauth_verifier code.
45
     *
46
     * @return bool|string
47
     */
48
    public function getVerifier()
49
    {
50
        if ( ! empty($this->key) && ! empty($this->secret)) {
51
            $key = rawurlencode($this->key);
52
            $secret = rawurlencode($this->secret);
53
54
            return base64_encode($key . ':' . $secret);
55
        }
56
57
        return false;
58
    }
59
60
    // ------------------------------------------------------------------------
61
62
    /**
63
     * Token::getRequest
64
     *
65
     * Gets OAuth Request Token.
66
     *
67
     * @return array|bool Returns FALSE if failed.
68
     */
69
    public function getRequest($callbackUrl, $httpMethod = self::HTTP_POST)
70
    {
71
        $algorithm = 'HMAC-SHA1';
0 ignored issues
show
Unused Code introduced by
The assignment to $algorithm is dead and can be removed.
Loading history...
72
        if (false === ($signature = Base64::decode($this->consumer->secret))) {
73
            $this->addError(400, 'Invalid Consumer Secret');
74
75
            return false;
76
        }
77
78
        if (false === ($signature = Json::decode($signature))) {
0 ignored issues
show
introduced by
The condition false === $signature = O...son::decode($signature) is always false.
Loading history...
79
            $this->addError(400, 'Invalid Consumer Secret');
80
81
            return false;
82
        }
83
84
        $signature->callbackUrl = $callbackUrl;
0 ignored issues
show
Bug introduced by
The property callbackUrl does not seem to exist on O2System\Spl\Datastructures\SplArrayObject.
Loading history...
85
        $signature->httpMethod = $httpMethod;
0 ignored issues
show
Bug introduced by
The property httpMethod does not seem to exist on O2System\Spl\Datastructures\SplArrayObject.
Loading history...
86
        $algorithm = $signature->algorithm;
87
88
        if (false !== ($payload = Base64::decode($this->consumer->key))) {
89
            $payload = Json::decode($payload)->getArrayCopy();
90
        }
91
92
        if ($payload) {
93
            $payload[ 'timestamp' ] = time();
94
95
            $segments[] = Base64::encode(Json::encode($signature));
0 ignored issues
show
Comprehensibility Best Practice introduced by
$segments was never initialized. Although not strictly required by PHP, it is generally a good practice to add $segments = array(); before regardless.
Loading history...
96
            $segments[] = $token = Base64::encode(Signature::generate([
97
                'payload' => Base64::encode(Json::encode($payload)),
98
                'token'   => \OAuthProvider::generateToken(strlen($this->consumer->secret), true),
99
            ], $this->consumer->key, $algorithm));
100
101
            $secret = Base64::encode(Signature::generate($segments, $this->consumer->key, $algorithm));
102
103
            return [
104
                'oauth_token'        => $token,
105
                'oauth_token_secret' => $secret,
106
            ];
107
        }
108
109
        return false;
110
    }
111
112
    // ------------------------------------------------------------------------
113
}