When calling loadAuthorizedClient on ReactiveOAuth2AuthorizedClientService, loadAuthorizedClient returns a Mono<OAuth2AuthorizedClient> that never resolves (never reaches completion) after subscribed to.
To Reproduce
oAuth2AuthorizedClientService.loadAuthorizedClient(MYCLIENTID, MYPRINCIPALNAME)
.subscribe(s -> System.out.println("FINISHED"));
Expected behavior I would expected "FINISHED" to be printed, however this never happens.
Comment From: marcusdacoregio
Hi @godfriedmeesters,
It is not possible for us to troubleshoot what is happening without more detail, would you be able to provide more information or a minimal, reproducible sample?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: godfriedmeesters
The context is a Spring Reactor web app, where the user is already authenticated. I want to get the current refresh token.
Here is a more complete view of the problem code:
@Slf4j
@RequiredArgsConstructor
@Service
public class POPTokenGenerator {
public static final String ANONYMOUS = "anonymous";
public static final String EULOGIN = "eulogin";
private final ReactiveOAuth2AuthorizedClientService oAuth2AuthorizedClientService;
public static Optional<String> getCurrentUserLogin() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(extractPrincipal(securityContext.getAuthentication()));
}
public Mono<EuLoginTokenResponse> getPopToken() {
String principalName = getCurrentUserLogin().orElse(ANONYMOUS);
Mono<OAuth2AuthorizedClient> authorizedClient = oAuth2AuthorizedClientService.loadAuthorizedClient(EULOGIN, principalName);
return authorizedClient.flatMap(tokenResponse -> {
System.out.println("UNFORTUNETELY NEVER EXECUTED");
System.out.println(tokenResponse.getRefreshToken().getTokenValue());
....
Comment From: marcusdacoregio
Hi @godfriedmeesters,
are you sure that the request is completed successfully and that there is a user in the SecurityContextHolder? If those are true, can you provide a minimal, reproducible sample?
Comment From: godfriedmeesters
I'm sure that the statement return authorizedClient.flatMap(tokenResponse -> { is reached. Unfortunately I can't provide a complete sample since I changed it a lot since in the meantime; I fixed the problem of getting the current refresh token by injecting the authorized client in my controller, rather than relying on ReactiveOAuth2AuthorizedClientService, as follows:
@RegisteredOAuth2AuthorizedClient("eulogin") OAuth2AuthorizedClient authorizedClient
So topic can be closed.