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.

JwtStrategy   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 80
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A authenticate() 0 4 1
B authenticateJwtToken() 0 41 5
A getSlug() 0 4 1
1
<?php
2
3
namespace Audiens\AdobeClient\Authentication;
4
5
use Audiens\AdobeClient\Exception\AuthException;
6
use Doctrine\Common\Cache\Cache;
7
use GuzzleHttp\ClientInterface;
8
9
/**
10
 * Class JwtStrategy
11
 */
12
class JwtStrategy implements AuthStrategyInterface
13
{
14
15
    const NAME = 'jwt_auth_strategy';
16
17
    const BASE_URL = 'https://ims-na1.adobelogin.com/ims/exchange/jwt/';
18
19
    const CACHE_NAMESPACE = 'jwt_auth_token';
20
    const TOKEN_EXPIRATION = 110;
21
22
    /** @var Cache */
23
    protected $cache;
24
25
    /**
26
     * JwtStrategy constructor.
27
     *
28
     * @param ClientInterface $clientInterface
29
     * @param Cache|null $cache
30
     */
31
    public function __construct(ClientInterface $clientInterface, Cache $cache)
32
    {
33
        $this->cache = $cache;
34
        $this->client = $clientInterface;
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
    }
36
37
    public function authenticate($clientId, $secretKey, $username, $password, $cache = true, $refresh = false)
38
    {
39
        // TODO: Implement authenticate() method.
40
    }
41
42
    public function authenticateJwtToken($clientId, $secretKey, $jwtToken, $cache = true)
43
    {
44
        $cacheKey = self::CACHE_NAMESPACE . sha1($clientId . $secretKey . $jwtToken . self::BASE_URL);
45
46
        if ($cache) {
47
            if ($this->cache->contains($cacheKey)) {
48
                return $this->cache->fetch($cacheKey);
49
            }
50
        }
51
52
        $response = $this->client->request(
53
            'POST',
54
            self::BASE_URL,
55
            [
56
                'form_params' =>
57
                    [
58
                        'client_id' => $clientId,
59
                        'client_secret' => $secretKey,
60
                        'jwt_token' => $jwtToken,
61
                    ]
62
            ]
63
        );
64
65
66
        $content = $response->getBody()->getContents();
67
        $response->getBody()->rewind();
68
69
        $contentArray = \json_decode($content, true);
70
71
        if (!isset($contentArray["access_token"])) {
72
            throw new \Exception(AuthException::authFailed('No field access token available in json response'));
73
        }
74
75
        $token = $contentArray["access_token"];
76
77
        if ($cache) {
78
            $this->cache->save($cacheKey, $token, self::TOKEN_EXPIRATION);
79
        }
80
81
        return $token;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getSlug()
88
    {
89
        return self::NAME;
90
    }
91
}
92