Issues (58)

src/Service/AuthenticatedAtlassianClient.php (4 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AtlassianConnectBundle\Service;
6
7
use AtlassianConnectBundle\Entity\TenantInterface;
8
use Symfony\Component\HttpClient\DecoratorTrait;
9
use Symfony\Contracts\HttpClient\HttpClientInterface;
10
use Symfony\Contracts\HttpClient\ResponseInterface;
11
12
final class AuthenticatedAtlassianClient implements HttpClientInterface
13
{
14
    use DecoratorTrait;
15
16
    public function request(string $method, string $url, array $options = []): ResponseInterface
17
    {
18
        /** @var TenantInterface $tenant */
19
        $tenant = $options['tenant'];
20
        $userId = $options['user_id'];
21
        unset($options['tenant']);
22
        unset($options['user_id']);
23
24
        if (!$userId) {
25
            $options['headers']['Authorization'] = 'JWT '.JWTGenerator::generate($url, $method, $tenant->getAddonKey(), $tenant->getSharedSecret());
0 ignored issues
show
It seems like $tenant->getSharedSecret() can also be of type null; however, parameter $secret of AtlassianConnectBundle\S...WTGenerator::generate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            $options['headers']['Authorization'] = 'JWT '.JWTGenerator::generate($url, $method, $tenant->getAddonKey(), /** @scrutinizer ignore-type */ $tenant->getSharedSecret());
Loading history...
It seems like $tenant->getAddonKey() can also be of type null; however, parameter $issuer of AtlassianConnectBundle\S...WTGenerator::generate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            $options['headers']['Authorization'] = 'JWT '.JWTGenerator::generate($url, $method, /** @scrutinizer ignore-type */ $tenant->getAddonKey(), $tenant->getSharedSecret());
Loading history...
26
27
            return $this->client->request($method, $url, $options);
28
        }
29
30
        if (!$tenant->getOauthClientId()) {
31
            throw new \RuntimeException('Tenant is not set up as oath application. Install the app with "ACT_AS_USER" scope.');
32
        }
33
34
        $result = $this->client->request('POST', 'https://oauth-2-authorization-server.services.atlassian.com/oauth2/token', [
35
            'body' => [
36
                'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
37
                'assertion' => JWTGenerator::generateAssertion($tenant->getSharedSecret(), $tenant->getOauthClientId(), $tenant->getBaseUrl(), $userId),
0 ignored issues
show
It seems like $tenant->getBaseUrl() can also be of type null; however, parameter $baseUrl of AtlassianConnectBundle\S...or::generateAssertion() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
                'assertion' => JWTGenerator::generateAssertion($tenant->getSharedSecret(), $tenant->getOauthClientId(), /** @scrutinizer ignore-type */ $tenant->getBaseUrl(), $userId),
Loading history...
It seems like $tenant->getSharedSecret() can also be of type null; however, parameter $secret of AtlassianConnectBundle\S...or::generateAssertion() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
                'assertion' => JWTGenerator::generateAssertion(/** @scrutinizer ignore-type */ $tenant->getSharedSecret(), $tenant->getOauthClientId(), $tenant->getBaseUrl(), $userId),
Loading history...
38
            ],
39
        ]);
40
41
        $options['headers']['Authorization'] = 'Bearer '.$result->toArray()['access_token'];
42
43
        return $this->client->request($method, $url, $options);
44
    }
45
}
46