首页 > 解决方案 > 从 jwt 身份验证中的身份验证 api 获取自定义标头

问题描述

我正在使用 JWT 身份验证,并且我使用了 Authenticate 方法,如下所示:

class ModelBackendCustom(ModelBackend):
    """
    This backend is to be used when the server is handling authentication
    from an LDAP or Active Directory service.
    By default, the ``authenticate`` method creates ``User`` objects for
    usernames that don't already exist in the database.  Subclasses can disable
    this behavior by setting the ``create_unknown_user`` attribute to
    ``False``.
    """
    def authenticate(self, request, username=None, password=None, **kwargs):
        logger.info("Trying to authenticate the user %s against the database" % subject_dn)
        user = super(ModelBackendCustom, self).authenticate(request, username, password, **kwargs)

        # Check DB groups against mapping
        if user:
            if user.is_authenticated:
                logger.info("Authenticate the user %s against the database with success" % subject_dn)
                user = self.configure_user(request, user)
                return user
            else:
                logger.info("Authenticate the user %s against the database failed by giving a non authenticated user" % subject_dn)
        else:
            logger.info("Authenticate the user %s against the database failed" % subject_dn)


        return None

当我只在我的请求中使用用户名密码并且我通常会收到我的令牌时,我已经完成了这一切。我现在想从身份验证请求中使用标头,但请求始终为 None 。谁有一个想法,如何解决这个问题或一种方法来覆盖身份验证方法以获得标题。谢谢

标签: authenticationdjango-rest-frameworkjwt

解决方案


推荐阅读