๐ป Token Authentication and CORS ๐ป
Posted on Sep 19th, 2022
๐๏ธ Todayโs Topics
- Token authentication in DRF with Djoser
- CORS headers
๐ฏ Collaborative Project
Work with your team. Tonight, plan out your models โ please draw a diagram! โ and write down a list of the endpoints you think you will need. It should take you some time to talk this through. What data will those endpoints have to return? Will your endpoints need to accept any data (remember you can do this in the body of the request or using part of the URL)?
Your list of planned endpoints should look something like (this is a partial list using examples from Habit Tracker. Youโre going to need a bunch more endpoints than this). Keep in mind that you should include endpoints ONLY if you need them, so consider the actions that you need to support according to the project requirements.
Example planning for endpoints (youโll need more than these, of course):
Request URL | ย | Description |
---|---|---|
GET api/habits |
ย | returns a list of all habits for the authenticated user |
GET api/habits/<int:pk> |
ย | returns details about one habit and its associated records |
POST api/habits |
ย | create a new habit |
๐ซ No writing code yet! Today should be used for planning only. Weโll cover working together on GitHub tomorrow.
๐ Read | ๐บ Watch | ๐ง Listen
- ๐บ Finally Understand Auth in DRF - a Will Vincent talk -> Will isnโt using the Djoser library but he does a great job of reviewing different auth strategies and why you would choose one or the other. Watch this for a better understanding and overview of authentication.
- ๐ Julia Evans comic explaining CORS better than MDN does
- ๐ More Julia Evans on the Same Origin Policy
- ๐ Simple Is Better Than Complex: How to Implement Token Authentication in DRF This does NOT use Djoser, but itโs a great walkthrough of some of what Djoser does for you if you would like more detail.
๐ Resources
Authentication
- Djoser documentation
- DRF docs: Token-based authentication
- The Ultimate Tutorial for Django REST Framework: Login and Authentication This uses the Djoser library.