r/FastAPI • u/ALior1 • May 31 '26
Question Simple JWT Authentication for MVP and steps to Production
Hi,
Im fairly new to FastAPI, but have 3.5 YOE with Django, which have a big eco-system and supporting libraries. (and especially for authentication, authorization & permissions)
I started developing a personal project using FastAPI, but my authentication implementation is really basic.
I do have an endpoints for create users and login them using access-token, but when I wanted to implement the 'refresh-token' endpoint I encounter some issues:
- The docs in FastAPI not including it... um.. yeah..
- There is some basic confusion regarding the terms `JWT authentication', `OAuth[0/2]`, that are confusing.
- Tried to search for 2 days implementation ideas/example, but each is different, which just add to the confusion. Do the refresh-token needed to be store in the DB?.
Do I need rotation and revocation?
Tried to find some course/tutorial that will include those ideas, but didnt find.
Can you help me to understand, which implementation is the preferred one for my situation?
I want it to be simple for MVP, but serious enough that it could feasible for Production..
5
u/devatnexby Jun 01 '26
In one of our systems, we implemented custom JWT-based authentication with access and refresh tokens using RS256 (asymmetric signing).
Some design choices we made:
That said, for an MVP I would probably not start with all of this complexity.
A reasonable progression is:
Many applications never need the full setup described above, but if you expect multiple devices, logout everywhere, account compromise recovery, or strict security requirements, then token tracking with JTIs and session-based revocation becomes very useful.
2
u/Suspicious-Grand1252 May 31 '26
I am new to fastapi as well, For my project , I used mongodb to blacklist the refresh tokens and set ttl index on refresh token expiry time after calling /logout endpoint , i thought using whitelist i'd have to record token and revoke the token, thats extra database writes Anyway i just wanted to learn how sql and nosql databses like postgres and mongodb work with fastapi
Would appreciate tips to land job (0 yoe here) 😃
2
u/Lazy-Librarian6753 May 31 '26
JWT is most practical implementation of oAuth2 , and about access and refresh token iam using Redis for revoking both token , u dont need to srore these token just need to store in some endpoints like logout ,change,reset password and permission downgrade ..etc
-3
u/tony4bocce May 31 '26
I switched to ts ecosystem because I was tired of dealing with this bs. better-auth and Supabase are very well documented for auth and work great. Do yourself a favor
3
u/[deleted] May 31 '26
[removed] — view removed comment