FastAPI Authentication Example With OAuth2, JSON Web Tokens and Tortoise ORM

  Рет қаралды 103,067

Pretty Printed

Pretty Printed

3 жыл бұрын

In this video, I will show you how to implement authentication in your FastAPI apps. OAuth2 will be the type of authentication I demonstrate because it's very common among APIs, and I will use JSON web tokens (JWT) for the token in the OAuth flow. In addition to authentication, I'll use Tortoise ORM for the user model.
Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted.com/coaching
Get the code here: prettyprinted.com/l/t75
Twitter: / pretty_printed
Github: github.com/prettyprinted

Пікірлер: 85
@ofranc6204
@ofranc6204 4 ай бұрын
I am watching this 3 years later and it's still the best tutorial on this topic that I have found. Thanks for this.
@Vijay-Yarramsetty
@Vijay-Yarramsetty 3 жыл бұрын
so structured, so modular. lately found this channel. you are way good in explaining things. Thanks a lot.
@tonidelacalle
@tonidelacalle 10 ай бұрын
Excelent video. I wasn't expecting to get so much knowledge in just 40 minutes. And very well explained!!! Thanks a million.
@HitraNtheProgrammer
@HitraNtheProgrammer 3 жыл бұрын
Very educational! I'm glad I ran into your channel
@Smoonwalkerm
@Smoonwalkerm 3 жыл бұрын
awesome!! I was waiting for you to upload fastapi videos!!
@prettyprinted
@prettyprinted 3 жыл бұрын
More to come!
@Fsoza2008
@Fsoza2008 3 жыл бұрын
Real good videos man! Been real helpful
@ndk87
@ndk87 3 жыл бұрын
Thanks so much! Your videos really helped me some years ago when I was coding in Python flask, and just as I start working on FastAPI you begin making videos in that area too 🙌🙌
@NaguVisionaryVibes
@NaguVisionaryVibes 2 ай бұрын
Hi bro can you help me on this project
@juanfranciscolopez9968
@juanfranciscolopez9968 3 жыл бұрын
Very nice video and excellent channel!! looking forward to see how to protect FastAPI with OAuth2 but just acting as a Resource Server (and getting the token from and external Authorization Server). Thanks for sharing!
@djanthony6662
@djanthony6662 3 жыл бұрын
Awesome, thank you Anthony!
@jccorman5848
@jccorman5848 Жыл бұрын
This video actually gave me some insights into Pydantic, which I'm still trying to wrap my head around. So a tutorial using Pydantic more explicitly would be great. But you have a great back catalog already.
@mbalslow
@mbalslow 3 жыл бұрын
Fantastic video, very clear and to the point! Thank you. For a follow-up video (could simply build on top of this code), it would be great to see how to implement expiration in the tokens and a (maybe automatic) refresh logic. Maybe with a dummy (just plain) HTML login page. Anyways, thanks for the great content.
@suyashsingh675
@suyashsingh675 2 жыл бұрын
Did you find any reading material @mathias ?
@jonxslays
@jonxslays 2 жыл бұрын
This video helped me a ton thanks dude.
@10a3asd
@10a3asd 3 жыл бұрын
Ugh man, this is great. I'm learning OAuth2 and FastAPI at the same time and this was incredibly helpful to see the pieces work from the developer side.
@wendel1210
@wendel1210 3 жыл бұрын
me too, open connect too
@ItzSenaCrazy
@ItzSenaCrazy 3 жыл бұрын
Well explained. Ty very much!
@MADAHAKO
@MADAHAKO 2 жыл бұрын
VERY cognitive! Thank you!
@airoomstyles
@airoomstyles Жыл бұрын
great video, thanks!
@jacksonfeng4327
@jacksonfeng4327 11 ай бұрын
Best video on fastapi oauth❤
@prettyprinted
@prettyprinted 11 ай бұрын
Glad you like the video!
@HG-mt3vl
@HG-mt3vl 3 жыл бұрын
This is what makes your video stands out from other low quality content producers
@johnmichaelbitancor913
@johnmichaelbitancor913 3 жыл бұрын
Thanks Anthony!
@rizkydarmadi3196
@rizkydarmadi3196 2 жыл бұрын
very useful video, God bless you. love from jakarta
@freepythoncode
@freepythoncode 10 ай бұрын
Thank you so much 🙂❤
@jarvis7698
@jarvis7698 Жыл бұрын
Not only teaches authentication but also how a tutorial should be. Excellent demonstration & to the point. Thanks a lot for this :)
@ambejar13
@ambejar13 3 жыл бұрын
LOVE THIS
@felixnyamongo
@felixnyamongo Жыл бұрын
Bro you are awesome
@TheAremoh
@TheAremoh 3 жыл бұрын
Awesome as always. How about Some front-end registration and login form to help understand this better. Just me asking for more though. Thanks for this video.
@aureliojmnz2959
@aureliojmnz2959 2 жыл бұрын
Awesome...this has helped so much. Any two-factor authentication, or 2FA implementation in the future?
@JordanCote
@JordanCote 3 жыл бұрын
Very nice introduction! Do you have a video explaining how we could extend from this example, attaching this with some other OAuth2.0 providers like Google? Thanks!
@wa.6006
@wa.6006 2 жыл бұрын
Thanks!
@Avico78
@Avico78 3 жыл бұрын
great tutorials , will u consider to create tutorial for fastapi+ frontend ? it could be very interesting to see how u use th jwt + login screen .
@adriancroitor5154
@adriancroitor5154 3 жыл бұрын
Thank you. You always provide a good start point for development. Do you think it is a good ideea to use tortoise-orm in production ? Some devs say sqlalchemy is better for speeding up your api. I can configure sqlalchemy for a sync def, but failed configuring it for async.
@yourdadsbestfriend7101
@yourdadsbestfriend7101 3 жыл бұрын
more fastapi !!
@rangabharath4253
@rangabharath4253 3 жыл бұрын
Awesome thanks so much
@prettyprinted
@prettyprinted 3 жыл бұрын
Thanks for watching!
@oj43085
@oj43085 Жыл бұрын
Nice.
@ziaddwagy8973
@ziaddwagy8973 2 жыл бұрын
thanks and that's awesome work . one more question now should pass the user in all new additional endpoints ??
@Jesufemi_O
@Jesufemi_O 3 жыл бұрын
awesome video! can you do something on microservices soon ?
@davutlu60
@davutlu60 3 жыл бұрын
Thank you so much for the video.. I want to try it with postgres but I could not find a way.. any recommendation is welcome..
@hackwithharsha5228
@hackwithharsha5228 3 жыл бұрын
Thank you !! If possible, can someone explain difference between uvicorn, gunicorn, hypercorn ?
@puresocial3594
@puresocial3594 2 жыл бұрын
great
@TheAremoh
@TheAremoh 3 жыл бұрын
At the right time
@prettyprinted
@prettyprinted 3 жыл бұрын
Thanks for watching!
@saurabh210284
@saurabh210284 3 жыл бұрын
Thank you. Is there a way we can implement LDAP authentication ?
@athulkrishnadiyil1735
@athulkrishnadiyil1735 3 жыл бұрын
Please do a video on a chat / Meeting app setup using Fastapi+ MongoDB asyncioMotorClient
@_rameez
@_rameez 2 жыл бұрын
Great video. One think i don't understand. We have to login into the database before accessing any tables. Lets say i am using react and fastapi. User form data will be sent to fastapi's /login endpoint. Here i will try to create a db connection based on forms username and password. If sucess then create a sessionpool. or return exception. But you are directly accessing the db. HOW
@davutlu60
@davutlu60 3 жыл бұрын
Thank you for the tutorial. I was wondering if there is a particular method to exclude "hash_parword" in returning user data in pydantic user model..
@user-bc3nn1oy4u
@user-bc3nn1oy4u 3 жыл бұрын
Just pop the key from the dictionary
@harrisonfok8267
@harrisonfok8267 2 жыл бұрын
How come my VS code doesn't have code recommendations when I'm typing? Which extension did you install?
@vashistnarayansingh5995
@vashistnarayansingh5995 3 жыл бұрын
how fast api handles multiple requests, as we have threading as a parameter in flask to handle multiple request how does fast api do it?
@carlosaugusto-mo2hb
@carlosaugusto-mo2hb 2 жыл бұрын
I was able to perform the whole process of validation using PostMan , however I don’t know what username and password to input when I click in the button AUTHORIZE in swagger. Where did you register that ?
@emiliod90
@emiliod90 3 жыл бұрын
Hey dude, if you ever work out how to do the Authorisation Code Grant with Proof Key using FastAPI I will gladly pay 👍
@sheddtutt7875
@sheddtutt7875 Жыл бұрын
I want to implement auth0 token on my existing app but I really need to know if token will increase in size / length if I store more user informations on it e.g permissions (to be used on frontend)
@thesongmade
@thesongmade 2 жыл бұрын
Great video, but i cant manage to user if condition with awaits, it only return the default detail message, Ex: user = await User.get(username=username), if not user statment will not work, only inside a try catch structure, can someone help me?
@bokistotel
@bokistotel 2 жыл бұрын
Can you make an example using a OAuth2AuthorizationCodeBearer ?
@promisesheggs8863
@promisesheggs8863 3 жыл бұрын
is there a way to integrate google authentication with fast API?
@danielschmider5069
@danielschmider5069 2 жыл бұрын
your payload should definitely include the expiration date of the token
@bernardacquah3885
@bernardacquah3885 Жыл бұрын
can't seem to find any records in my DB. I know it's there though because it detects when I try to add a duplicate. What am I doing wrong?
@rahulsriram6295
@rahulsriram6295 3 жыл бұрын
Please make a similar video on Django Rest Framework
@prettyprinted
@prettyprinted 3 жыл бұрын
I'll look into it. Thanks for watching.
@romankocherezhchenko34
@romankocherezhchenko34 2 жыл бұрын
Do JWTs support RBAC?
@ralfvenchbillones3312
@ralfvenchbillones3312 3 жыл бұрын
Waiting for fastapi playlist.
@MD-vm7tv
@MD-vm7tv 3 жыл бұрын
Hi, Anthony, I'm a freelancer! Experienced with web scraping but I want to switch to web development. I don't have a college degree, I have a little knowledge about Django, Flask, Celery, and React. Should I go for Backend with Python or Frontend with React or something else? Can you consider to recommend a path for me?
@cepuofficial9025
@cepuofficial9025 3 жыл бұрын
I will recommend frontend since the job for that path would be more abundant
@harrisonfok8267
@harrisonfok8267 2 жыл бұрын
It didn't generate the sqlite files for me for some reasons. Do you know why?
@ABK6969
@ABK6969 8 ай бұрын
Make sure you're running `hypercorn main:app --reload` and not `hypercorn example:app --reload`
@tusharsnn
@tusharsnn 3 жыл бұрын
how to get bash inside windows pc like you have ?
@clearthinking5441
@clearthinking5441 10 ай бұрын
is there a way to do it with email rather than username?
@serg888fert4
@serg888fert4 7 күн бұрын
hi, sir. I get missing. TypeError: OAuth2AuthorizationCodeBearer.__init__() missing 1 required positional argument: 'authorizationUrl' help me please.
@harryodendaal345
@harryodendaal345 3 жыл бұрын
at 1:48 how do you get your json data in the web browser to be styled like that?
@zachblake6457
@zachblake6457 3 жыл бұрын
thats how it looks in firefox
@harryodendaal345
@harryodendaal345 3 жыл бұрын
@@zachblake6457 o snap just tested it and jup usually use chroms but thats really cool
@techiecurries1355
@techiecurries1355 Жыл бұрын
How can authenticate a fastapi which doesn't have a username and password. I mean no login credentials..
@advrxh
@advrxh 3 жыл бұрын
09:50
@bhaveshmevada8424
@bhaveshmevada8424 3 жыл бұрын
Sir can i make facebook messenger chatbot using fastapi?
@thecoasterfollower3564
@thecoasterfollower3564 11 ай бұрын
You had something in the authorization box of the postman token request but you didnt show it, doing it the way you showed wont work unless you had something there and forgot to say anything
@johnmcway6120
@johnmcway6120 Жыл бұрын
wow, god bless django for abstracting away this boilerplate.
@hamodeyDooba
@hamodeyDooba 3 жыл бұрын
i am watching and I feel like , ye just copy paste copy paste copy paste !!!! wtf with content creators
@mrjaimees
@mrjaimees Жыл бұрын
Hi, I can't access to sqlite3 db.sqlite3, appear this message sqlite3: The term 'sqlite3' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. somebody can help me?
@nigelfranciscoharosisa1579
@nigelfranciscoharosisa1579 2 жыл бұрын
It is possible to authenticate from get, for instance hhtp://user/me?user&password?
FastAPI Authentication with  JWT (JSON Web Tokens)
56:18
Bek Brace
Рет қаралды 95 М.
How to Use FastAPI: A Detailed Python Tutorial
20:38
ArjanCodes
Рет қаралды 219 М.
100❤️
00:19
MY💝No War🤝
Рет қаралды 21 МЛН
OAuth 2.0 explained with examples
10:03
ByteMonk
Рет қаралды 107 М.
What Is JWT and Why Should You Use JWT
14:53
Web Dev Simplified
Рет қаралды 1,1 МЛН
Why You NEED To Learn FastAPI | Hands On Project
21:15
Travis Media
Рет қаралды 153 М.
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 246 М.
FastAPI JWT Tutorial | How to add User Authentication
20:27
Eric Roby
Рет қаралды 45 М.