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...
Join my free course on building a Todo API with Django REST Framework: prettyprinted.com/djangotodoapi
I think this is the best video with django anfd JWT
you are amazing Anthony you have a very good explanation style. bless you god
I have been following you since my days of learning flask. Your tutorials are simply the best. Please make videos on authentication, permission .
Will definitely cover those topics. Thanks for watching!
Thanks man...for the simple explanation
Great tutorial, it helped me understand how the package works!
loved watching your series! thanks a lot
Thanks for watching!
Outstanding video and explanation. Thank you.
Great tutorial, straight to the point and with very good explanations.
Thanks for watching!
Great tutorial series, really appreciated it!
awesome.... thanks
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.
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?
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?
You saved my life. Thank you!
Glad i could help!
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?
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?
You are awesome man, Thanks a ton
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
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
hi I have a doubt .. from where you referred paradigms .. ?? this the source of paradigms is not displayed in this video ..
how can I declare which api need access token and which doesn't in django
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!
Did you install it in the right virtual environment? sometimes people made this mistake
It's awesome! Thanks!
Thanks for watching!
thank you so much man
I don't want to use library for jwt. Is there any source for python jwt?
How to implement this in a form in django?
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?
Simple and short!!
Thanks for watching!
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
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.
FYI, I did not use POSTMAN, I got the token directly from the website after I entered the login credentials.
Everything is well done. However, why I can't access Django Database essential, it says that 404 page not found !?
Help, please.
Thank you! 🙌
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
how can I consume this api from a fronent or an html with ajx ?
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?
i find this question interesting
For that we have to use permissions along with jwt.
how do i create a routh only for auth users
Hi I am getting
ModuleNotFoundError at /
No module named 'rest_framework_simplejwt'
Really simple to use......thanks Anthony...
Compared with Django Rest Knox would you say JWT is more secure or faster ?
hey can you make a Django snowflake database connection video I have searched allot but not found the solution anywhere
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.
Excellent, thank you
You're welcome. Thanks for watching.
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 !
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.
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
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.
are declaring permission class as AllowAny or authentication class as IsAuthorizedOrReadOnly? If yes, then please don't.
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.
how can i generate jwt custom token for django api...Thank You Advance.
it's really really awesome
Thanks!
:) Excelent. Thanks you so much
More options in: www.django-rest-framework.org/api-guide/authentication/#third-party-packages
from where paradigms came i lost it there
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?
how can i get token for user and not admin ?
hello , can i use it for cb token adder thankssssssssssssss
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!
I'll look into djoser. Thanks for the idea.
oh yeah please do!
Thanks for to do this video
You're welcome! Thanks for watching.
awesome
Thanks a lot...!
You're welcome! Thanks for watching.
@Pretty Printed How are you connecting python in Ubuntu Bash with VScode?
I don't actually. I keep them separate. I eventually need to connect them though.
Excellent :)
Superb
Thanks for watching.
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?
No video on ldap, but I'll consider it for the future.
by default, for how long is the token valid?
Five minutes. You can see the defaults here: github.com/davesque/django-rest-framework-simplejwt#settings
@@prettyprinted thanks
i hope you do token based authentication with django rest framework
I'll probably cover that in the future.
You rock dude
Thanks for watching!
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?
Generally the differences between any similar libraries are just the patterns. So try out both and see which pattern you like best.
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.
Everything in DRF can be customized, but it takes more code. But yeah, you can change to a different database.
where to modify the code to get the user details along with the tokens generated.
@@prettyprinted Is there a direction that we can look at for this?
@@kancharlanikhilsai9838 Hi! Did you manage to solve this issue you were facing?
Nice Video bro. But is there any way to use JWT without DRF(Django Rest Framework ). Thank You
Yeah, check out my JWT videos with Flask. The concept will be the same in Django.
Hey Pretty good job man. Can you do Class Based View tuths. Waiting for it :)
Yep, that's on the list. Thanks for watching.
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
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.
are the google api keys jwt tokens?
No, they're tokens specific to Google.
@@prettyprinted thanks for answering
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
No particular reason. If you can use, then you should be able to figure out the other. Thanks for watching.
hello sir i am brown person and u r smartents black person i know, thanks for the help!
Umm thanks.
Great, please enumerate your videos.
pip install djangorestframework_simplejwt
Flask > Django.