Notification Providers
Relevant source files
The following files were used as context for generating this wiki page:
Notification Providers in Casdoor represent a modular system designed to facilitate communication between the IAM platform and external messaging services. These providers allow the system to dispatch alerts, verification codes, and administrative notifications (such as SSO logout events) to various third-party platforms like Telegram, Slack, and Discord.
The architecture relies on a factory pattern to instantiate specific provider clients based on configuration, ensuring that the core system remains decoupled from the specific implementation details of each messaging API.
Sources: notification/provider.go, object/notification.go:41-48
Core Architecture and Data Flow
The system architecture consists of a backend factory that generates notifier clients and a frontend interface for configuration. When a notification is triggered, the system retrieves the provider details, instantiates the appropriate client via the notification package, and executes the delivery.
Notification Dispatch Process
The backend logic for sending notifications is primarily handled in object/notification.go. The function GetNotificationProvider acts as the primary factory, accepting parameters such as ClientId, ClientSecret, and Metadata to return an object conforming to the notify.Notifier interface.
This diagram illustrates how the GetNotificationProvider factory routes requests to specific provider implementations.
Sources: notification/provider.go:19-54, object/notification.go:27-39
Supported Provider Types
Casdoor supports a wide array of notification services. Each provider requires a specific set of credentials and configuration parameters.
| Provider Type | Key Configuration Fields | Implementation Source |
|---|---|---|
| Telegram | ClientSecret (Token), Receiver (Chat ID) | notification/provider.go:21 |
| Slack | ClientSecret (Webhook URL), Receiver | notification/provider.go:37 |
| WeCom | ClientSecret (Webhook URL) | notification/wecom.go:38 |
ClientId, ClientSecret, Username, Password, Receiver | notification/reddit.go:22 | |
| Custom HTTP | Receiver (URL), Method (GET/POST), Title (Param) | notification/provider.go:23 |
| Discord | ClientSecret (Webhook URL), Receiver | notification/provider.go:41 |
| Lark | ClientSecret (Webhook URL) | notification/provider.go:27 |
Sources: notification/provider.go:19-54, web/src/Setting.js:283-348
SSO Logout Notifications
A critical use case for Notification Providers is the targeted session-level Single Sign-On (SSO) logout. When a user logs out, Casdoor can send signed notifications to all configured notification providers associated with the user's application.
Logout Notification Payload
The SsoLogoutNotification struct contains user identity, session information, and security headers to prevent replay attacks.
| Field | Type | Description |
|---|---|---|
Event | string | Fixed to sso-logout |
SessionIds | []string | List of session IDs being terminated |
Nonce | string | Random unique ID for replay protection |
Timestamp | int64 | Unix timestamp of notification generation |
Signature | string | HMAC-SHA256 hash of the payload for verification |
Sources: object/notification.go:50-71
Signature Verification Flow
To ensure the authenticity of the logout request, the system generates a signature using the Application's ClientSecret.
This sequence shows the secure delivery and verification of logout events across the notification infrastructure.
Sources: object/notification.go:107-133, object/notification.go:165-176
UI Configuration and Testing
The frontend provides specialized fields for configuring each notification provider type.
Implementation Details
- Configuration Component:
renderNotificationProviderFieldsdynamically renders inputs forregionId,method,metadata, andtitlebased on the provider type. - Testing Interface: The
Send Testing Notificationbutton triggers an API call to/api/send-notification.
Sources: web/src/provider/NotificationProviderFields.js:27-84, web/src/common/TestNotificationWidget.js:33-42
API Endpoint Summary
The system exposes several REST API endpoints for managing and utilizing these providers as defined in the Swagger specification.
| Method | Endpoint | Description |
|---|---|---|
POST | /api/add-provider | Create a new notification provider |
GET | /api/get-providers | List all providers for an organization |
POST | /api/send-notification | Dispatch a notification via a specific provider |
Sources: swagger/swagger.yml:256-271, swagger/swagger.yml:955-971, swagger/swagger.yml:1481-1498
Conclusion
Notification Providers serve as the communication backbone for Casdoor, enabling integration with modern messaging platforms. By supporting standard webhook formats (Slack, Discord, WeCom) and custom HTTP requests, the system ensures flexibility for diverse administrative and security notification requirements, most notably in secure SSO session management.