public function handle(Request $request, Closure $next, $requestKey = 'default')
    {
        if (!array_key_exists($requestKey, $this->configurations->get('signed-requests'))) {
            throw new InvalidConfigurationException();
        }

        $signed = new Verifier($request);

        $key = sprintf(
            '%s.%s',
            $this->configurations->get("signed-requests.$requestKey.cache-prefix"),
            $signed->getId()
        );

        $tolerance = $this->configurations->get("signed-requests.$requestKey.request-replay.tolerance");

        if (true !== $this->configurations->get("signed-requests.$requestKey.request-replay.allow")) {
            $isExpired = $signed->isExpired($tolerance);

            if ($isExpired || $this->cache->has($key)) {
                throw new ExpiredRequestException();
            }
        }

        $signed
            ->setSignatureHeader($this->configurations->get("signed-requests.$requestKey.headers.signature"))
            ->setAlgorithmHeader($this->configurations->get("signed-requests.$requestKey.headers.algorithm"));

        if (!$signed->isValid($this->configurations->get("signed-requests.$requestKey.key"))) {
            throw new InvalidSignatureException();
        }

        $this->cache->put($key, $key, $tolerance / 60);

        return $next($request);
    }
public function handle(Request $request, Closure $next, $requestKey = 'default')
    {
        if (!array_key_exists($requestKey, $this->configurations->get('signed-requests'))) {
            throw new InvalidConfigurationException();
        }

        $signed = new Verifier($request);

        $key = sprintf(
            '%s.%s',
            $this->configurations->get("signed-requests.$requestKey.cache-prefix"),
            $signed->getId()
        );

        $tolerance = $this->configurations->get("signed-requests.$requestKey.request-replay.tolerance");

        if (true !== $this->configurations->get("signed-requests.$requestKey.request-replay.allow")) {
            $isExpired = $signed->isExpired($tolerance);

            if ($isExpired || $this->cache->has($key)) {
                throw new ExpiredRequestException();
            }
        }

        $signed
            ->setSignatureHeader($this->configurations->get("signed-requests.$requestKey.headers.signature"))
            ->setAlgorithmHeader($this->configurations->get("signed-requests.$requestKey.headers.algorithm"));

        if (!$signed->isValid($this->configurations->get("signed-requests.$requestKey.key"))) {
            throw new InvalidSignatureException();
        }

        $this->cache->put($key, $key, $tolerance / 60);

        return $next($request);
    }
public function handle ( Request $ request , Closure $ next , $ requestKey = 'default' ) { if ( ! array_key_exists ( $ requestKey , $ this -> configurations -> get ( 'signed-requests' ) ) ) { throw new InvalidConfigurationException ( ) ; } $ signed = new Verifier ( $ request ) ; $ key = sprintf ( '%s.%s' , $ this -> configurations -> get ( "signed-requests.$requestKey.cache-prefix" ) , $ signed -> getId ( ) ) ; $ tolerance = $ this -> configurations -> get ( "signed-requests.$requestKey.request-replay.tolerance" ) ; if ( true !== $ this -> configurations -> get ( "signed-requests.$requestKey.request-replay.allow" ) ) { $ isExpired = $ signed -> isExpired ( $ tolerance ) ; if ( $ isExpired || $ this -> cache -> has ( $ key ) ) { throw new ExpiredRequestException ( ) ; } } $ signed -> setSignatureHeader ( $ this -> configurations -> get ( "signed-requests.$requestKey.headers.signature" ) ) -> setAlgorithmHeader ( $ this -> configurations -> get ( "signed-requests.$requestKey.headers.algorithm" ) ) ; if ( ! $ signed -> isValid ( $ this -> configurations -> get ( "signed-requests.$requestKey.key" ) ) ) { throw new InvalidSignatureException ( ) ; } $ this -> cache -> put ( $ key , $ key , $ tolerance / 60 ) ; return $ next ( $ request ) ; }
Applies the middleware to the request before moving onto the next request
handler.

@throws \SoapBox\SignedRequests\Exceptions\InvalidSignatureException
Thrown when the signature of the request is not valid.
@throws \SoapBox\SignedRequests\Exceptions\ExpiredRequestException
Thrown if request replays are disabled and either the request
timestamp is outside the window of tolerance, or the request has
previously been served.
@throws \SoapBox\SignedRequests\Exceptions\InvalidConfigurationException
Thrown if the request key is not defined in the config

@param  \Illuminate\Http\Request $request
An instance of the request.
@param  \Closure $next
A callback function of where to go next.
@param  mixed $requestKey

@return mixed
Applies the middleware to the request before moving onto the next request handler .