This is a simple user management application built with FastAPI. It allows users to sign up, log in, and view their profiles. The application uses JWT tokens for authentication and stores user data in a database.
- User registration (signup)
- User login with token-based authentication
- Profile viewing
- Basic error handling
- HTML templates for rendering responses
- FastAPI
- SQLAlchemy (for database interactions)
- Jinja2 (for HTML templating)
- OAuth2 (for secure token-based authentication)
- Python 3.x
Make sure you have the following installed:
- Python 3.7 or higher
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/starsden/AuthAPI.git cd AuthAPI -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activatevenv\Scripts\activate
-
Install the required packages:
pip install fastapi[all] sqlalchemy jinja2
-
Initialize the database:
Make sure to implement the
init_db()function in yourmodels.pyto create the necessary tables.
To run the application, use the following command:
uvicorn main:app --reloadThis will start the server at http://127.0.0.1:8000.
-
POST
/signupForm Data:
username: stremail: strpassword: str
Response: Redirects to
/successon successful signup.
-
POST
/tokenForm Data:
username: strpassword: str
Response: Redirects to
/profile?username=<username>on successful login and sets a cookie with the access token.
-
GET
/profile?username=<username>Response: Renders the profile page of the specified user.
-
GET
/successResponse: Renders a success message after signup.
-
GET
/Response: Renders the main index page.
-
GET
/loginResponse: Renders the login page.
Custom error handling can be implemented by uncommenting the exception handler in the code. This will allow rendering of custom error pages for specific HTTP status codes.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to modify any sections as needed, especially regarding installation instructions or any additional features you may want to highlight!