Webhooks allow you to receive real-time updates about user verification status changes and other events. This guide will help you set up and handle webhooks securely.
Triggered when a user's verification status or confidence level changes.
{
"type": "user.verification.updated",
"data": {
"sub": "user_id",
"verified": true,
"verification_confidence": 3,
"previous_values": {
"verified": false,
"verification_confidence": null
}
}
}
Here's an example of how to handle webhooks using AWS Lambda:
import UniversalVerify from 'universal-verify';
const webhookSecret = 'your-webhook-secret';
const universalVerifyClient = new UniversalVerify('client-id', 'client-secret');
exports.handler = async (event) => {
try {
// Get the signature from headers
const signature = event.headers['Universal-Verify-Signature'] ||
event.headers['universal-verify-signature'];
// Verify the webhook signature
const body = universalVerifyClient.verifyWebhookSignature(
event.body,
signature,
webhookSecret
);
// Process the webhook
switch (body.type) {
case 'user.verification.updated':
await handleVerificationUpdate(body.data);
break;
// Add other event types as needed
}
return {
statusCode: 200,
body: JSON.stringify({
status: 'Success',
message: 'Webhook received'
})
};
} catch (error) {
console.error('Webhook error:', error);
return {
statusCode: 400,
body: JSON.stringify({
status: 'Error',
message: 'Invalid webhook signature'
})
};
}
};
If a webhook delivery fails (e.g., your server is down or returns an error), Universal Verify will retry the delivery up to 2 additional times, for a total of 3 attempts (including the initial delivery). Each retry attempt will be made with the same payload and signature.