How to Roll Your Own Auth

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 344

  • @con-f-use
    @con-f-use 3 місяці тому +655

    I was fully prepared for sarcasm and snark. Instead I got the most useful short intro on web-authentication there is.

    • @snowballeffect7812
      @snowballeffect7812 3 місяці тому +6

      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 3 місяці тому +1

      that all of ben's videos

    • @petleveler8366
      @petleveler8366 3 місяці тому +2

      @@snowballeffect7812 that is the basics everyone should know that

    • @snowballeffect7812
      @snowballeffect7812 3 місяці тому

      @@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 3 місяці тому

      @@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 3 місяці тому +420

    I PERSIST MY TOKENS ON MY ARMS USING TATTOOS.

  • @goober9105
    @goober9105 3 місяці тому +314

    No way hes back

  • @emptytank604
    @emptytank604 3 місяці тому +35

    This was quite possibly the best and most concise explanation of how to implement auth I have seen. Thank you!

  • @vinceerkadoo45
    @vinceerkadoo45 3 місяці тому +62

    Literally popped on my suggestion seconds before i was going to search for this!

    • @ghdshds1899
      @ghdshds1899 3 місяці тому +1

      damn google really has your personal data dead to rights

  • @AndrewScofield
    @AndrewScofield 3 місяці тому +18

    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.

  • @zb2747
    @zb2747 3 місяці тому +16

    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

  • @Andres-Estrella
    @Andres-Estrella 3 місяці тому +1

    Thanks!
    Auth is one of those things you have to implement 2 or 3 times to fully understand.

  • @mikealejandro3938
    @mikealejandro3938 3 місяці тому +2

    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 !

  • @rohithk6466
    @rohithk6466 3 місяці тому +3

    Hi Ben this video was pretty useful, kindly keep coming back with these

  • @philhumphreys
    @philhumphreys 2 місяці тому

    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.

  • @MaxPicAxe
    @MaxPicAxe 3 місяці тому +9

    I can't believe you just explained so much about auth I had no idea about in this short video, so well. Thank you.

  • @user-zo2ky4mz7d
    @user-zo2ky4mz7d 3 місяці тому +3

    I was just researching this for a side project. Thanks Ben for reading my mind.

  • @PedroPedruzzi
    @PedroPedruzzi 3 місяці тому +4

    Very nice. I've used this design with two JWT, but never seen it explained anywhere. Cool!

  • @schism15
    @schism15 3 місяці тому +2

    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 3 місяці тому +1

    From all of the authentication videos I have seen, you explained everything very well.

  • @maneeshparihar
    @maneeshparihar 3 місяці тому +3

    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

  • @bojidaryovchev9995
    @bojidaryovchev9995 2 місяці тому

    that's why we love you Ben, what an amazing video, mad props yo, tight, tight tight tight!

  • @buzz1ebee
    @buzz1ebee 3 місяці тому +1

    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 3 місяці тому +8

    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 3 місяці тому

      What did you learn from him? I see mostly reaction videos

    • @w.e.b_b
      @w.e.b_b 3 місяці тому

      @@monsieurLDN you’ll have to go back to his content from 2018-2019ish when he was making more long form content

  • @rutvikpatel7640
    @rutvikpatel7640 3 місяці тому +2

    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.

  • @Yaxqb
    @Yaxqb 3 місяці тому

    here I have walked literal years wondering why we have refresh tokens. Your explanation is so clear

  • @devxsadik
    @devxsadik 3 місяці тому +1

    i missed this type of content bro
    pls keep doin it

  • @pingxtratech
    @pingxtratech Місяць тому

    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.

  • @pt_trainer9244
    @pt_trainer9244 3 місяці тому

    Summarized months of learning all of this in a short video, good stuff

  • @kevinroleke2769
    @kevinroleke2769 3 місяці тому +2

    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.

  • @amagicpotato5511
    @amagicpotato5511 3 місяці тому +6

    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!

  • @theo_ludwig
    @theo_ludwig Місяць тому

    Well explained, straight to the point with pros and cons of each method.
    Thank you!

  • @Smurfis
    @Smurfis Місяць тому

    I absolutely love this, was asking for it and he provided thanks Ben

  • @alessiotucci0
    @alessiotucci0 3 місяці тому +2

    Great intro to authentication, Thanks a lot Ben

  • @KevinNaughtonJr
    @KevinNaughtonJr 3 місяці тому +1

    great vid super informative benjamin

  • @erickshaffer6615
    @erickshaffer6615 3 місяці тому

    PLEASE KEEP THIS GOING, VERY EDUCATIONAL

  • @CardinalHijack
    @CardinalHijack 3 місяці тому +1

    step by step tutorial on doing this, like the old style videos this channel did, would be super cool

  • @SalimOfShadow
    @SalimOfShadow 3 місяці тому +2

    I always really really liked how you explained everything!!!
    Really enjoyed this quick rundown

  • @ayushgupta0010
    @ayushgupta0010 3 місяці тому +1

    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.

  • @gbbelloponce
    @gbbelloponce 3 місяці тому +1

    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!

  • @_solstice
    @_solstice 3 місяці тому

    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

  • @i-am-artur
    @i-am-artur 3 місяці тому

    Thanks for the video a lot! I am currently working on a project with JWT, and was about to read on xss

  • @SeanCassiere
    @SeanCassiere 3 місяці тому +12

    A wild Ben has appeared!

  • @KazSadeghi
    @KazSadeghi 3 місяці тому

    This is insane, best auth video / resource I've seen

  • @WillDelish
    @WillDelish 3 місяці тому

    Yep, oath + jwt + cookies be my fav flow right now. I have to use this at work.

  • @marcgentner1322
    @marcgentner1322 3 місяці тому

    Love it. Practical and simple. I have build the db setup in php but I like your methods on the jwt way

  • @krishnabirla16
    @krishnabirla16 3 місяці тому

    Best web-dev video I saw this week.

  • @regularyt-pz4ki
    @regularyt-pz4ki 3 місяці тому +1

    bro just back like he never left

  • @Sindoku
    @Sindoku 3 місяці тому

    Oooohhh crap, our boy Ben Awad is finally back. Welcome back baby, we missed you.

  • @gabrielbiacchi6169
    @gabrielbiacchi6169 3 місяці тому +4

    Hell yeah you're back homie

  • @Niksorus
    @Niksorus 3 місяці тому

    Fantastic, I'm down for a longer video 😄

  • @amzabdrahim3350
    @amzabdrahim3350 3 місяці тому

    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.

  • @Alphfirm
    @Alphfirm 3 місяці тому

    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!

  • @tanglesites
    @tanglesites 3 місяці тому

    Ben where you been? Good to see you back.

  • @eleah2665
    @eleah2665 3 місяці тому +1

    He back! But the room, mic and cuts make it look like he's been kidnapped.

  • @SoreBrain
    @SoreBrain 3 місяці тому

    I would have paid for this video more than I paid my auth provider 3 years ago.

  • @DanTheMan-rr3yg
    @DanTheMan-rr3yg 3 місяці тому +2

    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.

  • @lynxcat4life
    @lynxcat4life 3 місяці тому +1

    the ThioJoe effect has hit Ben

  • @Zayetzo
    @Zayetzo 3 місяці тому

    This was a very good explanation thank you!

  • @akashdeb9823
    @akashdeb9823 3 місяці тому

    babe wake up ben's new video just dropped

  • @vrinfotechies
    @vrinfotechies 3 місяці тому

    Yoo thanks for the explanation of creating a fully working auth model for my website thanks

  • @joshuasingh854
    @joshuasingh854 3 місяці тому

    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

  • @JOJO_THE_PROGRAMMER
    @JOJO_THE_PROGRAMMER 3 місяці тому

    he is back with tutorials!!!

  • @h45e32u4f
    @h45e32u4f 3 місяці тому

    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!

  • @TechTube-22
    @TechTube-22 3 місяці тому +1

    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

  • @V0LAT1LE_
    @V0LAT1LE_ 3 місяці тому +1

    The 2 doors in the back are hitting some weird parts in my brain. Its like they are saying red pill or blue pill

  • @eedoan
    @eedoan 3 місяці тому +1

    The true token is the friends we made along the way

  • @jakeave
    @jakeave 3 місяці тому

    Good job! I like the explanation of the log out of all devices. Next let's do authorization 😂

  • @ashrafuzzamankhalid3465
    @ashrafuzzamankhalid3465 3 місяці тому

    Hey Ben, will you please make a video about career choices and their difficulties and how to make sure to learn it...

  • @schoolofbillt2656
    @schoolofbillt2656 3 місяці тому

    This is so helpful. Thank you for this video!

  • @blancartembl
    @blancartembl 3 місяці тому

    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

  • @gavilansalcedo2422
    @gavilansalcedo2422 3 місяці тому

    THE KING IS BACK

  • @jeremyshorter2641
    @jeremyshorter2641 3 місяці тому

    Please do an email password auth video, I need it. Most useful video you've dropped in a few years tysm

  • @toTheMuh
    @toTheMuh 2 місяці тому

    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?

  • @radunicolaeeduard9194
    @radunicolaeeduard9194 3 місяці тому +1

    I always use keycloak !

  • @timkunze603
    @timkunze603 3 місяці тому +2

    Fun fact: saying "JWT" takes longer than just saying "JSON Web Token"

    • @SimonPaul-u7x
      @SimonPaul-u7x 3 місяці тому

      Fun Fact: everyone pronounced these two words now

  • @zeroliuxiyuan
    @zeroliuxiyuan 3 місяці тому

    The good old Ben is back

  • @danielsharp2402
    @danielsharp2402 3 місяці тому

    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).

  • @FatahChan
    @FatahChan 3 місяці тому

    Ben Awad making a video? what a surprise

  • @houssemchr1539
    @houssemchr1539 3 місяці тому

    Thank you for explication Ben, but how about using OAuth 2.0 ?
    I think it's the most secure one

  • @petaflop3606
    @petaflop3606 3 місяці тому

    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

  • @codewgem
    @codewgem 3 місяці тому

    You actually have YT. I just saw you on tiktok 😂 now I'm gonna be your subscriber

  • @jonacempelule9876
    @jonacempelule9876 3 місяці тому

    For the logic to invalidate the JWTs for ‘Signing out all devices’ why not have a Redis Cache/DB to keep track of blacklisted tokens, and set the expiration of that cached token to 15mins(or however your access token take long to expire).
    Now in your middleware, to validate the JWT you first check if the access token is blacklisted.
    Now when a user signs out of all devices, just have the other tokens in the blacklist cache.
    Your thought?

    • @prabaleshp1359
      @prabaleshp1359 2 місяці тому

      You can use it but in the end it'll become the same as sessions

  • @knwanze
    @knwanze 3 місяці тому

    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?

  • @hoangtrinh3448
    @hoangtrinh3448 3 місяці тому +4

    As a senior software engineer, I found this video is useful

  • @richardwang3541
    @richardwang3541 3 місяці тому

    Hey Ben this was super helpful! I was wondering what's your strategy for refreshing tokens? Do you have a /refresh endpoint to handle this?
    But then how do you know when to call it?
    For example, say the expiry on your access token was 15 minutes. How does the client know "oh my 15 minutes is up, better go call the /refresh endpoint"? Do you use a timeout or do you poll in the background?

  • @metro_0x
    @metro_0x 3 місяці тому

    Good tech content is back ❤❤

  • @alimahdi1012
    @alimahdi1012 3 місяці тому

    Throwback to a very similar video you made 4 years ago.

  • @yasharma2301
    @yasharma2301 3 місяці тому

    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

  • @codingwithjamal
    @codingwithjamal 3 місяці тому

    Ben coding tutorials back lets goo🔥

  • @floodo1
    @floodo1 3 місяці тому

    Nice little breakdown

  • @RyanLynch1
    @RyanLynch1 3 місяці тому

    welcome back king

  • @ryank9719
    @ryank9719 3 місяці тому

    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 3 місяці тому

      Congrats you have just reinvented regular sessions

  • @juanfelipemonsalvevargas602
    @juanfelipemonsalvevargas602 2 місяці тому

    Amazing video bro!

  • @armaan-ci3nv
    @armaan-ci3nv 3 місяці тому

    can you make a more in depth version really focusing on best security practices that owasp has laid out?

  • @ThatOneCEO
    @ThatOneCEO 3 місяці тому

    I wish this video came out 24 hours earlier

  • @trimpta
    @trimpta 3 місяці тому

    Where was this video when i had to go and do all this research myself

  • @Smurfis
    @Smurfis 3 місяці тому

    Absolute legend.

  • @ryanschofield6160
    @ryanschofield6160 3 місяці тому

    Love your videos, hope you’re doing well!

  • @abdulazeez.98
    @abdulazeez.98 3 місяці тому

    Awesome tutorial 👏

  • @MedKani
    @MedKani 3 місяці тому

    Welcome back I guess, thanks for the video

  • @dumbfailurekms
    @dumbfailurekms 3 місяці тому +2

    Is lucia analogous to passport.js or is it a higher level of abstraction

  • @StarCourtesan
    @StarCourtesan 3 місяці тому

    Easy to understand and covers everything :)

  • @Amir-bz1fk
    @Amir-bz1fk 3 місяці тому

    Unexpectedly helpful