Django API Authentication using JWT Tokens

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

КОМЕНТАРІ • 205

  • @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 7 місяців тому +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 6 місяців тому

      share link for the optimized way

    • @Shamir-qb1ih
      @Shamir-qb1ih 3 місяці тому

      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?

  • @RONALDO362009
    @RONALDO362009 7 днів тому

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

  • @shagilislam2533
    @shagilislam2533 5 місяців тому +2

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

  • @learningchannel4001
    @learningchannel4001 2 роки тому +8

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

  • @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

  • @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

  • @bilaltufaildev
    @bilaltufaildev 7 місяців тому +1

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

  • @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.

  • @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 ?

  • @ArghyaBhattacharyaNITA
    @ArghyaBhattacharyaNITA 3 роки тому +3

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

  • @abbaskareem5281
    @abbaskareem5281 Рік тому

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

  • @EveryGameArchive
    @EveryGameArchive Рік тому

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

  • @shubhamathawane02
    @shubhamathawane02 7 місяців тому +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 ?

  • @dabalayonas1340
    @dabalayonas1340 2 місяці тому +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

  • @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.

  • @sushovitshah9083
    @sushovitshah9083 7 місяців тому

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

  • @understand1004
    @understand1004 Рік тому +3

    26:10
    dont need to .decode("utf-8")
    just
    token = jwt.encode(payload, 'secret', algorithm='HS256')
    that's it

  • @nicolasportelli3766
    @nicolasportelli3766 2 роки тому

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

  • @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

  • @edwardwalsh1115
    @edwardwalsh1115 Рік тому +2

    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.

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

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

  • @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

  • @thabosiphiwemngoma1859
    @thabosiphiwemngoma1859 10 місяців тому

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

  • @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

  • @imcamilaaa
    @imcamilaaa 3 роки тому +12

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

  • @allanalais7859
    @allanalais7859 2 роки тому +3

    How can I create super users?

  • @Nikhil-Tomar
    @Nikhil-Tomar Рік тому +1

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

  • @HEATER_APP
    @HEATER_APP Рік тому

    super straightforward and concise, great job!

  • @mrek1668
    @mrek1668 Рік тому

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

  • @nicklennonfortes9611
    @nicklennonfortes9611 2 роки тому

    best teacher ever

  • @Craennie
    @Craennie 9 місяців тому +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

  • @pradyumnabharadwaja8237
    @pradyumnabharadwaja8237 Рік тому

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

  • @achrafbilal4200
    @achrafbilal4200 3 роки тому +1

    The best (from morocco)

  • @ivanromanov7120
    @ivanromanov7120 11 місяців тому

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

  • @davidadu-tenkorang3186
    @davidadu-tenkorang3186 3 роки тому +3

    Excellent work. Thank you

  • @muskulanikhil3623
    @muskulanikhil3623 2 роки тому

    you are a life save dude

  • @musicbrorijit
    @musicbrorijit Рік тому +1

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

  • @luisematos_
    @luisematos_ 2 роки тому

    I have to say THANK YOU!

  • @roamandlift
    @roamandlift 3 роки тому +1

    Such a dope explanation 🔥🔥🔥

  • @shashishekhar----
    @shashishekhar---- Рік тому

    Great content, subscribed !

  • @manolismandamadiotis5853
    @manolismandamadiotis5853 2 роки тому +1

    very helpful video and keeping it simple tthanks!

  • @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.

  • @medd4545
    @medd4545 5 місяців тому

    Does this work with a flutter frontend

  • @sorooshmoghimi5494
    @sorooshmoghimi5494 Рік тому

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

  • @keshavachandu99
    @keshavachandu99 6 місяців тому

    I learnt a lot here Thank You !!!

  • @JohnHaroldbeltran
    @JohnHaroldbeltran Рік тому +1

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

  • @frankydubi
    @frankydubi 2 роки тому

    The biggest THANK YOU!

  • @adhy612000151
    @adhy612000151 10 місяців тому +1

    Thanks a lot good man!
    God always bless you!

    • @adhy612000151
      @adhy612000151 10 місяців тому

      Many Many Thanks For you good man!

  • @edwardzombie9222
    @edwardzombie9222 2 роки тому +1

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

  • @윤현영-i4d
    @윤현영-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

    • @윤현영-i4d
      @윤현영-i4d 3 роки тому +1

      @@ScalableScripts explain code??TT

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

    This is tutorials is awesome.. Thanks a lot

  • @abcrectify6916
    @abcrectify6916 2 роки тому

    Thanks for making this video.

  • @RidGamTech-Gopal
    @RidGamTech-Gopal 3 роки тому +1

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

  • @algorithms_hub
    @algorithms_hub 5 місяців тому

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

  • @ВладМицкевич-о1и
    @ВладМицкевич-о1и 9 місяців тому

    thank you very much. excellent presentation of the material

  • @marcellacarvalho6705
    @marcellacarvalho6705 2 роки тому

    Thank you for this. You are awesome!

  • @Travellife8877
    @Travellife8877 3 роки тому

    just osm content and step by step explaination

  • @jorgeperalta9780
    @jorgeperalta9780 5 місяців тому

    awesome video! Thank you!

  • @kevinbeano1916
    @kevinbeano1916 2 роки тому

    great tutorial. How about the guard ?

  • @shadmanlatif6530
    @shadmanlatif6530 2 роки тому

    Legit helped me

  • @PartimeMemer
    @PartimeMemer Рік тому

    Amazing tutorial dude

  • @anarbairam
    @anarbairam Рік тому

    great explanation!

  • @hyunjungoh6672
    @hyunjungoh6672 3 роки тому

    I love this video!!!!! the best ever!

  • @_nishadkv
    @_nishadkv 3 роки тому

    Helps a lot.. Thanks buddy

  • @maksymmalicki2720
    @maksymmalicki2720 Рік тому

    Amazing tutorial, thank you very much!

  • @johntygomes6519
    @johntygomes6519 3 роки тому

    Very Greeat Explanation Sir...ThankYou

  • @rashedulhasanporosh7722
    @rashedulhasanporosh7722 2 роки тому

    Thank you so much. It was a great help!

  • @Acel-01
    @Acel-01 3 роки тому

    GREAT Tutorial!

  • @omarchristie3923
    @omarchristie3923 6 місяців тому

    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.

  • @paasxx
    @paasxx Рік тому

    Superb content, very helpful

  • @NiM44
    @NiM44 2 роки тому

    Very well explained , Thanks

  • @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 ?

  • @duberlyivanmondragonmancha6198

    Good video!!

  • @thaminduKavinda
    @thaminduKavinda 3 роки тому +1

    Super Helpful great tutorial. Thanks a lot.

  • @k1vz_
    @k1vz_ 4 місяці тому

    very nice, thank you!!

  • @engrnasirshah4426
    @engrnasirshah4426 3 роки тому

    Thanks very will explanation

  • @mayankdandwani9951
    @mayankdandwani9951 3 роки тому

    Superb Content Bro

  • @achirasilva2567
    @achirasilva2567 7 місяців тому

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

  • @aleksandrsemenov1764
    @aleksandrsemenov1764 2 роки тому

    Great job, thanks!

  • @jadedanial3255
    @jadedanial3255 Рік тому

    great tutorial! thumbs up!

  • @user-dev953
    @user-dev953 2 роки тому

    This was very helpful thank you

  • @nguyenichthanhtu8502
    @nguyenichthanhtu8502 2 роки тому

    This is Awesome, helpful for me. Thanks

  • @NadirNAITYAHIA-ft7bx
    @NadirNAITYAHIA-ft7bx Рік тому

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

  • @lawfirm3843
    @lawfirm3843 3 роки тому +3

    after setting username=None. i cant create superuser.

  • @novoehuevoe9340
    @novoehuevoe9340 3 роки тому

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

  • @Developer_python_
    @Developer_python_ 8 місяців тому

    The best movie that I saw!

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

    Thank you so so much brother

  • @angwamoses5005
    @angwamoses5005 3 роки тому

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

  • @SalimDria
    @SalimDria Рік тому

    where are the token stored ? in the user table ??

  • @assaqofi
    @assaqofi 3 роки тому

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

  • @muruganraja9
    @muruganraja9 3 роки тому

    Excellent tutorial,

  • @DevBishwasBh
    @DevBishwasBh 2 роки тому +1

    Thanks but please do `NextAuth` with Django Rest Framework, with email and password. Also, adding OAuth on the same tutorial will be great. I am desperetely waiting for your response.

  • @juiceearthhh7225
    @juiceearthhh7225 5 місяців тому

    Thanks helped a lot

  • @vignesh5618
    @vignesh5618 3 роки тому +2

    Came from freecodecamp

  • @blabla-kk8bl
    @blabla-kk8bl 3 роки тому

    Is it refreshing jwt token automatically after expiry?

  • @sujit_ghimire
    @sujit_ghimire Рік тому

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

  • @majmunovski
    @majmunovski 3 роки тому

    Thank you very much!

  • @jakubrudy9372
    @jakubrudy9372 3 роки тому

    thank you for this tutorial very much!

  • @yaroslavstetsko4174
    @yaroslavstetsko4174 2 роки тому

    It is perfect tutorial, thank u, and continue.