[英]How can I authenticate a user who belongs to another database through my other microservice in django rest framework?
I'm new to django and I am required to create two microservices with separate databases;我是 django 的新手,我需要创建两个具有不同数据库的微服务;
One to hold user information and the other to hold todo/tasks information.一个保存用户信息,另一个保存待办事项/任务信息。 So far, I have created two separate projects with two separate databases,到目前为止,我已经用两个独立的数据库创建了两个独立的项目,
I need the todo project to verify the token by routing it back to the todo_auth project, and then I need the todo_auth project to send a response to the todo project.我需要 todo 项目通过将令牌路由回 todo_auth 项目来验证令牌,然后我需要 todo_auth 项目向 todo 项目发送响应。 (By specifying the port) (通过指定端口)
How can I achieve this?我怎样才能做到这一点? Many thanks.非常感谢。
PS: I'm running the two django projects on the same server with different port numbers. PS:我在具有不同端口号的同一台服务器上运行两个 django 项目。
Simple JWT provides a verify
route that you can pass a token to which will validate it was singed by the server and it is not expired.简单的 JWT 提供了一个verify
路由,您可以将一个令牌传递给该路由,该令牌将验证它是否由服务器签名并且它没有过期。
From the documentation:从文档中:
You can also include a route for Simple JWT's TokenVerifyView if you wish to allow API users to verify HMAC-signed tokens without having access to your signing key:如果您希望允许 API 用户在无需访问您的签名密钥的情况下验证 HMAC 签名的令牌,您还可以包含 Simple JWT 的 TokenVerifyView 的路由:
from rest_framework_simplejwt.views import TokenVerifyView urlpatterns = [... path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'), ... ]
If you want to do some other logic you should just write a normal view, use the JWT auth provided, and have the other one forward the token in the request如果您想做一些其他逻辑,您应该只编写一个普通视图,使用提供的 JWT 身份验证,并让另一个在请求中转发令牌
requests.get(
"http://service/api/do-thing/",
headers={
"Authorization": self.request.headers["authorization"]
}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.