Issues (281)

src/Request/SubscriptionsRequestMiddleware.php (4 issues)

1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Request;
12
13
use Lcobucci\JWT\Parser;
14
use Lcobucci\JWT\Signer\Hmac\Sha256;
15
use Symfony\Component\HttpFoundation\Request;
16
use Ynlo\GraphQLBundle\Subscription\SubscriptionRequest;
17
18
/**
19
 * This middleware listen for internal subscriptions requests to set this arguments in the query.
20
 *
21
 * NOTE: subscriptions requests are internal requests send by a subscription consumer in order to
22
 * emulate a request like a final user but when a subscription is dispatched.
23
 */
24
class SubscriptionsRequestMiddleware implements RequestMiddlewareInterface
25
{
26
    protected $secret;
27
28
    /**
29
     * SubscriptionsRequestMiddleware constructor.
30
     *
31
     * @param string $secret
32
     */
33
    public function __construct($secret)
34
    {
35
        $this->secret = $secret;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function processRequest(Request $request, ExecuteQuery $query): void
42
    {
43
        $content = $request->getContent();
44
        if ($content
45
            && $request->headers->has('Subscription')
46
            && $subscriptionJWT = $request->headers->get('Subscription')) {
47
            $token = (new Parser())->parse($subscriptionJWT);
48
            if (!$token->verify(new Sha256(), $this->secret)) {
0 ignored issues
show
Deprecated Code introduced by
The function Lcobucci\JWT\Token::verify() has been deprecated: This method has been removed from the interface in v4.0 ( Ignorable by Annotation )

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

48
            if (!/** @scrutinizer ignore-deprecated */ $token->verify(new Sha256(), $this->secret)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
                throw new \RuntimeException('Invalid subscription signature');
50
            }
51
52
            $query->setSubscriptionRequest(
53
                new SubscriptionRequest(
54
                    $token->getClaim('jti'),
0 ignored issues
show
It seems like $token->getClaim('jti') can also be of type null; however, parameter $id of Ynlo\GraphQLBundle\Subsc...nRequest::__construct() 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

54
                    /** @scrutinizer ignore-type */ $token->getClaim('jti'),
Loading history...
Deprecated Code introduced by
The function Lcobucci\JWT\Token::getClaim() has been deprecated: This method has been removed from the interface in v4.0 ( Ignorable by Annotation )

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

54
                    /** @scrutinizer ignore-deprecated */ $token->getClaim('jti'),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
                    unserialize($token->getClaim('data'), [true])
0 ignored issues
show
Deprecated Code introduced by
The function Lcobucci\JWT\Token::getClaim() has been deprecated: This method has been removed from the interface in v4.0 ( Ignorable by Annotation )

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

55
                    unserialize(/** @scrutinizer ignore-deprecated */ $token->getClaim('data'), [true])

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
56
                )
57
            );
58
        }
59
    }
60
}
61