Django - DRF自带的token认证和JWT区别
Posted allen2333
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django - DRF自带的token认证和JWT区别相关的知识,希望对你有一定的参考价值。
问题重现
当查看DRF 文档时发现DRF内置的token是存储在数据库里,这和我在网上搜索资料时认识的token-based authentication有出入。
from rest_framework.authtoken.models import Token # 有Token这个model
原因
其实网上大多数的token是json web token,是和DRF自带的token不同的。JWT只存储在客户端。
引用DRF文档:
JSON Web Token is a fairly new standard which can be used for token-based authentication. Unlike the built-in TokenAuthentication scheme, JWT Authentication doesn‘t need to use a database to validate a token. A package for JWT authentication is djangorestframework-simplejwt which provides some features as well as a pluggable token blacklist app.
参考
- https://www.django-rest-framework.org/api-guide/authentication/#json-web-token-authentication
- https://stackoverflow.com/questions/57442082/why-django-rest-framework-stores-token-in-database?noredirect=1#comment101361728_57442082
- https://stackoverflow.com/questions/29440014/should-i-use-jwt-or-basic-token-authentication-in-django-rest-framework
- https://stackoverflow.com/questions/27578726/appropriate-choice-of-authentication-class-for-python-rest-api-used-by-web-app
- https://stackoverflow.com/questions/31600497/django-drf-token-based-authentication-vs-json-web-token
以上是关于Django - DRF自带的token认证和JWT区别的主要内容,如果未能解决你的问题,请参考以下文章
签发token校验token多方式登录签发token的实现自定义认证反爬规则的认证类admin使用自定义User表:新增用户密码密文群查接口各种筛选组件数据准备drf搜索过滤组件drf排