Get info from user with SecurityPrincipal in services
ricardoasc opened this issue · 2 comments
Obtain user information in the request that arrives at the services
How would be a correct way to get user data just using SecurityPrincipal in my controls when a request is sent to some service?
The way the services are not exposed, to request a service you have to go through the API Gateway, which is where authorization is required.
How do I transit the authenticated user's information in Keycloak by passing the authenticated user's information to my services?
Because in some records I will need, for example, the user ID you requested, how can I do that?
This should be the answer for what you are looking. So basically you would implement the authentication on the other services also, and you can relay the token.
As suggested by @gianluca1606 you have to use TokenRelay, to forward the request from the API Gateway to the services.
Here is the updated documentation for Token Relay - https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#the-tokenrelay-gatewayfilter-factory