Skip to content

Commit 47623ca

Browse files
authored
docs: improved Casdoor webhooks documentation with setup and testing guide (#645)
1 parent ec3e68a commit 47623ca

File tree

1 file changed

+96
-4
lines changed

1 file changed

+96
-4
lines changed

docs/webhooks/overview.md

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,102 @@
11
---
2-
title: Overview
3-
description: Adding Webhooks in Casdoor
4-
keywords: [webhook]
2+
title: Webhooks Overview
3+
description: Configuring Webhooks in Casdoor
54
authors: [huang-yilong]
5+
keywords: [webhook, event-driven, API, integration]
66
---
77

88
## Overview
99

10-
Event systems enable you to create integrations that subscribe to specific events in Casdoor. When one of these events is triggered, a JSON payload will be sent to the configured URL via a POST request. The application will parse the JSON payload and execute the specified function. Events include signup, login, logout, and user updates, all of which are stored in the action field of the record. Event systems can be used to update an external issue from users.
10+
Casdoor provides an event-driven system that allows you to integrate with external applications using webhooks. Webhooks enable real-time communication by sending HTTP `POST` requests with a JSON payload to a configured endpoint whenever a specified event occurs. This allows your application to react to Casdoor events such as user sign-ups, logins, logouts, and profile updates.
11+
12+
## How Webhooks Work
13+
14+
When an event is triggered in Casdoor:
15+
16+
1. Casdoor sends a `POST` request to the specified webhook URL.
17+
2. The request contains a JSON payload with event details.
18+
3. Your application processes the payload and executes relevant actions based on the event type.
19+
20+
### Supported Events
21+
22+
Casdoor webhooks support various user-related events, which are stored in the `action` field of the request payload.
23+
24+
| Event | Description |
25+
|------------|-------------------------------------------------|
26+
| `signup` | Triggered when a user signs up |
27+
| `login` | Triggered when a user logs in |
28+
| `logout` | Triggered when a user logs out |
29+
| `update` | Triggered when user details are updated |
30+
31+
## Setting Up a Webhook
32+
33+
To configure a webhook in Casdoor:
34+
35+
1. **Navigate to the Casdoor Webhooks Section:**
36+
- Open your Casdoor instance.
37+
- Go to **Settings** > **Webhooks**.
38+
39+
2. **Create a New Webhook:**
40+
- Click on **Add Webhook**.
41+
- Enter the **Webhook URL** where Casdoor should send event data.
42+
- Select the events you want to listen to (e.g., `signup`, `login`).
43+
- (Optional) Add custom headers for authentication.
44+
45+
3. **Save the Webhook Configuration:**
46+
- Once saved, Casdoor will start sending event notifications to the specified endpoint.
47+
48+
## Example Webhook Payload
49+
50+
Here’s an example of a JSON payload sent to your webhook when a user logs in:
51+
52+
```json
53+
{
54+
"event": "login",
55+
"timestamp": 1709452800,
56+
"user": {
57+
"id": "12345",
58+
"username": "johndoe",
59+
"email": "[email protected]"
60+
}
61+
}
62+
```
63+
64+
Your application should parse this payload and perform necessary actions, such as logging the event or notifying another service.
65+
66+
## Testing Your Webhook
67+
68+
Before deploying your webhook integration, you can test it using tools like:
69+
70+
- **[Beeceptor](https://beeceptor.com/)** – Allows you to create a custom webhook URL and inspect incoming requests.
71+
- **[Webhook.site](https://webhook.site/)** – Provides an instant webhook endpoint for testing.
72+
73+
### Example Test with Beeceptor
74+
75+
1. Visit [Beeceptor](https://beeceptor.com/) and create a new endpoint.
76+
2. Copy the generated webhook URL and configure it in Casdoor.
77+
3. Trigger a test event (e.g., log in to Casdoor).
78+
4. Check Beeceptor’s dashboard to inspect the received request.
79+
80+
## Handling Webhooks in Your Application
81+
82+
Your server should be able to process incoming webhook requests. Below is a simple example in Node.js:
83+
84+
```javascript
85+
const express = require('express');
86+
const app = express();
87+
88+
app.use(express.json());
89+
90+
app.post('/webhook', (req, res) => {
91+
console.log('Received webhook:', req.body);
92+
res.status(200).send('Webhook received');
93+
});
94+
95+
app.listen(3000, () => console.log('Server running on port 3000'));
96+
```
97+
98+
## Conclusion
99+
100+
Casdoor webhooks provide a powerful way to integrate with external applications by enabling event-driven interactions. Whether you need to sync user data, trigger notifications, or update external systems, webhooks allow seamless automation.
101+
102+
To ensure a smooth integration, always validate incoming requests and test your webhooks with tools like Beeceptor or Webhook.site before deploying them in production.

0 commit comments

Comments
 (0)