{"id":50928361,"url":"https://github.com/persteenolsen/fastapi-jwt-auth-mongo-render-two","last_synced_at":"2026-06-17T01:31:10.266Z","repository":{"id":360699377,"uuid":"1251268125","full_name":"persteenolsen/fastapi-jwt-auth-mongo-render-two","owner":"persteenolsen","description":"Python and FastAPI with JWT Auth hosted at Render using MongoDB at Atlas","archived":false,"fork":false,"pushed_at":"2026-05-27T14:27:35.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-27T15:12:25.862Z","etag":null,"topics":["fastapi","jwt","mongodb","python","render"],"latest_commit_sha":null,"homepage":"https://fastapi-jwt-auth-mongo-render-two.onrender.com/docs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/persteenolsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-27T12:10:46.000Z","updated_at":"2026-05-27T14:37:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/persteenolsen/fastapi-jwt-auth-mongo-render-two","commit_stats":null,"previous_names":["persteenolsen/fastapi-jwt-auth-mongo-render-two"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/persteenolsen/fastapi-jwt-auth-mongo-render-two","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-mongo-render-two","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-mongo-render-two/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-mongo-render-two/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-mongo-render-two/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/persteenolsen","download_url":"https://codeload.github.com/persteenolsen/fastapi-jwt-auth-mongo-render-two/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-mongo-render-two/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34430688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","jwt","mongodb","python","render"],"created_at":"2026-06-17T01:31:09.676Z","updated_at":"2026-06-17T01:31:10.245Z","avatar_url":"https://github.com/persteenolsen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 FastAPI Auth System (JWT + MongoDB + bcrypt)\n\nLast updated:\n\n- 03-06-2026\n\n# Version\n\nAt Render I use the PYTHON_VERSION environment variable to tell Render to use Python version 3.11. Locally I am using Python 3.12\n\nA production-ready authentication backend built with **FastAPI**, **MongoDB Atlas**, **JWT authentication**, and **bcrypt password hashing**, deployed on **Render**.\n\n---\n\n## 📌 Overview\n\nThis project provides a secure backend API with:\n\n- 🔐 User authentication (JWT-based)\n- 🧂 Secure password hashing (bcrypt)\n- 🗄️ MongoDB Atlas integration (async via Motor)\n- ☁️ Render deployment ready\n- 🧪 Development mode toggle (`DEV_MODE`)\n- ⚡ High-performance async API using FastAPI\n\n---\n\n## ⚙️ Tech Stack\n\n- **Backend:** FastAPI  \n- **Database:** MongoDB Atlas  \n- **Driver:** Motor (async MongoDB driver)  \n- **Auth:** JWT (python-jose)  \n- **Security:** bcrypt password hashing  \n- **Server:** Uvicorn / Render  \n\n---\n\n## 📂 Features\n\n### 🔐 Authentication\n- Register users (dev-only endpoint)\n- Login with username \u0026 password\n- JWT token generation (30 min expiry)\n- Protected routes with Bearer token\n\n### 🗄️ Database\n- MongoDB Atlas integration\n- Async database operations (Motor)\n- Secure user storage with hashed passwords\n\n### 🛡️ Security\n- bcrypt hashed passwords (no plaintext storage)\n- JWT-based authentication\n- Environment-based configuration\n- DEV_MODE protection for sensitive endpoints\n\n---\n\n## 📁 Project Structure\n\napp.py\n\nrequirements.txt\n\n.env\n\n### 🔑 Environment Variables\n\nCreate a .env file:\n\nATLAS_URI=mongodb+srv://\u003cuser\u003e:\u003cpassword\u003e@cluster.mongodb.net/\nDB_NAME=your_db_name\nCOLLECTION_NAME=users\n\nSECRET_KEY=your_secret_key\nALGORITHM=HS256\n\nDEV_MODE=true\n\n⚠️ Set DEV_MODE=false on Render for production.\n\n## 🚀 Installation\n\n### 1. Clone the repository\n\ngit clone https://github.com/your-username/fastapi-auth-mongo.git  \ncd fastapi-auth-mongo  \n\n---\n\n### 2. Create virtual environment\n\npython -m venv venv  \nsource venv/bin/activate   # macOS/Linux  \nvenv\\Scripts\\activate      # Windows  \n\n---\n\n### 3. Install dependencies\n\npip install -r requirements.txt  \n\n---\n\n### 4. Run locally\n\nuvicorn app:app --reload  \n\n---\n\nAPI will be available at:\n\nhttp://127.0.0.1:8000  \n\nSwagger docs:\n\nhttp://127.0.0.1:8000/docs  \n\n---\n\n## 🔐 API Endpoints\n\n### 🟢 Health Check\n\nGET /health  \n\nResponse:\n{\n  \"status\": \"ok\"\n}\n\n---\n\n### 🧑 Create User (DEV ONLY)\n\nPOST /create-user  \n\nRequest body:\n{\n  \"username\": \"testuser\",\n  \"password\": \"admin123\"\n}\n\nResponse:\n{\n  \"message\": \"User created (DEV MODE)\",\n  \"user_id\": \"mongodb_object_id\"\n}\n\n🚨 Disabled automatically when DEV_MODE=false  \n\n---\n\n### 🔑 Login (Get Token)\n\nPOST /token  \n\nForm data:\nusername=testuser  \npassword=admin123  \n\nResponse:\n{\n  \"access_token\": \"JWT_TOKEN_HERE\",\n  \"token_type\": \"bearer\"\n}\n\n---\n\n### 🔒 Protected Route\n\nGET /protected  \n\nHeaders:\nAuthorization: Bearer JWT_TOKEN_HERE  \n\nResponse:\n{\n  \"message\": \"Hello testuser\"\n}\n\n---\n\n## 🧪 Development Mode\n\nDEV_MODE controls whether user creation is allowed.\n\nMode | Behavior\n-----|---------\ntrue | /create-user enabled\nfalse | /create-user blocked (403)\n\n---\n\n## ☁️ Deployment (Render)\n\n### Build Command\n\npip install -r requirements.txt  \n\n### Start Command\n\nuvicorn app:app --host 0.0.0.0 --port 10000  \n\n### Environment Variables (Render Dashboard)\n\nATLAS_URI\n\nDB_NAME\n\nCOLLECTION_NAME\n\nSECRET_KEY\n\nALGORITHM\n\nDEV_MODE=false  \n\n---\n\n## 🔐 Security Notes\n\n- Passwords are hashed using bcrypt (salted)\n- JWT tokens expire after 30 minutes\n- No plaintext passwords stored\n- DEV endpoints disabled in production\n\n---\n\n## 📈 Future Improvements\n\n- 🔁 Refresh tokens  \n- 🚪 Logout / token revocation  \n- ⚖️ Role-based access control (RBAC)  \n- 🚦 Rate limiting login attempts  \n- 📧 Email verification  \n- 🧠 Password strength validation  \n\n---\n\n## 👨‍💻 Author\n\nBuilt with FastAPI, MongoDB, and bcrypt for secure backend authentication systems.\n\n---\n\n## ⭐ License\n\nMIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-mongo-render-two","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-mongo-render-two","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-mongo-render-two/lists"}