Reputation: 553
This might be a basic question about microservices. I searched for a few articles but not able to find anything apt. I am developing two different django rest applications (say A and B) which has to use the same authentication service. I've built the authentication service using django-rest-framework-simplejwt. My current plan is when a token is sent to A, I use TokenVerifyView from authentication service to validate the token. In certain cases where user information is required I have created a view in authentication service to return username. I'm intending to achieve this by sending a request to the authentication service for each view in A using a decorator. I understand this will be very slow and is a sub-optimal solution. What is a better way to achieve this? Thanks.
Upvotes: 3
Views: 996
Reputation: 1745
This seems correct for the most part but I'm not sure if you'd want to call an API of the authentication service for authorization during each API request to either A or B. For higher throughput, I think you should look at a message queue like ZeroMQ which could be an ideal solution here.
You could also use django-channels to enable communication between the web apps using web sockets here. This would be easier to implement out of the two solutions.
For a basic system, contacting the authorization service for each call to either microservice would work but eventually you'll run into scalability issues at which point you might need to come up with a way to contact the authorization service once. That, I feel, is out of the scope of this question but if you want to read more about that, you could look at this stackoverflow answer.
Upvotes: 1