如何使用DRF(Django rest框架)和mongoengine实现JSON Web令牌?

问题描述 投票:0回答:1

我正在使用django-rest-framework和mongoengine作为REST API的后端框架,并使用Angular JS作为前端。如何使用自定义用户文档实现JSON Web令牌(JWT)身份验证?我已经检查了此链接https://jpadilla.github.io/django-rest-framework-jwt/。但它仅支持Auth User模型的django-rest。我该如何处理?我应该尝试使用python库https://pyjwt.readthedocs.org/en/latest/installation.html来实现它吗?欢迎所有建议。谢谢。

django django-rest-framework jwt mongoengine
1个回答
1
投票

您可能要在设置文件中进行配置

AUTH_USER_MODEL = 'your_custom_user_class

请参见https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#substituting-a-custom-user-model

然后您可以继续使用Django Rest Framework的身份验证类:

REST_FRAMEWORK = {
    ...
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.