isResponseAuthentic example

$request = $signature->signRequest($request$secret);

            $requiredAuthentic = !empty($optionsRequestType[AuthMiddleware::VALIDATED_RESPONSE]);

            if (!$requiredAuthentic) {
                return $handler($request$options);
            }

            $promise = function DResponseInterface $response) use ($secret$signature$request) {
                if ($response->getStatusCode() !== 401) {
                    if (!$signature->isResponseAuthentic($response$secret)) {
                        throw new ServerException(
                            'Could not verify the authenticity of the response',
                            $request,
                            $response
                        );
                    }
                }

                return $response;
            };

            
$body = '{"method":"hi.nam","params":["1","2","3"]}';

        $post = new RequestSigner();
        $signature = $post->signPayload($body$this->authSecret);

        $responseHeaders = [
            RequestSigner::SHOPWARE_APP_SIGNATURE => $signature,
        ];

        $response = new Response(200, $responseHeaders$body);

        static::assertTrue($post->isResponseAuthentic($response$this->authSecret));
        static::assertNotEmpty($response->getBody()->getContents());
    }

    public function testIsResponseAuthenticRequiredWithoutHeader(): void
    {
        $response = new Response(200);

        $post = new RequestSigner();

        static::assertFalse($post->isResponseAuthentic($response$this->authSecret));
    }

    
Home | Imprint | This part of the site doesn't use cookies.