{"id":24915195,"url":"https://github.com/rennf93/two-fast-auth","last_synced_at":"2025-04-14T17:54:37.333Z","repository":{"id":275346565,"uuid":"925321996","full_name":"rennf93/two-fast-auth","owner":"rennf93","description":"FastAPI middleware that provides seamless two-factor authentication implementation. It integrates with FastAPI to offer robust 2FA protection for your application routes.","archived":false,"fork":false,"pushed_at":"2025-03-08T11:03:19.000Z","size":792,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T04:38:20.321Z","etag":null,"topics":["2fa","fastapi","middleware","python","security"],"latest_commit_sha":null,"homepage":"https://rennf93.github.io/two-fast-auth/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rennf93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rennf93","tidelift":"pypi/two-fast-auth","custom":["https://paypal.me/renzof93"]}},"created_at":"2025-01-31T16:52:55.000Z","updated_at":"2025-04-06T02:03:21.000Z","dependencies_parsed_at":"2025-02-19T12:03:53.032Z","dependency_job_id":"a50a7628-ac24-488e-b14b-97fb4ebfa44c","html_url":"https://github.com/rennf93/two-fast-auth","commit_stats":null,"previous_names":["rennf93/two-fast-auth"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennf93%2Ftwo-fast-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennf93%2Ftwo-fast-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennf93%2Ftwo-fast-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rennf93%2Ftwo-fast-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rennf93","download_url":"https://codeload.github.com/rennf93/two-fast-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248931908,"owners_count":21185263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["2fa","fastapi","middleware","python","security"],"created_at":"2025-02-02T07:16:39.065Z","updated_at":"2025-04-14T17:54:37.308Z","avatar_url":"https://github.com/rennf93.png","language":"Python","funding_links":["https://github.com/sponsors/rennf93","https://tidelift.com/funding/github/pypi/two-fast-auth","https://paypal.me/renzof93"],"categories":[],"sub_categories":[],"readme":"![Two-Fast-Auth Logo](docs/assets/big_logo.svg)\n\n---\n\n[![PyPI version](https://badge.fury.io/py/two-fast-auth.svg?cache=none\u0026icon=si%3Apython\u0026icon_color=%23008cb4)](https://badge.fury.io/py/two-fast-auth)\n[![Release](https://github.com/rennf93/two-fast-auth/actions/workflows/release.yml/badge.svg)](https://github.com/rennf93/two-fast-auth/actions/workflows/release.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![CI](https://github.com/rennf93/two-fast-auth/actions/workflows/ci.yml/badge.svg)](https://github.com/rennf93/two-fast-auth/actions/workflows/ci.yml)\n[![CodeQL](https://github.com/rennf93/two-fast-auth/actions/workflows/code-ql.yml/badge.svg)](https://github.com/rennf93/two-fast-auth/actions/workflows/code-ql.yml)\n[![Docs Update](https://github.com/rennf93/two-fast-auth/actions/workflows/docs.yml/badge.svg)](https://github.com/rennf93/two-fast-auth/actions/workflows/docs.yml)\n[![Downloads](https://pepy.tech/badge/two-fast-auth)](https://pepy.tech/project/two-fast-auth)\n\n`two-fast-auth` is a FastAPI middleware that provides seamless two-factor authentication implementation. It integrates with FastAPI to offer robust 2FA protection for your application routes.\n\n---\n\n## Documentation\n\n📚 [Full Documentation](https://rennf93.github.io/two-fast-auth/) - Comprehensive technical documentation and API reference\n\n## Features\n\n- **QR Code Generation**: Automatic QR code creation for authenticator apps\n- **TOTP Verification**: Time-based one-time password validation\n- **Recovery Codes**: Secure recovery code generation and management\n- **Optional Secret Encryption**: Securely store and verify 2FA secrets\n- **Middleware Integration**: Easy integration with FastAPI routes\n\n## Installation\n\nTo install `two-fast-auth`, use pip:\n```bash\npip install two-fast-auth\n```\n\n## Basic Usage\n\n```python\nfrom fastapi import FastAPI\nfrom two_fast_auth import TwoFactorMiddleware, TwoFactorAuth\n\napp = FastAPI()\n\nasync def get_user_secret(user_id: str) -\u003e str:\n    # Implement your logic to retrieve user's secret from database\n    return \"user_stored_secret\"  # Replace with actual DB lookup\n\napp.add_middleware(\n    TwoFactorMiddleware,\n    get_user_secret_callback=get_user_secret,\n    excluded_paths=[\"/docs\", \"/redoc\"],\n    header_name=\"X-2FA-Code\",\n    encryption_key=\"your-key-here\"  # Optional\n)\n\n@app.get(\"/protected-route\")\nasync def protected_route():\n    return {\"message\": \"2FA protected content\"}\n```\n\n## Configuration Options\n\n### TwoFactorAuth Parameters\n\n| Parameter           | Default      | Description                                                                 |\n|---------------------|--------------|-----------------------------------------------------------------------------|\n| `secret`            | Auto-generated| Base32 secret for TOTP generation                                          |\n| `qr_fill_color`     | \"black\"      | QR code foreground color                                                    |\n| `qr_back_color`     | \"white\"      | QR code background color                                                    |\n| `issuer_name`       | \"2FastAuth\"  | Name displayed in authenticator apps                                        |\n\n### TwoFactorMiddleware Parameters\n\n| Parameter           | Default              | Description                                                                 |\n|---------------------|----------------------|-----------------------------------------------------------------------------|\n| `encryption_key`    | None                 | Encryption key for securing 2FA secrets (Fernet-compatible key)            |\n| `excluded_paths`    | [\"/login\", \"/setup-2fa\"] | Paths that bypass 2FA verification                                  |\n| `header_name`       | \"X-2FA-Code\"         | Request header containing 2FA verification code                             |\n\n## Advanced Configuration\n\n```python\n# Generate and encrypt secret\nsecret = TwoFactorAuth().secret\nencrypted_secret = TwoFactorAuth.encrypt_secret(\n    secret,\n    encryption_key=\"your-key-here\"\n)\n\n# Store encrypted secret in database\nasync def get_user_secret(user_id: str) -\u003e str:\n    return await fetch_encrypted_secret_from_db(user_id)\n\n# Middleware with encrypted secrets\napp.add_middleware(\n    TwoFactorMiddleware,\n    get_user_secret_callback=get_user_secret,\n    encryption_key=\"your-key-here\",\n    excluded_paths=[\"/healthcheck\"]\n)\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nMIT License - See [LICENSE](https://github.com/rennf93/two-fast-auth/blob/main/LICENSE) for details\n\n## Author\n\n**Renzo Franceschini**\n- [GitHub Profile](https://github.com/rennf93)\n- [Email](mailto:rennf93@gmail.com)\n\n## Acknowledgements\n\n- [Cryptography](https://cryptography.io/)\n- [FastAPI](https://fastapi.tiangolo.com/)\n- [PyOTP](https://pyauth.github.io/pyotp/)\n- [qrcode](https://github.com/lincolnloop/python-qrcode)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frennf93%2Ftwo-fast-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frennf93%2Ftwo-fast-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frennf93%2Ftwo-fast-auth/lists"}