2015-12-17 45 views
0

我使用django-rest-framework和mongoengine作爲我的REST API和Angular JS的後端框架作爲前端。如何使用自定義用戶文檔實現JSON Web令牌(JWT)認證?我已檢查此鏈接http://getblimp.github.io/django-rest-framework-jwt/。 但它只支持使用Auth User模型的django-rest。我如何繼續這樣做?我應該嘗試使用Python庫https://pyjwt.readthedocs.org/en/latest/installation.html?來實現它。所有建議都歡迎。 謝謝。如何使用DRF(Django rest框架)和mongoengine實現JSON Web Token?

回答

1

你可能想在你的設置來配置文件

AUTH_USER_MODEL = 'your_custom_user_class 

https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model

然後,您可以繼續使用DRF的驗證類:

REST_FRAMEWORK = { 
    ... 
    'DEFAULT_AUTHENTICATION_CLASSES': (
     'rest_framework_jwt.authentication.JSONWebTokenAuthentication', 
    ), 
    ... 
} 
+0

在SQLAlchemy中的情況下,是什麼ORM而不是MyUser(models.Model):我有MyUser(Base): –

相關問題