This repository contains a secure file-sharing REST API built using FastAPI. It supports role-based access control, JWT authentication, and secure one-time download links, ensuring safe delivery of files between operation users and clients.
- Language: Python 3
- Framework: FastAPI
- Authentication: JWT (OAuth2), Role-based (Ops, Client)
- Encryption: Fernet (used for secure email verification tokens)
- Data Storage: In-memory (Python dictionaries for simplicity)
- API Testing: Postman (collection included)
- Package Management: pip (
requirements.txt)
secure_file_sharing/
├── main.py # Main application file
├── .env # Environment configuration
├── requirements.txt # Python dependencies
├── SecureFileSharingAPI.postman_collection.json # Postman collection
└── README.md # Project documentation
- 🔐 User registration with role selection (
client,ops) - 📧 Email verification using a secure Fernet token
- 🔑 JWT-based login and token-based authorization
- 📤 Upload capability for operations team only
- 📂 File listing and downloading for verified clients
- 🔗 Secure one-time download links for files
- 📊 Simulated download tracking per client
git clone https://github.com/pinnu1/file_sharing.git
cd secure_file_sharingpip install -r requirements.txtCreate a .env file in the project root with the following keys:
SECRET_KEY=your_jwt_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
FERNET_KEY=your_fernet_key_hereGenerate a Fernet key using:
from cryptography.fernet import Fernet
print(Fernet.generate_key().decode())uvicorn main:app --reloadAccess the API at:
📎 http://127.0.0.1:8000/docs
| Method | Endpoint | Access Role | Description |
|---|---|---|---|
| POST | /signup |
Public | Register a new user |
| GET | /verify-email/{token} |
Public | Verify user's email |
| POST | /login |
Public | User login and receive JWT token |
| POST | /upload |
Ops only | Upload files |
| GET | /list-files |
Client only | View list of uploaded files |
| GET | /download-file/{file_id} |
Client only | Generate a secure file download link |
| GET | /secure-download/{token} |
Client only | One-time download using token |
| GET | /download-history |
Client only | View download history (simulated) |
-
Open Postman and import the collection:
SecureFileSharingAPI.postman_collection.json -
Test the API by following this flow:
- ➕ Sign Up using
/signup - 📧 Verify Email using
/verify-email/{token} - 🔐 Login via
/loginand capture theaccess_token - 📤 Upload Files as an
opsuser - 📥 List & Download Files as a
clientuser
- ➕ Sign Up using
Created and maintained by Prashant Garg
📧 Email: aprashant703@gmail.com
💼 GitHub: https://github.com/pinnu1