APIAuth is a secure authentication API built with Django REST Framework, utilizing JSON Web Tokens (JWT) for authentication, CORS headers for cross-origin requests, and SQLite3 as the database. This project provides a robust foundation for user authentication and authorization in web applications, allowing users to log in using their email or phone number and password.
- User registration and login with JWT-based authentication
- Secure token-based access control
- Cross-Origin Resource Sharing (CORS) support for frontend integration
- Lightweight SQLite3 database for easy setup and development
- RESTful API endpoints for user management
- Django REST Framework: For building the API
- JWT (JSON Web Tokens): For secure authentication
- django-cors-headers: To handle CORS requests
- SQLite3: Default database for simplicity and portability
- Python: Core programming language
-
Clone the repository:
git clone https://github.com/Nau-stack-110/authapi.git cd authapi
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Apply migrations:
python manage.py makemigrations python manage.py migrate
-
Run the development server:
python manage.py runserver
The API will be available at
http://localhost:8000
.
- JWT Settings: Configure JWT settings in
settings.py
(e.g., token expiration, secret key). - CORS: Adjust allowed origins in
settings.py
underCORS_ALLOWED_ORIGINS
for your frontend. - Database: SQLite3 is used by default. For production, consider switching to PostgreSQL or another database.
Endpoint | Method | Description |
---|---|---|
/register/ |
POST | Register a new user |
/token/ |
POST | Login and receive JWT tokens |
/token/refresh/ |
POST | Refresh JWT access token |
/api/me/ |
GET | List user (authenticated) |
Example request for login:
curl -X POST http://localhost:8000/token/ -d "username=youremailortel&password=yourpassword"
See requirements.txt
for a full list of dependencies. Key packages include:
django
djangorestframework
djangorestframework-simplejwt
django-cors-headers
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -m "Add your feature"
) - Push to the branch (
git push origin feature/your-feature
) - Open a pull request
This project is licensed under the MIT License. See the LICENSE
file for details.