How to Roll Your Own Auth

  Рет қаралды 124,518

Ben Awad

Ben Awad

Күн бұрын

Пікірлер: 349
@con-f-use
@con-f-use 5 ай бұрын
I was fully prepared for sarcasm and snark. Instead I got the most useful short intro on web-authentication there is.
@snowballeffect7812
@snowballeffect7812 5 ай бұрын
We were taught how to roll our own auth at my boot camp just so we could have a deeper understanding on how it works and what can go wrong. Super valuable skill to have! to clarify, we did this from scratch, including hashing and salting passwords and using session tokens.
@vaishnavejp9247
@vaishnavejp9247 5 ай бұрын
that all of ben's videos
@petleveler8366
@petleveler8366 5 ай бұрын
@@snowballeffect7812 that is the basics everyone should know that
@snowballeffect7812
@snowballeffect7812 5 ай бұрын
@@petleveler8366 you'd be surprised, apparently. maybe they do know that, but it seemed rare for anyone to implement working auth from scratch.
@snowballeffect7812
@snowballeffect7812 5 ай бұрын
@@petleveler8366 not sure why my response was deleted lol. but I'll try again and say that I don't think most devs have implemented auth from scratch on their own.
@msilence2009
@msilence2009 5 ай бұрын
I PERSIST MY TOKENS ON MY ARMS USING TATTOOS.
@victor_aiyeola
@victor_aiyeola 5 ай бұрын
Most secure! ☠
@ifeanyinneji7704
@ifeanyinneji7704 4 ай бұрын
😂
@goober9105
@goober9105 5 ай бұрын
No way hes back
@2breezy866
@2breezy866 5 ай бұрын
We are so back
@yaaaayeet745
@yaaaayeet745 5 ай бұрын
hostinger bro :)
@zweitekonto9654
@zweitekonto9654 5 ай бұрын
guess what, he is
@emptytank604
@emptytank604 5 ай бұрын
This was quite possibly the best and most concise explanation of how to implement auth I have seen. Thank you!
@AndrewScofield
@AndrewScofield 5 ай бұрын
Great high level tutorial for a very confusing topic! There are so many tutorials out there that make it seem like you have to start out at enterprise level complication, when in reality a setup like this is going to work great for most people.
@vinceerkadoo45
@vinceerkadoo45 5 ай бұрын
Literally popped on my suggestion seconds before i was going to search for this!
@ghdshds1899
@ghdshds1899 5 ай бұрын
damn google really has your personal data dead to rights
@zb2747
@zb2747 5 ай бұрын
Very concise explanation of JWT vs Sessions. Interesting to see how your take on the two has developed over the years. I find your videos super helpful when it comes to doing auth without 3rd party Lastly, it’s great seeing you Ben. Much peace and success brother
@mikealejandro3938
@mikealejandro3938 5 ай бұрын
Ben, you're mi inspiration for becoming a web dev, it's been like 3 years since I started this journey seriously (at 17), now I have a decent job, thanks for existing brother, love your vids, we miss you homie !
@MaxPicAxe
@MaxPicAxe 5 ай бұрын
I can't believe you just explained so much about auth I had no idea about in this short video, so well. Thank you.
@cryptophil85
@cryptophil85 3 ай бұрын
I've just watched several videos on this topic whilst deciding on how to proceed and this is by far the best one. I love fireship vids but this extra depth into pros and cons gives Jeff a run for his money. Keep it up! I'd love to see a collab between you two.
@PedroPedruzzi
@PedroPedruzzi 5 ай бұрын
Very nice. I've used this design with two JWT, but never seen it explained anywhere. Cool!
@schism15
@schism15 5 ай бұрын
Perfect timing for this. I had just decided to try rolling my own auth on my latest side project since its not critical, will be low traffic and I'm tired of auth feeling like such a black box.
@ygvanz
@ygvanz 5 ай бұрын
From all of the authentication videos I have seen, you explained everything very well.
@rohithk6466
@rohithk6466 5 ай бұрын
Hi Ben this video was pretty useful, kindly keep coming back with these
@Andres-Estrella
@Andres-Estrella 5 ай бұрын
Thanks! Auth is one of those things you have to implement 2 or 3 times to fully understand.
@user-zo2ky4mz7d
@user-zo2ky4mz7d 5 ай бұрын
I was just researching this for a side project. Thanks Ben for reading my mind.
@rutvikpatel7640
@rutvikpatel7640 5 ай бұрын
You uploaded this video right when I needed it! You answered so many questions of mine in just 15 mins than I found answers online for last 2 days. Thank you so much. And please make a next video on how you setup username and password auth.
@mtnrabi
@mtnrabi 5 күн бұрын
A note regarding your cookie configuration - same-site lax can still lead to csrf attacks… (it allows for cross site requests via links but not via images, and only GET - but still it’s possible) Only same-site strict would totally prevent csrf attacks (setting CORS to the origin site only would also work) Love your content btw and hope you keep creating !
@buzz1ebee
@buzz1ebee 5 ай бұрын
He's back! Great overview. I've rolled my own auth quite a few times and this is a great guide. Recently I've been using a self hosted zitadel instance for the user management and I have a reusable nestjs module for handling all the zitadel oauth stuff and session management etc. Super easy to add additional auth providers or implement 2fa via settings on zitadel without changing anything at all on my backend which is just basic session cookies storing access and refresh tokens for zitadel.
@w.e.b_b
@w.e.b_b 5 ай бұрын
I am stoked for this. You’re such an incredible engineer and I owe much of my success as a programmer to your teachings! Thank you my friend
@monsieurLDN
@monsieurLDN 4 ай бұрын
What did you learn from him? I see mostly reaction videos
@w.e.b_b
@w.e.b_b 4 ай бұрын
@@monsieurLDN you’ll have to go back to his content from 2018-2019ish when he was making more long form content
@bojidaryovchev9995
@bojidaryovchev9995 3 ай бұрын
that's why we love you Ben, what an amazing video, mad props yo, tight, tight tight tight!
@maneeshparihar
@maneeshparihar 5 ай бұрын
Thanks a ton ... nobody explained it better and all in one video.. I will need to dig a bit more in CSRF and XSS bits.. but still crisp and yet adequately detailed. Kudos
@devxsadik
@devxsadik 4 ай бұрын
i missed this type of content bro pls keep doin it
@nigelyong9060
@nigelyong9060 4 ай бұрын
⏱ CHAPTERS ⏱(By TimeSkip AI) 00:00:00 - Introduction to Authentication Setup 00:01:30 - Setting Up Your VPS with Hostinger 00:02:51 - User Account Verification and Security 00:04:30 - Session Storage vs JWTs Explained 00:05:36 - Implementing JWTs for Authentication 00:06:52 - Managing User Sessions and Tokens 00:09:40 - Best Practices for Token Storage 00:11:35 - Front-End User Authentication Checks 00:12:41 - Conclusion and Resources
@Smurfis
@Smurfis 2 ай бұрын
I absolutely love this, was asking for it and he provided thanks Ben
@pt_trainer9244
@pt_trainer9244 4 ай бұрын
Summarized months of learning all of this in a short video, good stuff
@amagicpotato5511
@amagicpotato5511 5 ай бұрын
Had to figure all this out myself a year ago. This video will serve well for anyone else that finds themselves in the same position. Thanks Benji!
@Yaxqb
@Yaxqb 5 ай бұрын
here I have walked literal years wondering why we have refresh tokens. Your explanation is so clear
@SeanCassiere
@SeanCassiere 5 ай бұрын
A wild Ben has appeared!
@kevinroleke2769
@kevinroleke2769 5 ай бұрын
You don’t need to buy a service for email. It’s a bit annoying but you can setup postfix on a VPS and point MX, SPF, DMARC records.
@alessiotucci0
@alessiotucci0 5 ай бұрын
Great intro to authentication, Thanks a lot Ben
@erickshaffer6615
@erickshaffer6615 5 ай бұрын
PLEASE KEEP THIS GOING, VERY EDUCATIONAL
@SalimOfShadow
@SalimOfShadow 5 ай бұрын
I always really really liked how you explained everything!!! Really enjoyed this quick rundown
@Sindoku
@Sindoku 5 ай бұрын
Oooohhh crap, our boy Ben Awad is finally back. Welcome back baby, we missed you.
@KazSadeghi
@KazSadeghi 5 ай бұрын
This is insane, best auth video / resource I've seen
@theo_ludwig
@theo_ludwig 2 ай бұрын
Well explained, straight to the point with pros and cons of each method. Thank you!
@pingxtratech
@pingxtratech 2 ай бұрын
This is so good. Nice one. With regards to Cookies vs LocalStorage, I always have my reservations and would usually choose LocalStorage as it'll only keep the user logged in on the Frontend. If it is tempered with, the user is kicked of out the system. I realized one thing that even with cookies, when I copied the cookies with their values on a certain browser and put it on a different browser, all I had to do was reload the page and I was logged in. Great insight though.
@gbbelloponce
@gbbelloponce 5 ай бұрын
Amazing video man!!! It's literally what I've been looking for lately. I would personally love a video talking about the username/password login approach. Greetings!
@gabrielbiacchi6169
@gabrielbiacchi6169 5 ай бұрын
Hell yeah you're back homie
@KevinNaughtonJr
@KevinNaughtonJr 5 ай бұрын
great vid super informative benjamin
@AlexCrocker
@AlexCrocker 4 ай бұрын
Thanks! 🐊🐊🐊
@ayushgupta0010
@ayushgupta0010 5 ай бұрын
My go-to method is to use JWT with a refresh token and token version, make the access token short-lived, like 15 min, and store it in the memory on the frontend.
@regularyt-pz4ki
@regularyt-pz4ki 5 ай бұрын
bro just back like he never left
@krishnabirla16
@krishnabirla16 5 ай бұрын
Best web-dev video I saw this week.
@marcgentner1322
@marcgentner1322 5 ай бұрын
Love it. Practical and simple. I have build the db setup in php but I like your methods on the jwt way
@TechTube-22
@TechTube-22 5 ай бұрын
Auth with cookies makes you're API only callable via browser, so if you want to use them in a mobile app, you have to change maaaany things
@_solstice
@_solstice 5 ай бұрын
very good video, everything was super clear, maybe this is a bit niche or too specific to be useful but a video about how you'd go about rolling your own oauth provider would be very interesting imo
@CardinalHijack
@CardinalHijack 5 ай бұрын
step by step tutorial on doing this, like the old style videos this channel did, would be super cool
@i-am-artur
@i-am-artur 5 ай бұрын
Thanks for the video a lot! I am currently working on a project with JWT, and was about to read on xss
@hoangtrinh3448
@hoangtrinh3448 5 ай бұрын
As a senior software engineer, I found this video is useful
@DanTheMan-rr3yg
@DanTheMan-rr3yg 5 ай бұрын
great video, you should do a video on the username + password, but do the whole shebang too! Reset password, forgot username, two factor authentication, magic link too, etc.
@V0LAT1LE_
@V0LAT1LE_ 5 ай бұрын
The 2 doors in the back are hitting some weird parts in my brain. Its like they are saying red pill or blue pill
@SoreBrain
@SoreBrain 5 ай бұрын
I would have paid for this video more than I paid my auth provider 3 years ago.
@eleah2665
@eleah2665 5 ай бұрын
He back! But the room, mic and cuts make it look like he's been kidnapped.
@lynxcat4life
@lynxcat4life 5 ай бұрын
the ThioJoe effect has hit Ben
@MedKani
@MedKani 5 ай бұрын
Welcome back I guess, thanks for the video
@eedoan
@eedoan 5 ай бұрын
The true token is the friends we made along the way
@amzabdrahim3350
@amzabdrahim3350 5 ай бұрын
amazing video, please do more. this popped on my suggestions, clicked on it immediately. had to do jwt for a client, i didn't know how to set up the refresh token.
@WillDelish
@WillDelish 5 ай бұрын
Yep, oath + jwt + cookies be my fav flow right now. I have to use this at work.
@Kayzewolf
@Kayzewolf 13 күн бұрын
It’s appealing and tempting to do the JWT flow but just feels like a session lookup is the best match since you probably want data that you wouldnt want to expose in a JWT payload, or perhaps would want to revoke faster. Say, if you ban a user, they still got access for as long as the JWT is valid. Even with a small expiration via refresh token flow, it’s still a window of opportunity you gotta then trade off to where you’ll probably start refreshing every other request anyways. I mainly use JWT for expiring temp tokens like email verification or even password resets (hash value to check db, inside an expiring token). If I’m doing a microservices approach, JWT benefits where you have the auth service do the lookup and then send a potentially sensitive JWT via internal network to that microservice, decoupling auth from services. JWTs are fine for auth but I just prefer more control and safety of sessions (via redis) for access changes (banning, access permissions, etc).
@Kayzewolf
@Kayzewolf 13 күн бұрын
For a point in JWT auth’s favor, I suppose checking permissions via query might reduce these concerns, though the potential performance/coding complexity might still be a reason not to? I dunno
@avi12
@avi12 5 ай бұрын
Dev: How do I deal with auth? Ben: Yes
@joshuasingh854
@joshuasingh854 5 ай бұрын
Bro thanks so much for this!! This was very useful and cleared a bunch of stuff for me!! Yes please do the next video if how you set up username/email and password
@akashdeb9823
@akashdeb9823 5 ай бұрын
babe wake up ben's new video just dropped
@Niksorus
@Niksorus 5 ай бұрын
Fantastic, I'm down for a longer video 😄
@jakeave
@jakeave 4 ай бұрын
Good job! I like the explanation of the log out of all devices. Next let's do authorization 😂
@JOJO_THE_PROGRAMMER
@JOJO_THE_PROGRAMMER 5 ай бұрын
he is back with tutorials!!!
@FatahChan
@FatahChan 5 ай бұрын
Ben Awad making a video? what a surprise
@dumbfailurekms
@dumbfailurekms 5 ай бұрын
Is lucia analogous to passport.js or is it a higher level of abstraction
@timkunze603
@timkunze603 5 ай бұрын
Fun fact: saying "JWT" takes longer than just saying "JSON Web Token"
@SimonPaul-u7x
@SimonPaul-u7x 4 ай бұрын
Fun Fact: everyone pronounced these two words now
@Zayetzo
@Zayetzo 4 ай бұрын
This was a very good explanation thank you!
@iamlasbrey6334
@iamlasbrey6334 5 ай бұрын
Just about when A.I was taking over, Ben Awad came through for us He's Back!!!
@danielsharp2402
@danielsharp2402 4 ай бұрын
For me refresh token is usually not a JWT since accessing the database is happening there anyway. And that gives you the best of both worlds with revoking as well. Usually stored in redis with EX. Also for early MVP services I like to do a Frankenstein approach of letting an access token close to expiry refresh itself (works quite well, but obviously isn't as good as refresh tokens).
@codingwithjamal
@codingwithjamal 5 ай бұрын
Ben coding tutorials back lets goo🔥
@blancartembl
@blancartembl 5 ай бұрын
One way to do it without relying on a sass product its to use Lucia Auth... full fine grained control of the flow without magic like others
@vrinfotechies
@vrinfotechies 4 ай бұрын
Yoo thanks for the explanation of creating a fully working auth model for my website thanks
@tanglesites
@tanglesites 5 ай бұрын
Ben where you been? Good to see you back.
@thegreat.laflame
@thegreat.laflame 5 ай бұрын
Good tech content is back ❤❤
@schoolofbillt2656
@schoolofbillt2656 5 ай бұрын
This is so helpful. Thank you for this video!
@Alphfirm
@Alphfirm 5 ай бұрын
Sweet, thanks! For my situation, a tutorial on expo react native app with using secure storage as you mentioned and session storage would be great!
@codewgem
@codewgem 5 ай бұрын
You actually have YT. I just saw you on tiktok 😂 now I'm gonna be your subscriber
@ryank9719
@ryank9719 5 ай бұрын
A simpler way to invalidate tokens would be to create a table/collection for all your tokens. Then, when a user logouts, you search the table/collection for all tokens associated with that user and delete them.
@Sylvoo01
@Sylvoo01 4 ай бұрын
Congrats you have just reinvented regular sessions
@gavilansalcedo2422
@gavilansalcedo2422 4 ай бұрын
THE KING IS BACK
@h45e32u4f
@h45e32u4f 5 ай бұрын
This section looks great. And going deep into passwords, how to get credentials, why is not ok to send the token in cookies and get it in headers... Can be good. And in the future, I see you doing a video like this but " Exploring Coolify", host your own "vercel". It would be awesome to see that. Thank you for the information!
@zeroliuxiyuan
@zeroliuxiyuan 5 ай бұрын
The good old Ben is back
@RyanLynch1
@RyanLynch1 4 ай бұрын
welcome back king
@radunicolaeeduard9194
@radunicolaeeduard9194 5 ай бұрын
I always use keycloak !
@jeremyshorter2641
@jeremyshorter2641 5 ай бұрын
Please do an email password auth video, I need it. Most useful video you've dropped in a few years tysm
@pranjalagnihotri6072
@pranjalagnihotri6072 5 ай бұрын
Bro is back 🚀🚀🚀🚀🚀
@hrithiksingh73
@hrithiksingh73 5 ай бұрын
ben is back 🎉🎉
@yasharma2301
@yasharma2301 5 ай бұрын
One benefit of cookie I think is SSR? JWTs stored in local storage cant be read on SSR since you won't be able to send it in the first document call, while if you use cookies you can fetch user data on the frontend server. Correct me if I am wrong
@ashrafuzzamankhalid3465
@ashrafuzzamankhalid3465 5 ай бұрын
Hey Ben, will you please make a video about career choices and their difficulties and how to make sure to learn it...
@juanfelipemonsalvevargas602
@juanfelipemonsalvevargas602 4 ай бұрын
Amazing video bro!
@ThatOneCEO
@ThatOneCEO 5 ай бұрын
I wish this video came out 24 hours earlier
@toTheMuh
@toTheMuh 3 ай бұрын
5:30 - in a microservice environment you are most likely going to have a token AND a session cache, especially if you are working on a complex business SaaS (software like Salesforce, AWS, SAP, etc.) with RBAC/ACL/etc. The API Gateway will validate the token and then look up the users permissions in the cache. You could store the permissions within the token, yes. BUT that is very complicated. Imagine you have a user and that user has a role with a bunch of permissions. What if the permissions of the role change or the role of the user changes while the user is logged in?
@TestFirstTestLast-m7u
@TestFirstTestLast-m7u 3 ай бұрын
You can literally send the tokens through server cookies and if they sign out just remove the cookies and token itself from the db
@petaflop3606
@petaflop3606 5 ай бұрын
the first auth I self-rolled was an OIDC IdP server to connect a third party to our existing session-based auth (not SaaS it was just for one particular partner). It was fiddly at first but once you get it, like most things, it doesn't feel so bad and I'd be much more confident doing it again if I had to
@abdulazeez.98
@abdulazeez.98 5 ай бұрын
Awesome tutorial 👏
@trimpta
@trimpta 4 ай бұрын
Where was this video when i had to go and do all this research myself
@knwanze
@knwanze 5 ай бұрын
Good stuff Ben. Looking at your database queries in your screenshots, is that some ORM you're using or your own custom functions wrapped around SQL queries?
@comproprasad6438
@comproprasad6438 5 ай бұрын
you can sign the session token as well and store in a cookie
Serverless Doesn't Make Sense
10:13
Ben Awad
Рет қаралды 368 М.
Setting up a production ready VPS is a lot easier than I thought.
29:50
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Passkeys: The Future Of Authentication
31:22
Theo - t3․gg
Рет қаралды 88 М.
The 3 Laws of Writing Readable Code
5:28
Kantan Coding
Рет қаралды 788 М.
Session Vs JWT: The Differences You May Not Know!
7:00
ByteByteGo
Рет қаралды 299 М.
Technologies I used to Code My Backendless App
10:57
Ben Awad
Рет қаралды 149 М.
This is Why You Don't Roll Your Own Auth
16:21
ForrestKnight
Рет қаралды 14 М.
Microservices Gone Wrong at DoorDash
17:22
NeetCodeIO
Рет қаралды 168 М.
How to OVER Engineer a Website // What is a Tech Stack?
11:20
Fireship
Рет қаралды 2,5 МЛН
Oh, Auth Doesn't Have to Suck?
7:16
Josh tried coding
Рет қаралды 67 М.
Auth Does NOT Have To Be Hard
17:13
Web Dev Simplified
Рет қаралды 103 М.
Beginner React.js Coding Interview (ft. Clément Mihailescu)
36:31
Ben Awad
Рет қаралды 2,2 МЛН