Skip to content

A authentication template written in flask.

Notifications You must be signed in to change notification settings

MalonzaElkanah/Flask-Auth-Template

Repository files navigation

Flask API - AUTH Template

Table of Contents

Features

Implemented

  1. create user

  2. Confirm Email

  3. Resend Email Confirmation link

  4. Login (get refresh token and access token)

  5. Get new Access Token from Refresh Token

  6. Revoke tokens

  7. change password

  8. forgot password

  9. CRUD Roles (Admin)

  10. List, Read, Delete Users (Admin)

Todo

  • User Activity Logs
  • login with socials (google, fb, twitter, etc)
  • Phone SMS login
  • PIN Auth
  • Finger-print Auth
  • 2 Way Authentication
  • Face Recognition auth

Installation Guide

Dependacies Installation

  • Installing the application locally requires
    1. Python 3.7+ - download and install it.
    2. virtualenv - To create a virtual environment and activate it, run the following commands.
     python3 -m venv venv
     source venv/bin/activate
  • Install the project dependacies from requirements.txt by running the following command in shell:
pip install -r requirements.txt 
  • The project contains a .env.sample file at its root with the environment variables required to run the app. Copy the file and name it .env, populating it with the correct values.

Database Initialization

  • This Flask application needs a PostgreSQL database to store data. Create a database for this project, get the Database Name, Port, host, username and password and add it to .env file as shown in .env.sample file.
  • Run the following commands to set-up(create tables for the project) the database using Flask-Migrate:
flask db init
flask db migrate -m 'set-up the db'
flask db upgrade
  • If this is your first time setting up, you will need initial data seeded to your database. Run the following command to-do so:
flask seed

Testing and Running Guide

  1. To activate the development server run:
export FLASK_DEBUG=True
flask run

At this point, the development server should be accessible at http://localhost:5000/

  1. Testing - To run all the tests:
python -m pytest -v

API Documentation

Key Python Modules Used

  • Flask: micro-framework for web application development which includes the following dependencies:
    • click: package for creating command-line interfaces (CLI)
    • itsdangerous: cryptographically sign data
    • Jinja2: templating engine
    • MarkupSafe: escapes characters so text is safe to use in HTML and XML
    • Werkzeug: set of utilities for creating a Python application that can talk to a WSGI server
  • pytest: framework for testing Python projects
  • Flask-SQLAlchemy - ORM (Object Relational Mapper) for Flask
  • Flask-Migrate - An extension that handles SQLAlchemy database migrations for Flask applications using Alembic.
  • Flask-RESTful - An extension for Flask that adds support for quickly building REST APIs.
  • Marshmallow - A framework for Object/Model Validation, serialization and deserialization.
  • Flask-JWT-Extended - An extension for managing JSON Web Tokens.
  • psycopg2 - PostgreSQL database adapter for the Python programming language.
  • flasgger, apispec - a Flask extension to extract OpenAPI-Specification from all Flask views registered in your API.
  • flake8 - static analysis tool

Reference Resources

About

A authentication template written in flask.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published