I am running an Angular application with a Spring Boot MVC API in combination with Keycloak. I configured Angular following the instruction found under https://www.npmjs.com/package/keycloak-angular and it generally works fine.
In my Angular components I use the img tag to include Images, which are served by my Spring Boot application
<img *ngIf="id" src="api/v1/profile/image/{{id}}">
The MVC endpoint looks like this :
@GetMapping(value = "profile/image/{id}")
public @ResponseBody byte[] getProfileImage(@AuthenticationPrincipal Jwt jwt, @PathVariable String id)
throws IOException {
...
}
The problem is that I receive a 401 Response Code on the first load of the image.
Here are my key findings:
- The load of the image does (never) contain the "authorization: bearer
..." request header (as opposed to requests, that are sent via the
HttpClient) - The first failing request will have a
set-cookieresponse Header - Consecutive Requests will contain the cookie as part of the Request Header and will work
Can anybody point out, what I can do? Can keycloak be configured in a way, that the load of Images will contain the bearer authetication header?