FastAPI JWT Tutorial | How to add User Authentication

preview_player
Показать описание
In this tutorial, we will walk you through the process of integrating JWT (JSON Web Tokens) with FastAPI to secure user authentication. If you want to add JWT authentication to your FastAPI application, this video is for you!

If you are new to FastAPI or JWT, don't worry. We will cover the basics and gradually move towards more advanced topics. You'll get to understand not only how to implement JWT but also why it is important. FastAPI JWT authentication is what you want to use for your JWT Python project

===========================
🎓 Courses can be found:
===========================

👨‍💻 Hi, I am Eric!👨‍💻
Hey! I’m a seasoned developer and cloud enthusiast. I love sharing my knowledge and helping others to discover the exciting world of programming and cloud technologies. For more tutorials, tips, and tech magic, don’t forget to hit that subscribe button and ring the bell for notifications!

🙏 Support The Channel 🙏
If you found this tutorial helpful, please give it a thumbs up 👍, comment, and share it with your network 🌍

#fastapi #python #programming
Рекомендации по теме
Комментарии
Автор

Nice tutorial. But it would be awesome if you include a link to a repo. It's not because I don't want to type but I want to see multiple file at the same time while watching your video. Thanks anyway.

lonehayena
Автор

Man, congratulations on your lessons. Here in Brazil, we find little information about this subject, and you are saving us.

breno-codes
Автор

Wow the timing, this is literally what i was just trying to figure out! Thanks!

ryanschaefer
Автор

Super helpful! just 1 small request, let's not call it, un-hash. You can't un-hash a hash. Hashing is one way encryption. You can match the hash with the user provided password and match it with the hash already stored in database.

ishan.girdhar
Автор

Amazing tutorial. I really enjoyed it. thanks for the amazing explaination🙏

jacobwilsonmwale
Автор

The import statement in the auth file:

from datetime import timedelta, datetime
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from sqlalchemy.orm import Session
from starlette import status
from database import SessionLocal
from models import Users
from passlib.context import CryptContext
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
from jose import jwt, JWTError

marteinngumundsson
Автор

Hey Eric my question in my mind is always how to keep these token on the frontend, I send access token an response header and in JSON format and don't give refresh token instead set it as a httponly cookie.

In frontend I keep it in context API and to make sure if user is logged in or not for each 401 message I try to send request to refresh endpoint and in this way my cookie has been read by fast API and again I keep it in context API in frontend which is nextjs

What do you think of this?
What is the best practice?
I want to know your opinion

karacan
Автор

Very nice and structured video! Helped a lot, thanks!

JuliusThePianoGuy
Автор

Can I download your code from this tutorial somewhere? Keep up the good work.
Btw, very helpful turorial! Thank you so much.

rstiekema
Автор

I am created crud operation using fastapi and python, then I want implement jwt refresh token, pls give any idea

sowmiyapannerselvam
Автор

your fastapi course on udemy is amazing

edderleonardo
Автор

I'm having a problem in the swagger the Authorize button is performing the call towards the endpoint /token (which does not exist) instead that /auth/token as shown at 19:50. I cannot understand why.

vincenzobuonvino
Автор

Thanks man for this tutorial. It was amazing well explained and really saved me :)

herozero
Автор

Gracias amigo!! This video is very informative, your explanation are super clear, I would ask about the expiration time an automatically refresh it, refresh token or smt, is it store on db? Thx again for your time

dannisisgt
Автор

Thanks for your video. But do you know how I can integrate Clerk to my fast api project?

crazibility
Автор

19:47 - I want to have a place holder for just the token and not the entire form. How to do that?

thegrind
Автор

Really quick, what if the user is logged in and goes to the homepage, I want to redirect them to another page since they're already logged in

Ken-ixms
Автор

If some hack knows the secret key and the algorithm how can he authenticate? Doesn t the function get_current_user prevents that?

amiltonmoreira
Автор

hey, how i can get the token and save it in browser(how i can use oauth2) without using fastapi docs interface

gleb
Автор

hello, thanks for video, is it possible to share your setup to create this kind of content ? thanks advance

nulops