Open juliuskrah opened 4 years ago
@juliuskrah Did you solve this problem?
@codetalkr I took out the context path
me too.
I added an explicit redirect URI to the client registration:
...
spring:
webflux:
base-path: /path
security:
oauth2:
client:
registration:
keycloak:
client-id: my-client
client-secret: my-secret
redirect-uri: https://host.domain.com/path/login/oauth2/code/{registrationId}
...
Unfortunately, I'm still having issues with logging out when specifying a base-path
.
@juliuskrah The reason you are seeing
Location: # location is blank
is because the SPRING_SECURITY_SAVED_REQUEST
in the session is blank. The value should be http://localhost:8080/path/
. The root of this issue is in RedirectServerAuthenticationSuccessHandler
which uses WebSessionServerRequestCache
.
If you try the oauth2Login
Servlet sample, you will see that SavedRequestAwareAuthenticationSuccessHandler
obtains a DefaultSavedRequest
from HttpSessionRequestCache
with the value http://localhost:8080/path/
and it works as expected.
Would you be interested in submitting a PR for this fix?
Hi @jgrandja, you can assign me the task. May I?
Thank you @parikshitdutta ! The issue is yours.
Is there a workaround for this bug until it is fixed?
The most obvious workaround to me would be to extend RedirectServerAuthenticationSuccessHandler
and just override onAuthenticationSuccess()
to be something like this?
@Override
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) {
ServerWebExchange exchange = webFilterExchange.getExchange();
return this.requestCache.getRedirectUri(exchange).defaultIfEmpty(this.location).flatMap((location) -> {
if (location.toASCIIString().isBlank() && this.location.toASCIIString().isBlank()) {
location = URI.create("/");
} else if (location.toASCIIString().isBlank()) {
location = this.location;
}
return this.redirectStrategy.sendRedirect(exchange, location);
});
}
It seems like a huge pain to just copy an entire class almost word-for-word, so I'm hoping someone else is aware of a quicker/simpler workaround.
I ran into the same problem today but what I found out is that it does not work iif the request path equals the base path and does not end in a forward slash. Whether the base path ends in a slash is irrelevant.
So, if you have set spring.webflux.base-path: /path
and you request /path
, you will end up with /path/login?error
and "Invalid credentials" because of the reason described above. However, if you request /path/
or e.g. /path/foo
, it works.
As this issue is a bit older and things may have changed in the meantime, here some context about the version, I'm using:
I came also over this issue and the above workaround by @libantema worked for me. I just had to copy the class RedirectServerAuthenticationSuccessHandler
and override the method onAuthenticationSuccess
.
@Override public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) { ServerWebExchange exchange = webFilterExchange.getExchange(); return this.requestCache.getRedirectUri(exchange).defaultIfEmpty(this.location).flatMap((location) -> { if (location.toASCIIString().isBlank() && this.location.toASCIIString().isBlank()) { location = URI.create("/"); } else if (location.toASCIIString().isBlank()) { location = this.location; } return this.redirectStrategy.sendRedirect(exchange, location); }); }
Can this be fixed in the spring security core?
If anybody uses the Spring Cloud Gatway, also the following Issue could be interesting: https://github.com/spring-cloud/spring-cloud-gateway/issues/1935
Describe the bug I am running spring-boot
2.3.1
withspring-boot-starter-oauth2-client
, after adding a context-path, everything breaksTo Reproduce I have the following configuration
And my yaml has the following
Looking at the browser network tab, the final request looks like this
Expected behavior Application should redirect me to initially requested page