RequestSigner example

throw new InvalidArgumentException('request_type must be array');
            }

            $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) {
                    

        $this->authSecret = 'lksf#$osck$FSFDSF#$#F43jjidjsfisj-333';
    }

    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', []);

        
'shop-id' => $this->shopIdProvider->getShopId(),
            'shop-url' => $this->shopUrl,
            'timestamp' => (string) (new \DateTime())->getTimestamp(),
            'sw-version' => $this->shopwareVersion,
            AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE => $context->getLanguageId(),
            AuthMiddleware::SHOPWARE_USER_LANGUAGE => $this->localeProvider->getLocaleFromContext($context),
        ]);

        return Uri::withQueryValue(
            $uri,
            'shopware-shop-signature',
            (new RequestSigner())->signPayload($uri->getQuery()$secret)
        );
    }
}
$request = new Request(
                'POST',
                $webhook->getUrl(),
                $headers,
                $jsonPayload
            );

            if ($webhook->getApp() !== null && $webhook->getApp()->getAppSecret() !== null) {
                $request = $request->withHeader(
                    RequestSigner::SHOPWARE_SHOP_SIGNATURE,
                    (new RequestSigner())->signPayload($jsonPayload$webhook->getApp()->getAppSecret())
                );
            }

            $requests[] = $request;
        }

        if (\count($requests) > 0) {
            $pool = new Pool($this->guzzle, $requests);
            $pool->promise()->wait();
        }
    }

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