Posts

Showing posts from July, 2025

Authenticate a User

Image
Authentication auth.py modification to show it as a basic example to understand it. # This file is to define authenticator and authorization for the Todo application. # python-multipart is the package which will help to have forms for OAuth and which will make password acceptance secure. from venv import create from fastapi import APIRouter , status , Depends , HTTPException from UsersValidator import UserRequest from models import Users from database import SessionLocal from sqlalchemy . orm import Session from typing import Annotated # OAuth2 and password hashing form which has it's own swagger documentation. from fastapi . security import OAuth2PasswordBearer , OAuth2PasswordRequestForm # Method to encrypt the password using bcrypt from passlib . context import CryptContext pwd_context = CryptContext ( schemes = [ "bcrypt" ], deprecated = "auto" ) # creating db dependency def get_db ():     # We need to fetch this SessionLocal be...