signRequest example

$optionsRequestType = $options[self::APP_REQUEST_TYPE];

            if (!isset($optionsRequestType[self::APP_SECRET])) {
                throw new InvalidArgumentException('app_secret is required');
            }

            $secret = $optionsRequestType[self::APP_SECRET];

            $signature = new RequestSigner();

            $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(
                            


    public function testSignHeaderAddedRequest(): void
    {
        $body = '{"method":"hi.nam","params":["1","2","3"]}';
        $hashExpected = hash_hmac('sha256', $body$this->authSecret);

        $request = new Request('POST', 'https://example.local', []$body);

        $post = new RequestSigner();

        $request = $post->signRequest($request$this->authSecret);

        static::assertTrue($request->hasHeader(RequestSigner::SHOPWARE_SHOP_SIGNATURE));

        static::assertEquals($hashExpected$request->getHeader(RequestSigner::SHOPWARE_SHOP_SIGNATURE)[0]);
    }

    public function testSignHeaderWithoutAddedMethodGet(): void
    {
        $request = new Request('GET', 'https://example.local', []);

        $post = new RequestSigner();

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