Django API Authentication using JWT Tokens

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2025

ความคิดเห็น • 208

  • @dawoodsiyam512
    @dawoodsiyam512 ปีที่แล้ว +5

    man you are the best, straight to the point, no copy pasting, and very easy and readable code and step by step process, something that lots of tutorials struggle with, thank you so much.

  • @jasonvilla3696
    @jasonvilla3696 9 หลายเดือนก่อน +1

    Watching this today, although this is 3 years ago and there is an optimized way to use JWT, this really helped me understand what happens during a JWT authentication. Kudos

    • @MissoyKE
      @MissoyKE 8 หลายเดือนก่อน

      share link for the optimized way

    • @Shamir-qb1ih
      @Shamir-qb1ih 5 หลายเดือนก่อน

      I think this cannot be used on a app. Right? Mobile app cannot access cookies. I am developing in flutter. Does the method shows in this video can be done using cookies?

  • @learningchannel4001
    @learningchannel4001 2 ปีที่แล้ว +8

    The best token based Authentication I have watched. Very detailed. Thank you

  • @shagilislam2533
    @shagilislam2533 7 หลายเดือนก่อน +2

    Truly the smoothest and most accurate Django-JWT Tutorial I've ever seen!!!

  • @RONALDO362009
    @RONALDO362009 2 หลายเดือนก่อน

    This was the best video I've watched on TH-cam about Authentication using JWT Tokens. Thank you so much!

  • @konstantinoskostopoulos9794
    @konstantinoskostopoulos9794 3 ปีที่แล้ว +32

    Thanks a lot man, I had a hard time until I saw this one. The explanations were on point as well, cors even fixed a front-end problem my team had. Hope you grow big!

    • @ScalableScripts
      @ScalableScripts  3 ปีที่แล้ว +2

      Glad it helped!

    • @nepdevtech
      @nepdevtech 3 ปีที่แล้ว +1

      @@ScalableScripts I am getting error while decoding the token in userview

    • @goodboy435
      @goodboy435 2 ปีที่แล้ว

      @@nepdevtech me too... For me it says.
      "
      'str' object has no attribute 'decode'
      "
      Have u got the solution??

    • @jayantpatankar5967
      @jayantpatankar5967 2 ปีที่แล้ว

      @@ScalableScripts why I am getting - RecursionError: maximum recursion depth exceeded while calling a python object. How to solve...

    • @loganathant9840
      @loganathant9840 2 ปีที่แล้ว +1

      ​@@goodboy435 decode is not needed since its already decoded remove the decode and it will work

  • @bilaltufaildev
    @bilaltufaildev 9 หลายเดือนก่อน +1

    Perfect Tutorial for basic auth so far. Loved it! Keep it up Sir! 💖

  • @gamingfundas
    @gamingfundas 3 ปีที่แล้ว +6

    very well explained....loved this. Yeah, some exceptions are that, the person has to make a create_superuser function to create a superuser but its fine. JWT explained wonderfully

  • @raulemilianomirandagutierr3313
    @raulemilianomirandagutierr3313 3 ปีที่แล้ว +4

    Man you don't know how much I appreciate this video, let me tell you I've been looking for something like this for weeks, let me tell you there's nothing.

    • @jaitungodhani2334
      @jaitungodhani2334 3 ปีที่แล้ว +1

      plz tell me if you know how i applied Bearer method in video video instead of cookies.

  • @EveryGameArchive
    @EveryGameArchive ปีที่แล้ว

    Thanks! I had hard times trying to discover how to use jwt and you solved all questions that i had.

  • @sushovitshah9083
    @sushovitshah9083 9 หลายเดือนก่อน

    Best video for drf authentication. Totally loved it and learned a lot.

  • @zakariaazahaf394
    @zakariaazahaf394 2 ปีที่แล้ว

    I dont usually comment on yt videos, but this video is so damn good, with your explanations and the way how you talk.
    Keep up brother

  • @TommyBrick
    @TommyBrick 3 ปีที่แล้ว +12

    Hi, great video! One question: At @26:12, why did you decode the token? I get the error "'str' object has no attribute 'decode'" If I drop the decoded I get a decoded string.

    • @matteob9342
      @matteob9342 3 ปีที่แล้ว +6

      Hi, You can downgrade the PyJWT package to 1.7.1 or remove the call to decode. It should work

    • @TommyBrick
      @TommyBrick 3 ปีที่แล้ว +7

      @@matteob9342 removed .decode() and it dit work fine afterwards. Thanks!

    • @goodboy435
      @goodboy435 2 ปีที่แล้ว

      Got same error.. Just after an year.

    • @goodboy435
      @goodboy435 2 ปีที่แล้ว

      @@matteob9342 thanks matteo... Ur removing decode() call method worked for me too...

    • @toufikbenkhelifa917
      @toufikbenkhelifa917 2 ปีที่แล้ว

      @@goodboy435 how can i do it ?

  • @devniel
    @devniel 2 ปีที่แล้ว +1

    Awesome! thanks for your explanation. I just want to remind these typical topics for django, it always important to continue improving our skills.

  • @nicolasportelli3766
    @nicolasportelli3766 2 ปีที่แล้ว

    Very good video! Without getting lost in the bush, getting to the concept clearly
    Greetings from Argentina!

  • @thabosiphiwemngoma1859
    @thabosiphiwemngoma1859 ปีที่แล้ว

    This is an amazing video. So clear. Answered most of my questions before I asked them.

  • @aryanagarwal2257
    @aryanagarwal2257 2 ปีที่แล้ว

    Thank You! You have explained it so clearly, I haven't been able to understand this since days but with this one I was able to easily

  • @abbaskareem5281
    @abbaskareem5281 ปีที่แล้ว

    This is the best video on JWT and tokens in django and django-rest-framework ... thank you million times sir ❤❤

  • @HEATER_APP
    @HEATER_APP ปีที่แล้ว

    super straightforward and concise, great job!

  • @sorooshmoghimi5494
    @sorooshmoghimi5494 ปีที่แล้ว

    that was really helpful, and very straightforward! Thank you so much.

  • @imcamilaaa
    @imcamilaaa 3 ปีที่แล้ว +12

    thank you so much for the video, because of this now i and my group can sleep in peace hahahaha

  • @gregocanepa
    @gregocanepa 3 ปีที่แล้ว +8

    Awesome tutorial dude! One question: at 21:08 when you are fetching the user from the db, why do you do a filter and then a first instead of simply a get()? Thanks!

    • @souravjha2146
      @souravjha2146 3 ปีที่แล้ว +6

      filter(), whenever you expect more than just one object that matches your criteria. If no item was found matching your criteria, filter() returns am empty queryset without throwing an error.
      get(), you expect one (and only one) item that matches your criteria.
      Thus if there are more than one objects returned in queryset we would know that via filter

  • @manolismandamadiotis5853
    @manolismandamadiotis5853 2 ปีที่แล้ว +1

    very helpful video and keeping it simple tthanks!

  • @ArghyaBhattacharyaNITA
    @ArghyaBhattacharyaNITA 3 ปีที่แล้ว +3

    Thanks for the clear explanation. Bdw, what about the refresh token.. don't we need that as well ??

  • @pradyumnabharadwaja8237
    @pradyumnabharadwaja8237 ปีที่แล้ว

    The best explainantion and ONPOINT, loved it, Thank you 🙏

  • @davidadu-tenkorang3186
    @davidadu-tenkorang3186 3 ปีที่แล้ว +3

    Excellent work. Thank you

  • @dabalayonas1340
    @dabalayonas1340 4 หลายเดือนก่อน +1

    Great tutorial my brother!
    The cookies aren't saving automatically when I use ReactJs - Axios.
    How can I save the cookies automatically and also send it as part of the request using Axios or Fetch API

  • @roamandlift
    @roamandlift 3 ปีที่แล้ว +1

    Such a dope explanation 🔥🔥🔥

  • @JohnBiddulph
    @JohnBiddulph 10 หลายเดือนก่อน

    29:08, I have installed django-cors-headers and added to settings app and middleware, I am getting: No module named 'corsheaders' please help

  • @johntygomes6519
    @johntygomes6519 3 ปีที่แล้ว

    Very Greeat Explanation Sir...ThankYou

  • @ivanromanov7120
    @ivanromanov7120 ปีที่แล้ว

    Thank you for video! Can you tell what is the soft you use for DataBase on 06:42 ?

  • @thaminduKavinda
    @thaminduKavinda 3 ปีที่แล้ว +1

    Super Helpful great tutorial. Thanks a lot.

  • @Nikhil-Tomar
    @Nikhil-Tomar ปีที่แล้ว +1

    What about CSRF policies and securities, Why are they not applied here?

  • @shubhamathawane02
    @shubhamathawane02 9 หลายเดือนก่อน +2

    Can you tell how can i send token from frontend to backend again for each request as i am storing it as cookie on frontend ?

    • @shaannky
      @shaannky 13 วันที่ผ่านมา

      if you are using axios set withCredentials true

    • @shubhamathawane02
      @shubhamathawane02 13 วันที่ผ่านมา

      @shaannky Thanks

  • @ВладМицкевич-о1и
    @ВладМицкевич-о1и 11 หลายเดือนก่อน

    thank you very much. excellent presentation of the material

  • @maksymmalicki2720
    @maksymmalicki2720 2 ปีที่แล้ว

    Amazing tutorial, thank you very much!

  • @victorchendra4282
    @victorchendra4282 4 หลายเดือนก่อน

    This is tutorials is awesome.. Thanks a lot

  • @lawalabideen8943
    @lawalabideen8943 3 ปีที่แล้ว +1

    @26:00 in the token part, I keep on getting TypeeError: Object of type date-time is not serializable

    • @erlingrognhaugen5509
      @erlingrognhaugen5509 2 ปีที่แล้ว

      @@martinteppa4544 That did not seem to help

    • @diver1235
      @diver1235 ปีที่แล้ว

      same error, some solution?

  • @Craennie
    @Craennie 11 หลายเดือนก่อน +1

    The cookies aren't saving automatically when I use ReactJs - Axios.
    How can I save the cookies automatically and also send it as part of the request using Axios or Fetch API

  • @edwardwalsh1115
    @edwardwalsh1115 ปีที่แล้ว +3

    In May 2023, I had to change this:
    payload = jwt.decode(token, key='secret', algorithm=["HS256"])
    to this:
    payload = jwt.decode(token, key='secret', algorithms=["HS256"])

    • @mrtherapy309
      @mrtherapy309 ปีที่แล้ว

      Thanks for this. You just helped me.

  • @rashedulhasanporosh7722
    @rashedulhasanporosh7722 2 ปีที่แล้ว

    Thank you so much. It was a great help!

  • @keshavachandu99
    @keshavachandu99 8 หลายเดือนก่อน

    I learnt a lot here Thank You !!!

  • @faysalahmed3601
    @faysalahmed3601 3 ปีที่แล้ว

    'User' object has no attribute '_default_manager' getting this error at 15:21 minutes. Can anybody suggest me some solutions?

  • @shadmanlatif6530
    @shadmanlatif6530 3 ปีที่แล้ว

    Legit helped me

  • @Travellife8877
    @Travellife8877 3 ปีที่แล้ว

    just osm content and step by step explaination

  • @nguyenichthanhtu8502
    @nguyenichthanhtu8502 2 ปีที่แล้ว

    This is Awesome, helpful for me. Thanks

  • @user-dev953
    @user-dev953 2 ปีที่แล้ว

    This was very helpful thank you

  • @allanalais7859
    @allanalais7859 3 ปีที่แล้ว +3

    How can I create super users?

  • @hemantjain1321
    @hemantjain1321 5 หลายเดือนก่อน

    Video Explanation is Really amazingly. But Why there is no refresh token??

  • @davismghanga7484
    @davismghanga7484 10 วันที่ผ่านมา

    Great Tutorial.
    But aren't we supposed to have two tokens: access token and refresh token?

  • @nicklennonfortes9611
    @nicklennonfortes9611 2 ปีที่แล้ว

    best teacher ever

  • @paasxx
    @paasxx ปีที่แล้ว

    Superb content, very helpful

  • @adhy612000151
    @adhy612000151 ปีที่แล้ว +1

    Thanks a lot good man!
    God always bless you!

    • @adhy612000151
      @adhy612000151 ปีที่แล้ว

      Many Many Thanks For you good man!

  • @_nishadkv
    @_nishadkv 3 ปีที่แล้ว

    Helps a lot.. Thanks buddy

  • @NiM44
    @NiM44 3 ปีที่แล้ว

    Very well explained , Thanks

  • @shashishekhar----
    @shashishekhar---- ปีที่แล้ว

    Great content, subscribed !

  • @yaroslavstetsko4174
    @yaroslavstetsko4174 3 ปีที่แล้ว

    It is perfect tutorial, thank u, and continue.

  • @maxfromsilenthill
    @maxfromsilenthill 2 ปีที่แล้ว

    Thank you for this. You are awesome!

  • @omarchristie3923
    @omarchristie3923 8 หลายเดือนก่อน

    Hey, I did this auth and now connecting it to Vue js frontend but when I sign out, I am still able to access protected views that need authentications. Only when I clear the browser cookie do the access stop. Also the cookie is still within the header when I sign out. How can I fix this? it work fine in postman.

  • @HarshitGupta-vo5bm
    @HarshitGupta-vo5bm ปีที่แล้ว

    is that pyjwt assigns refresh token to user , just like simple jwt does ? also does it refresh tokens automatically after expiration time ?

  • @jakubrudy9372
    @jakubrudy9372 3 ปีที่แล้ว

    thank you for this tutorial very much!

  • @musicbrorijit
    @musicbrorijit ปีที่แล้ว +1

    Does this work for multiple users getting logged in and out at the same time?

  • @edwardzombie9222
    @edwardzombie9222 2 ปีที่แล้ว +1

    Спасибо большое за урок! Очень помог!

  • @mrek1668
    @mrek1668 2 ปีที่แล้ว

    Great video! If I'm using Django templates instead of a separate front end, can I still use JWT for authentication?

  • @achirasilva2567
    @achirasilva2567 9 หลายเดือนก่อน

    There's a issue with "utcnow()" function in newer django versions. My cookie instantly get deleted.

  • @angwamoses5005
    @angwamoses5005 3 ปีที่แล้ว

    Please, how can i use django default isAuthenticated permission instead of having to check if the token is in cookie.

  • @JohnHaroldbeltran
    @JohnHaroldbeltran ปีที่แล้ว +1

    When you use IsAuthenticated permission class, it don't work. Can you explain why?

  • @PartimeMemer
    @PartimeMemer ปีที่แล้ว

    Amazing tutorial dude

  • @IndianRiderr07
    @IndianRiderr07 3 ปีที่แล้ว +1

    Tysm. Plz login using role such admin, user,student,teacher..plz make video on this

  • @achrafbilal4200
    @achrafbilal4200 3 ปีที่แล้ว +1

    The best (from morocco)

  • @abcrectify6916
    @abcrectify6916 2 ปีที่แล้ว

    Thanks for making this video.

  • @kevinbeano1916
    @kevinbeano1916 2 ปีที่แล้ว

    great tutorial. How about the guard ?

  • @clasesutnfrc8699
    @clasesutnfrc8699 หลายเดือนก่อน

    23:50 JWT Tokens

  • @davidadu-tenkorang3186
    @davidadu-tenkorang3186 3 ปีที่แล้ว

    Can PyJWT and Simple JWT be used for a django project?
    Also when the data from the frontend gets to the backend, django raises an error with the email.
    Thank you for your attention

  • @Nguyen-i4d
    @Nguyen-i4d 3 ปีที่แล้ว

    thanks for high quality video, but i have a question for you~~
    in the Userview part,, why you attech code -> ".first()" ??
    when I want all of the logined people, how can i???

    • @ScalableScripts
      @ScalableScripts  3 ปีที่แล้ว +1

      Because filter() returns a List and I add .first() to retrieve a single object. To get all the logged in users you have to store the jwt with the user_id in a database

    • @Nguyen-i4d
      @Nguyen-i4d 3 ปีที่แล้ว +1

      @@ScalableScripts explain code??TT

  • @lawfirm3843
    @lawfirm3843 3 ปีที่แล้ว +3

    after setting username=None. i cant create superuser.

    • @AshishSingh-dn8wb
      @AshishSingh-dn8wb 3 ปีที่แล้ว

      Could you fix it?

    • @lawfirm3843
      @lawfirm3843 3 ปีที่แล้ว

      @@AshishSingh-dn8wb sorry dude. Workung with magento now.

  • @novoehuevoe9340
    @novoehuevoe9340 3 ปีที่แล้ว

    Do you know how to use JWT auth in django's admin interface?

  • @engrnasirshah4426
    @engrnasirshah4426 3 ปีที่แล้ว

    Thanks very will explanation

  • @mayankdandwani9951
    @mayankdandwani9951 3 ปีที่แล้ว

    Superb Content Bro

  • @anarbairam
    @anarbairam ปีที่แล้ว

    great explanation!

  • @okeyshourovroy2769
    @okeyshourovroy2769 3 ปีที่แล้ว +1

    Please also include permissions. Like only authenticated users can see posts.

  • @sergeysoloviov9802
    @sergeysoloviov9802 3 ปีที่แล้ว +1

    if someone have login error with str.decode blahblah. it can be fixed with freezing PyJWT==1.7.1 in requirements.txt

  • @leboyoyo
    @leboyoyo 3 ปีที่แล้ว +1

    you can change
    instead of
    User.objects.filter(id=id).first()
    you can
    User.objects.get(pk=id)
    and thank for the tuto, I'll watch the svelte part now :)

    • @baldevvermamohapatra2146
      @baldevvermamohapatra2146 2 ปีที่แล้ว

      Need help! When passing a foreign key as the id to the payload, it states Type Error and not JSON serializable.

  • @baldevvermamohapatra2146
    @baldevvermamohapatra2146 2 ปีที่แล้ว

    I'm getting type error when using a id of a foreign key of a model to reference the payload

  • @sujit_ghimire
    @sujit_ghimire ปีที่แล้ว

    how to use jwt with other models ?
    can you please make a video or help on it

  • @AshishSingh-dn8wb
    @AshishSingh-dn8wb 3 ปีที่แล้ว

    Can we use this cookie based authentication with React Native?

  • @muruganraja9
    @muruganraja9 3 ปีที่แล้ว

    Excellent tutorial,

  • @mehboobshaikh8396
    @mehboobshaikh8396 3 ปีที่แล้ว

    can you make a video on how to integrate Django rest framework with Keycloak?

  • @JohnHaroldbeltran
    @JohnHaroldbeltran ปีที่แล้ว

    I get {"detail":"Authentication credentials were not provided."}, even though I the token is already on the token. Can someone help me? Thank you.

    • @parthsoni4203
      @parthsoni4203 10 หลายเดือนก่อน

      did you find any solution for this?

  • @algorithms_hub
    @algorithms_hub 7 หลายเดือนก่อน

    This is not JWT but Token based authentication since it needs database migration but it is amazing.

  • @jaitungodhani2334
    @jaitungodhani2334 3 ปีที่แล้ว

    how i perform traditional Bearer method for above code plz tell me if you know

  • @NadirNAITYAHIA-ft7bx
    @NadirNAITYAHIA-ft7bx ปีที่แล้ว

    I can't seem to understand the purpose of the 'Authenticated User' section.

  • @assaqofi
    @assaqofi 3 ปีที่แล้ว

    thank alot this is what i am looking for, but how to update the user data ?

  • @jaitungodhani2334
    @jaitungodhani2334 3 ปีที่แล้ว

    how i fetch token data same like you when i passing token in barrier token panel
    plz tell me if any ideas

  • @Acel-01
    @Acel-01 3 ปีที่แล้ว

    GREAT Tutorial!

  • @jorgeperalta9780
    @jorgeperalta9780 7 หลายเดือนก่อน

    awesome video! Thank you!

  • @blabla-kk8bl
    @blabla-kk8bl 3 ปีที่แล้ว

    Is it refreshing jwt token automatically after expiry?

  • @gautammishra96
    @gautammishra96 3 ปีที่แล้ว

    Don't we have to invalidate the JWT before removing it?

  • @jadedanial3255
    @jadedanial3255 2 ปีที่แล้ว

    great tutorial! thumbs up!

  • @muskulanikhil3623
    @muskulanikhil3623 2 ปีที่แล้ว

    you are a life save dude