To manage authentication in a microservice architecture, you must have a different perspective.
Remember, when you were working on a monolith, you had one authentication process.
As an example, in a PHP application, you will find your user in a database with the appropriate credentials, then you create a session, the user is "authenticated".
With microservices, the workflow is the same. The only thing that has changed now is that you cannot open a session in different services. In addition, you do not need to receive an authenticated user. You only need to make sure that he is authorized to make the current call on your microservices.
Thanks to oauth2, having a valid access_token, you get this information.
This should answer the outside. In the backend part (I mean, behind the api gateway) you should not control access_token, because this does not apply to microservices. You can use the function key to search for any information related to the user inside microservices, for example, uuid.
To get uuid when using oauth2, I suggest using openid connect. A user with this protocol manages specific user information and gives you access to a specific "/ userinfo" endpoint.
We hope that this outline will make this answer clearer.

David level
source share