Demonstration: https://drive.google.com/drive/u/0/folders/1IOAupRokQvc6zpEiNif99iOT2pcD7Vnl
This is a Django project that serves as a base model to build Django back-end APIs that require token and social media authentication. It utilizes Django Rest Framework and django-rest-auth.
The compatible front-end application can be found here.
- Prerequisites
- Project Description
- Run The Project
- Versions
- Why I Built This
- How I Built This
- API Endpoints
To thoroughly comprehend this solution, it is highly recommended to have a strong understanding of the following:
- Django
- Django Rest Framework, also known as DRF
- django-rest-auth
- Token authentication
This project covers the essential authentication functionalities of a back-end API that uses token authentication, which can be found here, and will eventually support social media authentication. The CustomUser is set as the authentication user model, which builds off of Django's usual user model, to allow developers to add extra user data (e.g. user's occupation or country of residence).
mkdir token_authcd token_authpython3 -m venv envsource env/bin/activatepip install --upgrade pippip3 install django && pip3 install djangorestframework && pip3 install django-rest-auth && pip3 install django-allauthgit clone https://github.com/ymoondhra/django-token-basecd django-token-basepython3 manage.py runserverpython3 manage.py makemigrations && python3 manage.py migrate- Navigate to http://localhost:8000/api/v1/rest-auth/login/
| # | Functionality Additions | Compatible with Front-End Version # |
|---|---|---|
| 1 | Support for endpoints found below with test cases | 1 |
| # | Functionality Additions | Compatible with Front-End Version # |
|---|---|---|
| 2 | Use email address as username | - |
| 3 | Support social media account authentication and creation | - |
In my experiences with full-stack applications, I have noticed how I have to rebuild the same functionalities every time (e.g. authentication), often having to look back at previous projects I have created. I want to minimize the amount of time developers spend on the repetitive aspects of creating a back-end API for full-stack applications.
Moreover, I want developers to be able to pull different versions (a.k.a. releases) of this project for the different functionalities they need. For example, If someone wants to build a back-end API that allows users to log in with Facebook or log in with their actual username, a developer may pull down only Version 3.0.0, which is the first version that has the Facebook login feature. However, Version 3.0.0 uses email to login/logout instead of username. Therefore, the best approach would be to pull down the directories of Version 1.0.0 (which uses username) and Version 3.0.0, compare the code, and use the helpful comments within the code to decide what code to remove.
For the developers who would prefer to start from scratch but use this project for reference, the section below outlines how I went about coding this API.
All versions can be found here.
Overall Coding Structure
1. Build Users app
2. Build Api app
Individual App Coding Structure
1. Start app with command line
2. Build models
3. Build serializers
4. Build views
5. Attach to URLs
6. Update settings.py as needed
7. Migrate
8. Configure admin: create superuser in command prompt and Add Site in admin website
Project Deployment
(OPTIONAL). Hide secret key
1. Create requirements.txt using pip freeze
2. Push token_auth and README.md to GitHub (not env folder)
All of these API endpoints are supported except the social media endpoints