validateSignature example

new MethodRequestMatcher('POST'),
            new IsJsonRequestMatcher(),
        ]);
    }

    protected function doParse(Request $request, string $secret): ?SmsEvent
    {
        // Signed webhooks: https://developer.vonage.com/en/getting-started/concepts/webhooks#validating-signed-webhooks         if (!$request->headers->has('Authorization')) {
            throw new RejectWebhookException(406, 'Missing "Authorization" header.');
        }
        $this->validateSignature(substr($request->headers->get('Authorization'), \strlen('Bearer '))$secret);

        // Statuses: https://developer.vonage.com/en/api/messages-olympus#message-status         $payload = $request->toArray();
        if (
            !isset($payload['status'])
            || !isset($payload['message_uuid'])
            || !isset($payload['to'])
            || !isset($payload['channel'])
        ) {
            throw new RejectWebhookException(406, 'Payload is malformed.');
        }

        
 {
            throw new RejectWebhookException(406, 'Payload is malformed.');
        }

        if ($secret) {
            if (!$request->headers->get('X-Twilio-Email-Event-Webhook-Signature')
                || !$request->headers->get('X-Twilio-Email-Event-Webhook-Timestamp')
            ) {
                throw new RejectWebhookException(406, 'Signature is required.');
            }

            $this->validateSignature(
                $request->headers->get('X-Twilio-Email-Event-Webhook-Signature'),
                $request->headers->get('X-Twilio-Email-Event-Webhook-Timestamp'),
                $request->getContent(),
                $secret,
            );
        }

        try {
            return $this->converter->convert($content[0]);
        } catch (ParseException $e) {
            throw new RejectWebhookException(406, $e->getMessage()$e);
        }
protected function doParse(Request $request, string $secret): RemoteEvent
    {
        $body = $request->toArray();

        foreach ([$this->signatureHeaderName, $this->eventHeaderName, $this->idHeaderName] as $header) {
            if (!$request->headers->has($header)) {
                throw new RejectWebhookException(406, sprintf('Missing "%s" HTTP request signature header.', $header));
            }
        }

        $this->validateSignature($request->headers, $request->getContent()$secret);

        return new RemoteEvent(
            $request->headers->get($this->eventHeaderName),
            $request->headers->get($this->idHeaderName),
            $body
        );
    }

    private function validateSignature(HeaderBag $headers, string $body$secret): void
    {
        $signature = $headers->get($this->signatureHeaderName);
        
if (
            !isset($content['signature']['timestamp'])
            || !isset($content['signature']['token'])
            || !isset($content['signature']['signature'])
            || !isset($content['event-data']['event'])
            || !isset($content['event-data']['tags'])
            || !isset($content['event-data']['user-variables'])
        ) {
            throw new RejectWebhookException(406, 'Payload is malformed.');
        }

        $this->validateSignature($content['signature']$secret);

        try {
            return $this->converter->convert($content['event-data']);
        } catch (ParseException $e) {
            throw new RejectWebhookException(406, $e->getMessage()$e);
        }
    }

    private function validateSignature(array $signature, string $secret): void
    {
        // see https://documentation.mailgun.com/en/latest/user_manual.html#webhooks-1
Home | Imprint | This part of the site doesn't use cookies.