首页 > 其他分享 >认证组件 LL

认证组件 LL

时间:2024-03-13 11:13:48浏览次数:17  
标签:LL jwt rest 认证 framework authentication 组件 import


1、authentication

"""
系统:session认证
rest_framework.authentication.SessionAuthentication
ajax请求通过认证:
cookie中要携带 sessionid、csrftoken,请求头中要携带 x-csrftoken

第三方:jwt认证 
rest_framework_jwt.authentication.JSONWebTokenAuthentication
ajax请求通过认证:
请求头中要携带 authorization,值为 jwt空格token

自定义:基于jwt、其它
1)自定义认证类,继承BaseAuthentication(或其子类),重写authenticate
2)authenticate中完成
    拿到认证标识 auth
    反解析出用户 user
    前两步操作失败 返回None => 游客
    前两步操作成功 返回user,auth => 登录用户
    注:如果在某个分支抛出异常,直接定义失败 => 非法用户
"""

 

2、自定义认证类:基于jwt

from rest_framework.exceptions import AuthenticationFailed
import jwt
from rest_framework_jwt.authentication import BaseJSONWebTokenAuthentication
from rest_framework_jwt.authentication import jwt_decode_handler

 

3、普通自定义认证类

from rest_framework.authentication import BaseAuthentication
def authenticate(self, request):
    auth = 从request中得到
    user = 从auth中得到
    if not user:
        return None
    return user, auth

 

标签:LL,jwt,rest,认证,framework,authentication,组件,import
From: https://www.cnblogs.com/97zs/p/18070182

相关文章

  • 权限组件 LL
    1、permission"""系统:1)AllowAny:允许所有用户,校验方法直接返回True2)IsAuthenticated:只允许登录用户必须request.user和request.user.is_authenticated都通过3)IsAuthenticatedOrReadOnly:游客只读,登录用户无限制get、option、head请求无限制前台请求必须校验......
  • 五个视图扩展类 LL
    作用:提供了几种后端视图(对数据资源进行曾删改查)处理流程的实现,如果需要编写的视图属于这五种,则视图可以通过继承相应的扩展类来复用代码,减少自己编写的代码量。这五个扩展类需要搭配GenericAPIView父类,因为五个扩展类的实现需要调用GenericAPIView提供的序列化器与数据库查询的......
  • 七个子类视图 LL
     1)CreateAPIView提供post方法继承自:GenericAPIView、CreateModelMixin2)ListAPIView提供get方法继承自:GenericAPIView、ListModelMixin3)RetrieveAPIView提供get方法继承自:GenericAPIView、RetrieveModelMixin4)DestoryAPIView提供delete方法继承自:GenericAP......
  • linux Shell 命令行-07-func 函数
    拓展阅读linuxShell命令行-00-intro入门介绍linuxShell命令行-02-var变量linuxShell命令行-03-array数组linuxShell命令行-04-operator操作符linuxShell命令行-05-test验证是否符合条件linuxShell命令行-06-flowcontrol流程控制linuxShell命令行-07-f......
  • 两个视图基类 LL
    1、APIViewrest_framework.views.APIView APIView是RESTframework提供的所有视图的基类,继承自Django的View父类。APIView与View的不同之处在于:传入到视图方法中的是RESTframework的Request对象,而不是Django的HttpRequeset对象;视图方法可以返回RESTframework的Respons......
  • springcloud 基础组件-Feign 调用流程
    原图来自:https://blog.csdn.net/luanlouis/article/details/82821294所有注册的feignclientorg.springframework.cloud.openfeign.FeignAutoConfiguration#feignContext决定使用哪种client的地方org.springframework.cloud.openfeign.FeignAutoConfiguration.OkHttpFeignCo......
  • docker-compose 部署apollo
    apollo-1.9.2docker-compose.yamlversion:'3'services:#模拟一个正常的mysql数据库mysql8:image:mysql:5.7restart:alwayscontainer_name:mysqlports:-3306:3306volumes:-./databases/mysql/logs:/var/log/mysql......
  • 07-ElementPlus组件库
    ElementPlus简介ElementPlus是饿了么团队研发的,基于Vue3的组件库准备工作:创建工程化的Vue项目选择TypeScript参照官方文档安装ElementPlus组件库(当前工程的目录下)npminstallelement-plus--savemain.ts中引入ElementPlus组件库参照官方文档//main.tsimpor......
  • 06-TDesign组件库
    TDesign具有统一的价值观,一致的设计语言和视觉风格,帮助用户形成连续、统一的体验认知。在此基础上,TDesign提供了开箱即用的UI组件库、设计指南和相关设计资产,以优雅高效的方式将设计和研发从重复劳动中解放出来,同时方便大家在TDesign的基础上扩展,更好的的贴近业务需求。......
  • 错误:在 /tmp/easy_install-rad8_t5b/PyQt5-5.14.0.tar.gz #15 中找不到安装脚本
    thePyQt55.14.0isbrokenbecausecan'tnotinstallonresppi3.youcantoinstallaversionofPyQt5thatworkingfineonresp.followthesteps:PyQt55.14.0已损坏,因为无法无法安装在resppi3上。您可以安装一个在resp上运行良好的PyQt5版本,请按照以下......