I configured a service with oauth2Login
.
User is redirected to Authorization Endpoint - /oauth2/authorization/{registrationId}
when he/she is not authorized.
I would like to customize redirection in a way that it takes into account path prefix, since application is accessible trough prefix /api/myapp/
.
From the source code I can see that there is OAuth2AuthorizationRequestRedirectWebFilter
during Spring Security setup and this filter is using DefaultServerRedirectStrategy
which decides if location is relative or not. Moreover it uses a contextPath
which is hard to set when using Spring Boot.
Unfortunately I don't know how to override default behavior to make redirect relative.
I don't need to modify contextPath
. Instead I've registered ForwardedHeaderTransformer
as a bean.
This transformer is able to retrieve headers set by proxy (X-Forwarded-Prefix
) and sets context path for request correctly.