Usage Examples
Note
The user's parmanent_password (passphrase) is only used to get a JWT. All subsequent requests are authenticated using the token in the Authorization header.
1. User Registration & Authentication
# Create a new user (Note: id can be any unique string, e.g., username)
curl -X POST "http://localhost:8000/users" \
-H "Content-Type: application/json" \
-d '{
"id": "alice",
"name": "Alice",
"email": "alice@example.com",
"designation": "Engineer"
}'
# Response includes the one-time permanent password. Save it!
# {
# "id": "alice",
# "name": "Alice",
# ...
# "parmanent_password": "some-generated-secure-passphrase",
# }
# Get an authentication token using the user's ID and permanent password
curl -X POST "http://localhost:8000/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=alice&password=some-generated-secure-passphrase"
2. Document Operations
# Set your JWT for convenience
TOKEN="your-jwt-token-here"
# Upload and share a document with 'bob' and 'charlie'
curl -X POST "http://localhost:8000/documents?share_with=bob&share_with=charlie" \
-H "Authorization: Bearer $TOKEN" \
-F "file=@./report.pdf"
# Share an existing document with 'david'
curl -X PUT "http://localhost:8000/documents/{doc_id}/share?share_with=david" \
-H "Authorization: Bearer $TOKEN"
# Download a document you have access to
curl -X GET "http://localhost:8000/documents/{doc_id}" \
-H "Authorization: Bearer $TOKEN" \
--output downloaded_report.pdf
# Revoke access for 'bob'
curl -X PUT "http://localhost:8000/documents/{doc_id}/revoke?revoke=bob" \
-H "Authorization: Bearer $TOKEN"