İmza Doğrulama

İmza Doğrulama

Webhook güvenliği, HMAC‑SHA256 imza doğrulaması ile sağlanır. Tüm webhook istekleri, X-Adisyo-Signature header'ı ile imzalanır.

İmza Algoritması

İmza Hesaplama

Message = WebhookEventType + "|" + EventTimeUtc + "|" + ApiKey
Signature = Base64(HMACSHA256(Message))

Header formatı

X-Adisyo-Signature: <base64-encoded-signature>

Kod Örnekleri

Node.js

import { createHmac, timingSafeEqual } from 'crypto';
 
function verifySignature(payload, signature, apiKey) {
  const webhookData = JSON.parse(payload);
  const message = `${webhookData.WebhookEventType}|${webhookData.EventTimeUtc}|${apiKey}`;
  const expectedSignature = createHmac('sha256', apiKey)
    .update(message)
    .digest('base64');
  
  return timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expectedSignature)
  );
}
 
// Kullanım
app.post('/webhook', (req, res) => {
  const signature = req.headers['x-adisyo-signature'];
  const apiKey = process.env.ADISYO_API_KEY;
  
  if (!verifySignature(JSON.stringify(req.body), signature, apiKey)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
  
  // Webhook işle
  res.status(200).json({ success: true });
});