Cannot get auth token from Keycloak and propagate it through all services in my Spring Boot Microservices

123 views
Skip to first unread message

Sercan Noyan Germiyanoglu

unread,
Jul 27, 2022, 4:06:21 PM7/27/22
to Keycloak User

Hi,

I have a problem about getting the correlation id auth token from Keycloak when I make a request from one service to another in my Spring Cloud.

I got null correlation id and auth token from Keycloak. I put a log in UserContextFilter in User service. Here is the result Management Service | UserContextFilter | doFilter | User Service Incoming Correlation id: null | Auth Token : null

That's why I got 401 Authorized value as I can get null of Correlation id and Auth Token from user service in management service making a request to user service.

I used rest template as a load balancer to get correlation id and auth token in management service and advertisement service but all these are null.

How can I get auth token and Correlation id and propagate them through services?

How can I fix it?

Here are some images : Link

Here is my project link : Link

Hassen Bennour

unread,
Jul 28, 2022, 6:47:47 AM7/28/22
to Keycloak User
Hi,

After a quick look at your code, it seems that you're doing many manual not needed stuff that are done by the <artifactId>keycloak-spring-boot-starter</artifactId>

I don't know where is the problem exactly but maybe it's a good idea te review your code.

For the token propagation I advise you to use Spring Cloud Sleuth baggage instead.

Hope this helps.

Hassen BENNOUR 

Sercan Noyan Germiyanoglu

unread,
Jul 28, 2022, 7:19:32 AM7/28/22
to Keycloak User

Hi,
Thank you for your response, I think it'll be better to run the app instead of looking through the code.

When I changed the type as a bearer token and copied access token from login of user service, I got 401 Authorized error.

I think my issue is related with security and rest template.

Can you test it if you have any idea about it?

Please let me know.
28 Temmuz 2022 Perşembe tarihinde saat 13:47:47 UTC+3 itibarıyla bennour...@gmail.com şunları yazdı:
Reply all
Reply to author
Forward
0 new messages