I want to use unicodeString from symfoni in laravel controller
protected function validateWaWebhook($known_token, Request $request)
{
if (($signature = $request->headers->get('X-Hub-Signature-256')) == null) {
// throw new BadRequestHttpException('Header not set');
return "header not set";
}
$signature_parts = explode('=', $signature);
if (count($signature_parts) != 2) {
// throw new BadRequestHttpException('signature has invalid format');
return "Signature invalid format";
}
$type = UnicodeString($request->getContent())->normalize(UnicodeString::NFC);
$known_signature = hash_hmac('sha256', $type, $known_token,false);
if (! hash_equals($known_signature, $signature_parts[1])) {
// throw new UnauthorizedException('Could not verify request signature ' . $signature_parts[1]);
return "Could not verify signature";
}
return "Valid signature";
}
When i try it it show
Error: Call to undefined function App\Http\Controllers\UnicodeString()
I've called the symphony
use Symfony\Component\String\UnicodeString;
My Answer:
>header('X-Signature')) && ($body = $request->getContent())) {
$unicodeString = new Symfony\Component\String\UnicodeString($body);
$computed_signature = hash_hmac('sha256', $unicodeString->toString(), $known_token);
if ($signature === $computed_signature) {
// Signature is valid
return true;
}
}
// Signature is invalid
return false;
}
Rate this post
3 of 5 based on 2800 votesComments