Skip to content

A robust FastAPI authentication system utilizing JWT for secure token generation and cookie management for session handling. This repository contains code that demonstrates user login processes, token verification, and protected route access.

Notifications You must be signed in to change notification settings

amr2018/FastAPI-JWT-Auth-Cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

FastAPI-JWT-Auth-Cookie

Overview

This repository contains a FastAPI application that demonstrates a secure authentication system using JWT (JSON Web Tokens) and cookie management. The code showcases how to handle user logins, token generation, and verification, as well as protecting routes to ensure only authorized users can access them.

Features

  • User login with email and password validation.
  • JWT token generation for successful logins.
  • Cookie management for maintaining user sessions.
  • Protected endpoints that require a valid token to access.

Installation

To run this FastAPI application, you will need to install the required dependencies:

fastapi==0.111.0
pydantic==2.7.1
PyJWT==2.8.0

Usage

Start the server with the following command:

uvicorn main:app --reload

The application will be available at http://127.0.0.1:8000.

Endpoints

  • POST /login: Authenticate users and set a cookie with a JWT token.
  • GET /dashboard: Display user information if authenticated.

Security

The application uses JWT for secure authentication. The secret key and algorithm are customizable for enhanced security.

Contributing

Contributions are welcome! Please feel free to submit pull requests or create issues for any bugs or improvements.

License

MIT

About

A robust FastAPI authentication system utilizing JWT for secure token generation and cookie management for session handling. This repository contains code that demonstrates user login processes, token verification, and protected route access.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages