This is a FastAPI starter code for setting up authentication quickly and efficiently. It provides a flexible solution that can be adapted to various types of applications, from small projects to complex SaaS products.
- Quick setup for user authentication
- Flexible enough to work with different kinds of apps
- Supports multiple authentication providers (Google, GitHub, LinkedIn)
- Customizable to fit your specific needs
- Includes
pytestfor authentication testing
- Python 3.7+
- FastAPI
- SQLite (or any other database supported by SQLAlchemy)
- pytest (for running tests)
Clone the repository:
git clone https://github.com/ialim0/fastapi-starter
cd fastapi-auth-starterInstall the required dependencies:
pip install -r requirements.txtCreate a .env file in the root directory of the project and add the following environment variables:
SECRET_KEY=your_secret_key
DATABASE_URL=sqlite:///./test.db
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI="http://127.0.0.1:8000/auth/google/callback"
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GITHUB_REDIRECT_URI="http://127.0.0.1:8000/auth/github/callback"
LINKEDIN_CLIENT_ID=your_linkedin_client_id
LINKEDIN_CLIENT_SECRET=your_linkedin_client_secret
LINKEDIN_REDIRECT_URI="http://127.0.0.1:8000/auth/linkedin/callback"Start the FastAPI server:
uvicorn main:app --reloadOpen your browser and navigate to http://127.0.0.1:8000 to see the application in action.
This starter code supports multiple authentication providers:
- Google: Use the
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET, andGOOGLE_REDIRECT_URIenvironment variables to configure Google authentication. - GitHub: Use the
GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET, andGITHUB_REDIRECT_URIenvironment variables to configure GitHub authentication. - LinkedIn: Use the
LINKEDIN_CLIENT_ID,LINKEDIN_CLIENT_SECRET, andLINKEDIN_REDIRECT_URIenvironment variables to configure LinkedIn authentication.
The starter code is designed to be flexible and customizable. You can easily adapt it to fit the specific needs of your application. Whether you're handling standard login/password systems or more complex roles and permissions, this starter code can give you a jump start.
This project includes pytest for testing the authentication functionality. To run the tests, follow these steps:
Ensure you have pytest installed:
pip install pytestRun the tests:
pytestThe tests are located in the tests directory. You can add more tests as needed to ensure the robustness of your authentication system.
We welcome contributions to this project! If you have suggestions, improvements, or bug fixes, please feel free to open an issue or submit a pull request. Your contributions help make this project better for everyone.
This project is licensed under the MIT License. See the LICENSE file for details.
Thanks to the FastAPI community for their excellent documentation and support.
Special thanks to the maintainers of the libraries used in this project.