Skip to content

Latest commit

 

History

History
117 lines (99 loc) · 4.52 KB

File metadata and controls

117 lines (99 loc) · 4.52 KB

Casdoor Dify Plugin

Overview

The Casdoor Dify Plugin integrates Casdoor OAuth-based authentication into the Dify ecosystem as an extension plugin. It provides endpoints to handle OAuth login, signup, and callback flows, enabling seamless user authentication via Casdoor.

Features

  • OAuth Authentication:
    Implements login, signup, and callback endpoints to facilitate the Casdoor OAuth flow.
  • Dify Plugin Integration:
    Uses a plugin manifest and endpoint YAML definitions to register the plugin with Dify.
  • Environment-Based Configuration:
    Loads sensitive credentials (certificates, client IDs, secrets, etc.) from a .env file.
  • Local Testing with Flask:
    Includes a Flask-based server (main.py) for local development and testing.

Project Structure

.
├── GUIDE.md                   # Quick start guide for plugin development
├── README.md                  # Project documentation
├── _assets
│   └── icon.svg               # Plugin icon asset
├── endpoints
│   ├── casdoor_auth.py         # Casdoor OAuth logic implementation
│   ├── casdoor_login.yaml      # Endpoint manifest for login
│   ├── casdoor_signup.yaml     # Endpoint manifest for signup
│   └── casdoor_callback.yaml   # Endpoint manifest for callback
├── main.py                    # Entry point for local testing (Flask server)
├── manifest.yaml              # Plugin manifest for Dify integration
└── requirements.txt           # Python dependencies list

Prerequisites

  • Python: Version 3.12 or higher.
  • Poetry: For dependency management. (Installation Guide)
  • Dify Plugin Scaffolding Tool: (Optional) For further development and testing on the Dify platform.
  • Environment Variables: A .env file containing your Casdoor credentials is required.

Installation

  1. Clone the Repository:
    git clone <repository-url>
    cd casdoor-dify-plugin
  2. Install Dependencies:
    poetry install

Configuration

Create a .env file in the project root and populate it with your Casdoor credentials:

# Casdoor Configuration
CASDOOR_CERT="-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----"
CASDOOR_ENDPOINT=https://your-casdoor-endpoint.example
CASDOOR_CLIENT_ID=your_client_id
CASDOOR_CLIENT_SECRET=your_client_secret
CASDOOR_ORG_NAME=your_organization_name
CASDOOR_APP_NAME=your_app_name

# Installation Configuration
INSTALL_METHOD=remote
REMOTE_INSTALL_HOST=debug.dify.ai
REMOTE_INSTALL_PORT=5003
REMOTE_INSTALL_KEY=********-****-****-****-************

# Database Configuration
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=your_db_port
DB_NAME=your_db_name

# Shared Secret for Generating Dify Tokens
SECRET_KEY=your_secret_key

# Redis Configuration
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
REDIS_PASSWORD=your_redis_password
REDIS_DB=your_redis_db

Running the Plugin Locally

For local testing, run the Flask server with:

poetry run python main.py

This starts the server on http://0.0.0.0:8000.

Testing the Endpoints

Dify Plugin Integration

This repository is structured as a Dify extension plugin:

  • Manifest File (manifest.yaml):
    Contains metadata and required permissions for plugin registration with Dify.
  • Endpoint YAML Files (in endpoints/):
    Define the API paths and HTTP methods for login, signup, and callback endpoints.

For more details on developing and integrating plugins with Dify, please refer to the Dify Plugin Documentation.

Contributing

Contributions are welcome! Fork the repository and submit pull requests for any improvements. For significant changes, please open an issue to discuss your ideas first.

License

This project is licensed under the MIT License.

Contact

For questions or support, please contact Mohammad Fotouhi.