我目前有一个利用 Django REST 框架的大型 Django 项目。
我有另一个较小的 Django 项目,我想在主要项目的基础上构建该项目,该项目不直接共享数据库,而是通过 API 获取必要的数据。
我想覆盖较小项目的 AUTHENTICATION_BACKEND 并让它使用较大项目的 API auth 端点作为身份验证器。
基本上流程如下:
是否有值得在此用例中使用的现有插件,还是我应该编写自己的 AUTHENTICATION_BACKEND?
最佳答案
听起来您可能想查看 django-rest-framework-jwt .这将允许您使用 JWT 作为您的身份验证机制,它可以轻松处理您的情况。该项目实际上提供了一个专门用于您想要的端点,verify_jwt_token
.根据documentation :
In some microservice architectures, authentication is handled by a single service. Other services delegate the responsibility of confirming that a user is logged in to this authentication service. This usually means that a service will pass a JWT received from the user to the authentication service, and wait for a confirmation that the JWT is valid before returning protected resources to the user.
因此,您的工作流程将类似于:
verify_jwt_token
大型 API 中的端点 关于django - 使用 Django REST Framework 作为 Django 的身份验证后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631141/