Skip to content

MahmudJewel/FastAPI-Role-based-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI-Role Based Access Control

There are multiple types of user like

  • customer
  • admin
  • vendor
    • They have different access control on the project.

Covered topics

  • Enum types
  • Abstract model like common model
  • RBAC with dependenies and routes.
  • Datetime in SQLAlchemy and Pydantic
  • Alembic = database migrations
  • Alembic = database migrations
  • sqladmin = SQLAlchemy Admin

Developed API

SRL METHOD ROUTE FUNCTIONALITY Required Fields ACCESS
1 POST /auth/token Login user email, password All users
2 POST /auth/users/ Create new user email, password Anyone
3 GET /auth/users/ Get all users list None admin
4 GET /auth/users/me/ Get current user details None authorized
5 GET /auth/users/{user_id} Get indivisual users details None Admin
6 PATCH /auth/users/{user_id} Update the user partially email, password, is_active, role Admin
7 DELETE auth/users/{user_id} Delete the user None admin
8 GET / Home page None anyone
9 GET /admin Admin Dashboard None admin_

Tools

Back-end

Language:

Python (3.11.6)

Frameworks:

FastAPI (0.108.0)
pydantic (2.5.3)

Other libraries / tools:

SQLAlchemy == 2.0.25
starlette == 0.32.0.post1
uvicorn == 0.25.0
python-jose == 3.3.0
alembic == 1.13.1

Database:

SQLite

Setup

The first thing to do is to clone the repository:

$ https://github.com/MahmudJewel/FastAPI-Role-based-auth

Create a virtual environment to install dependencies in and activate it:

$ cd FastAPI-jwt-auth
$ python -m venv venv
$ source venv/bin/activate

Then install the dependencies:

(venv)$ pip install -r requirements.txt

Note the (venv) in front of the prompt. This indicates that this terminal session operates in a virtual environment set up by virtualenv2.

Once pip has finished downloading the dependencies:

(venv)$ uvicorn core.main:app --reload

Happy Coding

From ==> Juwel Mahmud