spatie / laravel-webhook-client

Receive webhooks in Laravel apps
https://freek.dev/1383-sending-and-receiving-webhooks-in-laravel-apps
MIT License
1k stars 147 forks source link

Custom SignaureValidator error: not a valid signature validator class. #123

Closed Mozzarella-dev closed 2 years ago

Mozzarella-dev commented 2 years ago

I really don't know if it's a bug or i'm missing something here.

This is my validator, its path is App\Handler\MyValidator.php :

use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
use Spatie\WebhookClient\Exceptions\InvalidConfig;
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;

class MyValidator implements SignatureValidator
{
    public function isValid(Request $request, WebhookConfig $config): bool
    {
        $signature = $request->header($config->signatureHeaderName);

        if (! $signature) {
            return false;
        }

        $signingSecret = $config->signingSecret;

        if (empty($signingSecret)) {
            throw InvalidConfig::signingSecretNotSet();
        }

        $computedSignature = base64_encode(hash_hmac('sha256', $request->getContent(), $signingSecret, true));

        return hash_equals($signature, $computedSignature);
    }
}

In the webhook-client.php config file i've got:

'signature_validator' => \App\Handler\MyValidator::class,

The full error message is the following:

local.ERROR: `App\Handler\MyValidator` is not a valid signature validator class. A valid signature validator is a class that implements `Spatie\WebhookClient\SignatureValidator\SignatureValidator`. {"exception":"[object] (Spatie\\WebhookClient\\Exceptions\\InvalidConfig(code: 0): `App\\Handler\\MyValidator` is not a valid signature validator class. A valid signature validator is a class that implements `Spatie\\WebhookClient\\SignatureValidator\\SignatureValidator`. at /var/www/html/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php:22)