Getting Started with DeskDirector
DeskDirector Portals
Browser Support
What is the DeskDirector Admin Portal?
What is the DeskDirector Tech Portal
What is the DeskDirector Client Portal?
Desktop Portal
Managing Your Account
Admin Essentials
DeskDirector Features Overview
Logging in to DeskDirector
User Profiles & Profile Pictures
Managing Tickets with DeskDirector
Office Hours
Getting Started with the Solution Library
How Searching Works
Embedding Help Page Media
Get started with the DeskDirector Power Automate Connector
Features
Portal Customization
Forms
Service Catalogue
Communication
Email Connectors
Notifications
Email Notifications
Actionable Messages for Emails
Real-Time Chats
Email Template Engine
Surveys
Broadcasts
Generative AI
DeskDirector with Generative AI
Ticket Summary for TECH Portal
Setting up AI Service Providers
Microsoft Foundry for DeskDirector
Knowledge Bases for AI Assistants
Custom Tools for AI Assistants
AI Assistants in DeskDirector
Advanced
Login & Authentication
Contact Groups
Custom Domains
File Storage
Dashboard
Accounts
Contacts
Approvals
Tags
Task Lists
The Learning Center
Portal Deep Linking
Auditing & Analytics
Microsoft Power Automate
Actions
Solutions
Featured Solution: Teams Ticket Discussion
Power Automate Template Gallery
Featured Solution: Ticket Briefing
Power Automate Administration
DeskDirector Power Platform Connector Reference
Power Automate Connector - Setting up your first flow
Microsoft Teams App
Introducing the DeskDirector for Microsoft Team App
Installing the Microsoft Teams App (Client Mode)
Installing the Microsoft Teams App (TECH Mode)
Setting up Tags for Teams Discussions (TECH Portal)
Branding the DeskDirector Teams App
DeskDirector Teams App Notifications
Contact Groups Integration with Microsoft Teams
Setting up Content Security Policy (CSP)
Advanced topic: Setting up Tech & Client Mode in the same tenancy
Integrating Microsoft Teams with DeskDirector Tech Portal
Smart Alerts for TECH Users
Integrations
Developer Resources
Getting Started
What is the Toki Iti API
API Versions & Routes
Roles & Scopes
Authorization Options
Querying the API
How to Change an Entity Through the API
API Key Authorization
OAuth Fundamentals
Understanding OAuth for Tokity Integrations: Key Concepts
OAuth Authorization Code Flow: How an App Gets Access to Tokity
OAuth App Registration
How to Register an OAuth App to Integrate with Tokity
Choosing an OAuth App Type: Confidential vs. Public Apps and Client Secrets
OAuth Personal Secrets: What They Are and When to Use Them
OAuth Administration
Configuring OAuth Settings in Tokity
Managing OAuth Authorized Sessions and User Consent
Granting OAuth Admin Consent at the Root Level
API Response Control
Uploading Attachments (Ticket API)
The Prefer Header — Overview
Controlling Returned Data (Ticket API)
Controlling Returned Data (Form Result API)
Controlling Returned Data (Workspace API)
Workspace Ordering
How Workspace Ordering Works
Creating and Reordering Workspace Groups
Adding and Reordering Tickets in a Workspace Group
Data Sync & Notifications
Delta API: Tracking Changes Over Time
Webhooks vs. Events — Differences, When to Use Which
Verifying Webhook and Event Payloads (HMAC Signature)
Ticket Widgets
Ticket Widget: Overview
How the Widget Is Requested
Ticket Widget Anatomy and Styling
Ticket Widget Actions: Leading, Secondary and Primary
Ticket Widget: Progress Type
Ticket Widget: List Type
Ticket Widget: Description Type
Ticket Widget: Form Type
Ticket Widget: Control When a Widget Refreshes
Ticket Widget: Form Results and State Across Steps
Ticket Widget: Error Responses and Debugging
Ticket Widget: Building a Multi-Step Request
Glossary
Security
Troubleshooting
Troubleshooting via Web Developer Tools
Permissions & Access - Common Issues
Contact DeskDirector Support
Troubleshooting DeskDirector Connection Issues
Desktop Portal - Common Issues
Contact Impersonation
Approvals - Common Issues
Microsoft Teams App - Common Issues
Email & Email Delivery - Common Issues
Login & Authentication - Common Issues
DeskDirector Desktop App - Installation Issues
- All Categories
- Developer Resources
- Data Sync & Notifications
- Verifying Webhook and Event Payloads (HMAC Signature)
Verifying Webhook and Event Payloads (HMAC Signature)
Updated
by Niamh Ferns
Tokity offers various methods for sending webhooks. To ensure the security of the receiving endpoint, our system includes a signature as a custom header. This signature acts as a fingerprint for the current delivered webhook payload. The receiving endpoint utilises a secret to verify incoming HTTP requests.
Verification Process
The verification process involves several steps:
- Read Request Body: The incoming HTTP request body is read as a raw payload.
- Extract Custom Header: The custom header containing the signature is extracted from the HTTP request. Custom header name is
x-dd-signature. - Hash Calculation: The request body is hashed using the HMAC hash algorithm.
- Comparison: The hashed request body is compared with the extracted signature in the header. They must match for verification to succeed.
C# Code Example:
using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Http;
public class VerifierSample
{
public async Task HandleWebhookAsync(HttpRequest request)
{
StringValues value = request.Headers["x-dd-signature"];
if (value.Count != 1)
{
throw new Exception("Signature not exist");
}
string signatureHeader = value.ToString();
string requestBody = await ReadPayloadAsync(request);
if (String.IsNullOrEmpty(requestBody))
{
throw new Exception("Request does not have payload.");
}
const string secret = "kfA18wgZKW30F7dL1JtlHq2judcJ0uoB";
if (!VerifyWebhook(secret, requestBody, signatureHeader))
{
throw new Exception("Invalid signature");
}
// Handle webhook payload.
}
private bool VerifyWebhook(string secret, string requestBody, string signatureHeader)
{
if (!signatureHeader.StartsWith("sha256=", StringComparison.OrdinalIgnoreCase))
{
// handle unknown algorithm
return false;
}
string expectValue = CalculateSha256Signature(secret, requestBody);
return String.Equals(expectValue, signatureHeader, StringComparison.Ordinal);
}
private async Task<string> ReadPayloadAsync(HttpRequest request)
{
request.Body.Position = 0;
using StreamReader reader = new(request.Body);
return await reader.ReadToEndAsync();
}
private string CalculateSha256Signature(string secret, string body)
{
byte[] secretBytes = Encoding.UTF8.GetBytes(secret);
using HMACSHA256 hasher = new(secretBytes);
byte[] bodyBytes = Encoding.UTF8.GetBytes(body);
byte[] sha256Bytes = hasher.ComputeHash(bodyBytes);
return $"sha256={Convert.ToBase64String(sha256Bytes)}";
}
}
Explanation:
- secret: The secret key shared between the sender and receiver.
- requestBody: The raw payload of the incoming HTTP request.
- signatureHeader: The custom header containing the signature.
The VerifyWebhook method takes these inputs, calculates the HMAC-SHA256 hash of the request body using the shared secret, and compares the computed signature with the signature provided in the header. If they match, the method returns true, indicating successful verification.
Conclusion:
Implementing signature verification ensures the integrity and authenticity of incoming webhooks in the Tokity system. By employing this security measure, organisations can trust the data received through webhooks and mitigate potential risks associated with unauthorised access or tampering.