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