zoukankan      html  css  js  c++  java
  • drf——drf认证功能源码分析

    一、drf认证功能源码分析

    1 APIView---》dispatch---》self.initial(request, *args, **kwargs)--》self.perform_authentication(request)
    ---》Request.user--->self._authenticate(self):Request类的方法---》self.authenticators:Request类的属性---》在Request对象实例化的时候传入的
    ----》Request在什么时候实例化的?dispatch的时候
    ---》APIView:self.get_authenticators()--》return [auth() for auth in self.authentication_classes]
    ----》如果在自己定义的视图类中写了authentication_classes=[类1,类2]----》Request的self.authenticators就变成了我们配置的一个个类的对象 2 self._authenticate(self):Request类的方法 def _authenticate(self): for authenticator in self.authenticators: # BookView中配置的一个个类的对象 try: user_auth_tuple = authenticator.authenticate(self) except exceptions.APIException: self._not_authenticated() raise if user_auth_tuple is not None: self._authenticator = authenticator self.user, self.auth = user_auth_tuple return 3 只要在视图类中配置authentication_classes = [MyAuthen.LoginAuth, ] 就会执行上面的方法,执行认证
  • 相关阅读:
    Win32.Dfcsvc.A
    清除“熊猫烧香”(Worm.WhBoy.h、尼姆亚、FuckJacks)
    个人网站如何提高网站的Google PR值
    ROSE病毒
    vc二进制数值字符相互转换
    全flash站制作剖析
    C#.NET 中的类型转换
    .net开发常用工具
    xflash里的hello world程序
    什么是XHTML
  • 原文地址:https://www.cnblogs.com/guojieying/p/13956126.html
Copyright © 2011-2022 走看看