All Templates / Authentication
Python Authentication API Beta
Python API handles user reg., login, authentication, and profile update.
easy-python-backend-app
CrACK000/easy-python-backend-app
Just deployed
MongoDB
mongo
Just deployed
/data/db
This is a Python Flask application that provides various API routes for user registration, login, and profile update actions.
The application uses MongoDB for storing user data and Flask JWT-Extended for handling JWT-based authentication.
Application configuration variables are declared in a .env file. Here's a sample .env file:
FLASK_APP=app
FLASK_ENV=development
MONGO_URL=mongodb://localhost:27017
MONGO_DB=test
JWT_SECRET_KEY=secret123
Key configuration variables include:
Clone the repository
git clone https://github.com/CrACK000/easy-python-backend-app.git
Install the requirements
pip install -r requirements.txt
Run the application
flask run
Access the apis at http://localhost:5000 to register, login or perform other actions.
This Python Flask API provides different endpoints for managing user registration, login, and profile updates. The API can be tested using different tools like Postman, cURL etc. In this documentation, we demonstrate how to test the API using the Postman tool.
Before testing, ensure that you are running your application locally. Refer to the main README.md for the instructions on how to run the application.
A Postman collection called postman_collection.json is included in the root directory of this project's GitHub repository. This collection includes the requests needed to test the user registration, login, profile checking and profile updates.
To use this collection:
The collection should be imported into Postman, and you can use it to test the different endpoints.
POST
/register
username
password
email
This endpoint is used to register a new user. The request should include username, password and email in the form data.
POST
/login
username
password
This endpoint is used to login a user. The request should include username and password in the form data. On successful login, it returns a JWT access token, remember to replace it with for the following requests.
GET
/checkAuth
Authorization : Bearer
This endpoint is used to verify the user's JWT access token is valid or not. Replace with the token rendered after user login.
PATCH
/updateProfile
Authorization : Bearer
new_username
This endpoint is used to updated the username of the user. Replace with the token rendered after user login. new_username is the username you want to update to.
The JWT token obtained from the /login endpoint will be used in the Authorization header for the /checkAuth and /editProfile requests as Bearer . Note that this token will expire according to the expiration time set in your application (default is 15 minutes), so if your testing takes longer than that, you will need to login again to get a new token.
If the token expires or is otherwise incorrect, the server will respond with a 401 error. This means "unauthorized", so if you see this, you know you need to check your authorization header.
This application is a simple Flask application that has been Dockerized for consistency across different environments.
To build the Docker image, navigate to the directory containing the Dockerfile and run:
docker build -t my-app .
Replace "my-app" with the name you want to assign to the Docker image.
To run the image, enter:
docker run -p 5000:5000 my-app
Replace "my-app" with the name of the Docker image you created. This will start a Docker container from the image and bind it to port 5000.
Once the Docker container is running, you can test the application by navigating to http://localhost:5000 in your web browser.
To stop a running Docker container, first determine the container ID by running:
docker ps
Then, stop the container by running:
docker stop
Replace with the actual container ID.
Remember to stop the Docker container when you're finished to free up system resources.
Template Content
easy-python-backend-app
CrACK000/easy-python-backend-appMongoDB
mongoDetails
CrACK's Projects
Created on Mar 21, 2024
366 total projects
331 active projects
44% success on recent deploys
Python, Dockerfile
Authentication
More templates in this category
Keycloak
Keycloak template with keywind theme + apple and discord providers
beuz's Projects
480
Authorizer
Open-source authentication and authorization solution for your business.
Lakhan Samani's Projects
598