JSON Web Tokens With Django REST Framework

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • In this video I talk about how to use JSON Web Tokens (JWT) with Django REST Framework for authentication.
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    SimpleJWT: github.com/dav...
    Join my free course on building a Todo API with Django REST Framework: prettyprinted....
    Django Database Essentials: prettyprinted....
    Twitter: / pretty_printed
    Github: github.com/pre...

Комментарии • 116

  • @prettyprinted
    @prettyprinted  4 года назад +4

    Join my free course on building a Todo API with Django REST Framework: prettyprinted.com/djangotodoapi

  • @aldemarocruz9668
    @aldemarocruz9668 2 года назад

    I think this is the best video with django anfd JWT

  • @medoabdin480
    @medoabdin480 3 года назад

    you are amazing Anthony you have a very good explanation style. bless you god

  • @Myskyink
    @Myskyink 6 лет назад

    I have been following you since my days of learning flask. Your tutorials are simply the best. Please make videos on authentication, permission .

    • @prettyprinted
      @prettyprinted  6 лет назад

      Will definitely cover those topics. Thanks for watching!

  • @auroshisray9140
    @auroshisray9140 2 года назад

    Thanks man...for the simple explanation

  • @dutchprime1488
    @dutchprime1488 3 года назад

    Great tutorial, it helped me understand how the package works!

  • @minsukwon3833
    @minsukwon3833 4 года назад +2

    loved watching your series! thanks a lot

  • @johnquick7275
    @johnquick7275 3 года назад

    Outstanding video and explanation. Thank you.

  • @tomouyt
    @tomouyt 5 лет назад

    Great tutorial, straight to the point and with very good explanations.

  • @alexlindgren1
    @alexlindgren1 3 года назад

    Great tutorial series, really appreciated it!

  • @mrmuranga
    @mrmuranga 3 года назад +1

    awesome.... thanks

  • @thomasshowers6682
    @thomasshowers6682 5 лет назад +1

    I think the reason your signature was invalid on jwt.io is because you weren't using the secret from your settings.py file. When you toggle the 'secret base64 encoded' option it creates a new token using "secret" as the secret (10:50). If you put the secret from settings.py in that box and paste your token again it should work with 'secret base64 encoded' unchecked.

  • @veziop
    @veziop 2 года назад

    so if i understand correctly, this is a way of proviging an 'API token' for the users of our django REST API once we deploy it? I imagine in our documentation we include a step for acquiring the tokens only if the user inputs the relevant data into a POST method to '/api/token/' just as shown in this video. am i correct or am i missing something?

  • @ABMA79
    @ABMA79 Год назад

    My dear friend, I am a great fan of your youtube channel since I am an intermediate Django framework user. I do have a question, when do we need to make API for our application? from What I have seen, it is not obligatory unless you plan to share data with other entities or end users. So can you please tell me the goal of enabling API briefly?

  • @fabricioaugusto6324
    @fabricioaugusto6324 6 лет назад +3

    You saved my life. Thank you!

  • @sabitmahmud7652
    @sabitmahmud7652 5 лет назад +1

    hello Anthony !!As SuperUser can create lots of user according to their roll but Using JWT with DRF returns a response for Refresh and Access token. But it is impossible to define which user it is ! How can I return or pass a value by which I can able to understand what type of user it is?

  • @stanleyjohn4670
    @stanleyjohn4670 4 года назад

    I want to use a LOGOUT API that logs out the current user and deletes/removes the existing access token. The access token has an expiration date of 1 year (my requirement) but can be deleted/expire once a user logs out. How can I do this?

  • @AryanGNU
    @AryanGNU 4 года назад

    You are awesome man, Thanks a ton

  • @johncollera
    @johncollera 3 года назад

    Can you write the code to POST and get the the token... so the code will automatically get the JWT and then use that to return the data

  • @dgiri2333
    @dgiri2333 5 лет назад

    Hi how to create nested serializer like if select district then it's show model list ,if model select all village can show on villages how to implement

  • @hariprakasham
    @hariprakasham 4 года назад

    hi I have a doubt .. from where you referred paradigms .. ?? this the source of paradigms is not displayed in this video ..

  • @nguyenconghuy3847
    @nguyenconghuy3847 2 года назад

    how can I declare which api need access token and which doesn't in django

  • @harshilgohil3918
    @harshilgohil3918 5 лет назад +1

    Hello!, After installing djangorestframework_simplejwt and after updating 'DEFAULT_AUTHENTICATION_CLASSES' in settings.py and adding proper imports in urls.py .I am getting a ModuleNotFoundError: No module named 'rest_framework_simplejwt'. Is there any other dependency I need to install?
    Thanks in advance!

    • @stev3886
      @stev3886 4 года назад +1

      Did you install it in the right virtual environment? sometimes people made this mistake

  • @serhii.chumachenko
    @serhii.chumachenko 6 лет назад +3

    It's awesome! Thanks!

  • @MiRaje8086
    @MiRaje8086 3 года назад

    thank you so much man

  • @kutluaydn1508
    @kutluaydn1508 3 года назад

    I don't want to use library for jwt. Is there any source for python jwt?

  • @akshhay
    @akshhay 4 года назад +1

    How to implement this in a form in django?

  • @ChantOfSpirit
    @ChantOfSpirit 5 лет назад

    Author, what I should do with {% csrf_token %} template tag ? I can't remove it... How I can use my login/logout forms with new token?

  • @DANJUMA9
    @DANJUMA9 6 лет назад

    Simple and short!!

  • @amangautam6662
    @amangautam6662 5 лет назад

    When i'm trying to get access token and refresh token using curl command curl -X POST -H "Content-Type: application/json" -d '{"username":"myusername", "password":"mypassword"}' localhost:8000/api/token/
    i'm getting error username and password this field is required but it is working with postman api testing

  • @whateverreally
    @whateverreally 4 года назад

    Hey dude, I'm getting an error, just gonna paste it here:
    HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /authors (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
    This occurs when I'm tryna run the send.py file. Can you let me know what I can do? I kinda need help asap. Thanks bruh.

    • @whateverreally
      @whateverreally 4 года назад

      FYI, I did not use POSTMAN, I got the token directly from the website after I entered the login credentials.

  • @blog.pymastery
    @blog.pymastery 4 года назад

    Everything is well done. However, why I can't access Django Database essential, it says that 404 page not found !?
    Help, please.

  • @highskill
    @highskill 6 лет назад +1

    Thank you! 🙌

  • @ZainAli-me4qk
    @ZainAli-me4qk 4 года назад

    Can you please tell me how to create multi-users like Sellers buyers and admin with their roles i need model and serializers for 3 users model. Please help

  • @alexanderlabrador5608
    @alexanderlabrador5608 6 лет назад

    how can I consume this api from a fronent or an html with ajx ?

  • @jonathanma4501
    @jonathanma4501 3 года назад +1

    Hi, this was a great video. I have a question - like in the video, you created an access/refresh token with a given username and password. But what if you want to only allow some users to make the access/refresh token? For example, only paid users, or only users who have registered as an account? Would I have to implement logic in the views so that it checks with a database for preexisting users, or do I have to create a signed url to get access to make the token? What's the best way of restricting token creation? Or, should I have only a server side application connect to this resource api to create the access/refresh token, which I then pass to the frontend as a response?

    • @veziop
      @veziop 2 года назад

      i find this question interesting

    • @abhishektayal480
      @abhishektayal480 2 года назад

      For that we have to use permissions along with jwt.

  • @politicallynotcorrect2968
    @politicallynotcorrect2968 4 года назад

    how do i create a routh only for auth users

  • @sumitprakash2747
    @sumitprakash2747 4 года назад

    Hi I am getting
    ModuleNotFoundError at /
    No module named 'rest_framework_simplejwt'

  • @mrmuranga
    @mrmuranga 4 года назад

    Really simple to use......thanks Anthony...
    Compared with Django Rest Knox would you say JWT is more secure or faster ?

  • @dcatalyst6271
    @dcatalyst6271 4 года назад

    hey can you make a Django snowflake database connection video I have searched allot but not found the solution anywhere

  • @frostsmaker8966
    @frostsmaker8966 4 года назад

    How to get user_id from the access token/ authenticated user in views.py?? I want to use the object manager to get data using user_id.

  • @victorazuara3346
    @victorazuara3346 6 лет назад

    Excellent, thank you

    • @prettyprinted
      @prettyprinted  6 лет назад +1

      You're welcome. Thanks for watching.

  • @manhha3010932
    @manhha3010932 6 лет назад

    Hi! I'm counfusing after learn Django Rest framework, what django REST do? how to render those data to front end? because this is just pure data, how to use it in front? I am beginer so sorry if dumb question, thanks !

    • @prettyprinted
      @prettyprinted  6 лет назад

      If you want to display data, you can use the traditional template features of Django. Another way to render pure data is by using a frontend framework like React. I recommend looking into templates first though.

  • @Skaxarrat
    @Skaxarrat 6 лет назад +1

    I did this series two times, from scratch, but when I get to this point I start to have issues. I've 'pip installed' rest_framework_simplejwt', added it to settings.py and created the two endpoints to 'api/token' and 'api/token/refresh', yet I still don't get the 'Authentication credentials are not provided' message. Anyone is having the same issue as me and fixed it?
    Keep in mind I've tried this two times from scratch

    • @fester6537
      @fester6537 6 лет назад

      From what I can tell your permission is set to 'permissions.IsAuthenticatedOrReadOnly' instead of 'permissions.IsAuthenticated'. It should works if you change both permission in your settings.py and your LanguageView.

    • @niteshrawat576
      @niteshrawat576 5 лет назад

      are declaring permission class as AllowAny or authentication class as IsAuthorizedOrReadOnly? If yes, then please don't.

    • @davidmutua6971
      @davidmutua6971 5 лет назад

      Actually this is not a problem you must make sure first your local django development server is running. The message may vary like mine too doesn't show that when I post using postman but it does when using "Insomnia" software. It's similar to postman but simpler. Postman is a beast though.

  • @nagaraja4846
    @nagaraja4846 5 лет назад

    how can i generate jwt custom token for django api...Thank You Advance.

  • @toufanialfarisi1866
    @toufanialfarisi1866 5 лет назад

    it's really really awesome

  • @msasoftware
    @msasoftware 4 года назад

    :) Excelent. Thanks you so much

  • @msasoftware
    @msasoftware 4 года назад

    More options in: www.django-rest-framework.org/api-guide/authentication/#third-party-packages

  • @shubhamkumar9484
    @shubhamkumar9484 4 года назад +2

    from where paradigms came i lost it there

  • @christianmagnus1003
    @christianmagnus1003 4 года назад +1

    Hello buddy, i have a questions, that username and password was by the Admin user really? i mean that token is only for superuser in django rest framework, not for normal users yes?

    • @huzaifquazi
      @huzaifquazi 4 года назад

      how can i get token for user and not admin ?

  • @swaali1
    @swaali1 6 лет назад

    hello , can i use it for cb token adder thankssssssssssssss

  • @MrIgorbpf
    @MrIgorbpf 6 лет назад

    Great video, man! Could u do a series using djoser and JWT of the whole process of authentication? I men signup, login, password reset, email and etc. That would be awesome!

    • @prettyprinted
      @prettyprinted  6 лет назад +1

      I'll look into djoser. Thanks for the idea.

    • @abirulezz
      @abirulezz 6 лет назад +1

      oh yeah please do!

  • @CerebroVasconcelos
    @CerebroVasconcelos 5 лет назад

    Thanks for to do this video

  • @rayaangrewal1035
    @rayaangrewal1035 5 лет назад

    awesome

  • @sankarbathula8758
    @sankarbathula8758 6 лет назад

    Thanks a lot...!

  • @amirshehzad3352
    @amirshehzad3352 5 лет назад

    @Pretty Printed How are you connecting python in Ubuntu Bash with VScode?

    • @prettyprinted
      @prettyprinted  5 лет назад

      I don't actually. I keep them separate. I eventually need to connect them though.

  • @xtremehackerzpro9511
    @xtremehackerzpro9511 6 лет назад

    Excellent :)

  • @chesterholt5551
    @chesterholt5551 5 лет назад

    Superb

  • @wayneloo8234
    @wayneloo8234 6 лет назад

    That's really cool. But I think the user login is validating against the user model in the database. What if we're using external methods like ldap? How does it work? Do you have a video on that?

    • @prettyprinted
      @prettyprinted  6 лет назад

      No video on ldap, but I'll consider it for the future.

  • @georgesmith3022
    @georgesmith3022 5 лет назад +1

    by default, for how long is the token valid?

    • @prettyprinted
      @prettyprinted  5 лет назад +1

      Five minutes. You can see the defaults here: github.com/davesque/django-rest-framework-simplejwt#settings

    • @georgesmith3022
      @georgesmith3022 5 лет назад

      @@prettyprinted thanks

  • @nurizzati5892
    @nurizzati5892 5 лет назад

    i hope you do token based authentication with django rest framework

    • @prettyprinted
      @prettyprinted  5 лет назад

      I'll probably cover that in the future.

  • @bravmi
    @bravmi 6 лет назад

    You rock dude

  • @SidonDuarte
    @SidonDuarte 6 лет назад

    What is the differences between "django-rest-framework-jwt' and "django-rest-framework-simplejwt ( github.com/davesque/django-rest-framework-simplejwt ), what its advantages and drawbacks for each one?

    • @prettyprinted
      @prettyprinted  6 лет назад +1

      Generally the differences between any similar libraries are just the patterns. So try out both and see which pattern you like best.

  • @kancharlanikhilsai9838
    @kancharlanikhilsai9838 6 лет назад +1

    I was looking for this type of video and got yours. Excellent video. Thank you so much.
    The username and password are from auth_user table in db. Is there any way to take username and password from another table we create for storing users.

    • @prettyprinted
      @prettyprinted  6 лет назад

      Everything in DRF can be customized, but it takes more code. But yeah, you can change to a different database.

    • @kancharlanikhilsai9838
      @kancharlanikhilsai9838 6 лет назад +1

      where to modify the code to get the user details along with the tokens generated.

    • @mdk124
      @mdk124 4 года назад

      @@prettyprinted Is there a direction that we can look at for this?

    • @mdk124
      @mdk124 4 года назад

      @@kancharlanikhilsai9838 Hi! Did you manage to solve this issue you were facing?

  • @ahadulislam8891
    @ahadulislam8891 5 лет назад

    Nice Video bro. But is there any way to use JWT without DRF(Django Rest Framework ). Thank You

    • @prettyprinted
      @prettyprinted  5 лет назад

      Yeah, check out my JWT videos with Flask. The concept will be the same in Django.

  • @learnwithfun147
    @learnwithfun147 6 лет назад

    Hey Pretty good job man. Can you do Class Based View tuths. Waiting for it :)

    • @prettyprinted
      @prettyprinted  6 лет назад +1

      Yep, that's on the list. Thanks for watching.

  • @JonesDTaylor
    @JonesDTaylor 6 лет назад

    Hi Anthony
    Your videos are nice. Can you please show the audiance where do you get your code from ? for instance the settings.py changes for token authentication. It helps if you show the location (obviousily from the official doc of restframework) from which you get the code. Thank you

    • @prettyprinted
      @prettyprinted  6 лет назад

      It's not practical for me to give all the locations in the docs, but the extension's documentation isn't too complicated so you should be able to see if it you go to the relevant section.

  • @georgesmith3022
    @georgesmith3022 5 лет назад

    are the google api keys jwt tokens?

  • @oluwafemimatthew3501
    @oluwafemimatthew3501 6 лет назад

    Is there any reason behind your choice of github.com/davesque/django-rest-framework-simplejwt as against a more established github.com/GetBlimp/django-rest-framework-jwt. Nice video by the way, clear and concise

    • @prettyprinted
      @prettyprinted  6 лет назад

      No particular reason. If you can use, then you should be able to figure out the other. Thanks for watching.

  • @gopalsivethna2959
    @gopalsivethna2959 6 лет назад

    hello sir i am brown person and u r smartents black person i know, thanks for the help!

  • @estebanmejia9989
    @estebanmejia9989 4 года назад

    Great, please enumerate your videos.

  • @eduardorodriguezperez704
    @eduardorodriguezperez704 5 лет назад

    pip install djangorestframework_simplejwt

  • @eshaanbansal9122
    @eshaanbansal9122 4 года назад

    Flask > Django.