Over the past few days, I have been playing with the microservice template, and everything is going well, but security seems to puzzle me.
Therefore, if I can ask a question: How to handle user authentication on a separate service? I am currently submitting a Gateway API request that connects to the service in turn. Strike>
Editing Question Please see below
Whereas individual services should not know about each other. Gateway is an aggregator as such.
Current architecture.

A small code to simulate a request:
Frontend - client application
public class EntityRepository<T> { private IGateway _gateway = null; public EntityRepository(IGateway gateway) { this._gateway = gateway; } public IEnumerable<T> FindAll() { return this._gateway.Get(typeof(T)).Content.ReadAsAsync<IEnumerable<T>>().Result; } public T FindById(int id) { return this._gateway.Get(typeof(T)).Content.ReadAsAsync<T>().Result; } public void Add(T obj) { this._gateway.Post(typeof(T), obj); } public void Update(T obj) { this._gateway.Post(typeof(T), obj); } public void Save(T obj) { this._gateway.Post(typeof(T), obj); } }
I use generics to determine where it should fire when it enters the gateway. Therefore, if the Type Category , it starts the Category service by calling:
public IEnumerable<dynamic> FindAll(string appKey, string cls) { var response = ConnectTo.Service(appKey, cls); return (appKey == Application.Key) ? (response.IsSuccessStatusCode) ? response.Content.ReadAsAsync<IEnumerable<dynamic>>().Result : null : null; }
The gateway does not contain physical files / type classes.
After a little code, I was hoping someone could give me a little demo or a better approach for handling security / user authentication with the current architecture.
Case scenario 1 A user enters a web application and logs in, at which point users encrypt email and the password is sent to the Gateway API , which is then passed to the User Service and decides whether the user is checked - all is well and good, but now I want to retrieve all messages from the Message Service that the user received. I canβt tell in Gateway if the user is authenticated, retrieves messages, because this does not solve the problem of calling Message Service outside the Gateway API
I also canβt add authentication for each individual service, because this will require all the relevant services that speak to the User Service , and this defeats the purpose of the template.
Corrections: Allow the gateway to allow Services. Requests for services outside the gateway should be blocked.
I know that security is a broad topic, but in the current context, I hope that someone can guide me with the best action to solve the problem.
I currently have Hardcoded a Guid in all applications, which in turn retrieve data if the application is equal.