-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reactive Implementation of AuthorizedClientServiceOAuth2AuthorizedCli… #7589
Conversation
116f941
to
643fa9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @ankurpathak and for your patience waiting on me. Please see my comments.
* @see ReactiveOAuth2AuthorizedClientService | ||
* @since 5.3 | ||
*/ | ||
public final class ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager implements ReactiveOAuth2AuthorizedClientManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename to OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies. I meant to say AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
- without OAuth2
prefix so the naming is consistent with existing AuthorizedClientServiceOAuth2AuthorizedClientManager
...auth2/client/ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.java
Outdated
Show resolved
Hide resolved
...auth2/client/ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.java
Outdated
Show resolved
Hide resolved
...auth2/client/ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.java
Outdated
Show resolved
Hide resolved
...auth2/client/ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.java
Outdated
Show resolved
Hide resolved
}) | ||
.build() | ||
).flatMap(authorizationContext -> this.reactiveAuthorizedClientProvider.authorize(authorizationContext) | ||
.doOnNext(x -> reactiveAuthorizedClientService.saveAuthorizedClient(x, principal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename x
to authorizedClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to _authorizedClient as conflicting with local variable authorizedClient.
Hi, (not sure where i should post this comment... so i put it here) I had to change some code of the class to make it work with my use case. How i tested this PR (maybe wrongly?)(in my code, i already renamed ReactiveClientRegistrationRepository clientRegistrationRepository = new InMemoryReactiveClientRegistrationRepository(clientRegistration);
ReactiveOAuth2AuthorizedClientService authorizedClientService = new InMemoryReactiveOAuth2AuthorizedClientService(clientRegistrationRepository);
OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager authorizedClientManager =
new OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(
clientRegistrationRepository,
authorizedClientService
);
authorizedClientManager.setReactiveOAuth2AuthorizedClientProvider(new SpecificPartnerReactiveOAuth2AuthorizedClientProvider()); The current implementation does not save the authorized client into the repository. The code i changed to make it workI changed .doOnNext(x -> reactiveAuthorizedClientService.saveAuthorizedClient(x, principal)) to .flatMap(authClient -> reactiveAuthorizedClientService.saveAuthorizedClient(authClient, principal).thenReturn(authClient)) Regards |
643fa9c
to
3d55728
Compare
@ghostd I will wait for @jgrandja to review above commets and if your changes are required will do the needful. |
3d55728
to
e9c2081
Compare
…entManager ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager is reactive version of AuthorizedClientServiceOAuth2AuthorizedClientManager Fixes: spring-projectsgh-7569
e9c2081
to
9c8d027
Compare
Hi, I did some tests with the new version. It seems if |
attributes.putAll(contextAttributes); | ||
}).build()) | ||
).flatMap(authorizationContext -> this.authorizedClientProvider.authorize(authorizationContext) | ||
.doOnNext(_authorizedClient -> authorizedClientService.saveAuthorizedClient(_authorizedClient, principal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ghostd Thanks for catching this...
.flatMap(authClient -> reactiveAuthorizedClientService.saveAuthorizedClient(authClient, principal).thenReturn(authClient))
@ankurpathak This bug was fixed in this commit.
Can you also apply the update to the test to make use of PublisherProbe<Void> saveAuthorizedClientProbe
to ensure we cover the scenario of the Mono being subscribed to. See the commit that makes use of PublisherProbe
in the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @ankurpathak. Please see my comments.
|
||
@Override | ||
public Mono<Map<String, Object>> apply(OAuth2AuthorizeRequest authorizeRequest) { | ||
ServerWebExchange serverWebExchange = authorizeRequest.getAttribute(ServerWebExchange.class.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServerWebExchange
won't be available in this scenario so .defaultIfEmpty(Collections.emptyMap())
will execute every time. The logic should be similar to AuthorizedClientServiceOAuth2AuthorizedClientManager.DefaultContextAttributesMapper
. Looks like a test is missing for this scenario, can you please add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also see this comment as the logic for .flatMap(contextBuilder -> this.contextAttributesMapper.apply(authorizeRequest)
is incorrect. Please add a test for this as well. If contextAttributesMapper
returns an empty Map
, authorizedClientProvider.authorize()
should still be called.
Any chance this could be added in 5.2.x ? |
.build(); | ||
Mono<OAuth2AuthorizedClient> authorizedClient = this.authorizedClientManager.authorize(authorizeRequest); | ||
|
||
authorizedClient.subscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't subscribe()
here. Instead, rely on StepVerifier
subscribing (during verifyComplete()
). Move the verifications and assertions after the StepVerifier.
The same comment applies to all these test methods where .subscribe()
is explicitly called
@jgrandja you can takeover this as I tried a lot on this but can't make it. |
I can pick this up to continue it. |
@ankurpathak No worries and thank you for your work thus far. @philsttr That would be great if you can take over this. Much appreciated. |
Closing in favour of #7702 |
Rename OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager to AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager. Handle empty mono returned from contextAttributesMapper. Handle empty map returned from contextAttributesMapper. Fix DefaultContextAttributesMapper so that it doesn't access ServerWebExchange. Fix unit tests so that they pass. Use StepVerifier in unit tests, rather than .subscribe(). Fixes spring-projectsgh-7569
Rename OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager to AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager. Handle empty mono returned from contextAttributesMapper. Handle empty map returned from contextAttributesMapper. Fix DefaultContextAttributesMapper so that it doesn't access ServerWebExchange. Fix unit tests so that they pass. Use StepVerifier in unit tests, rather than .subscribe(). Fixes gh-7569
Rename OAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager to AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager. Handle empty mono returned from contextAttributesMapper. Handle empty map returned from contextAttributesMapper. Fix DefaultContextAttributesMapper so that it doesn't access ServerWebExchange. Fix unit tests so that they pass. Use StepVerifier in unit tests, rather than .subscribe(). Fixes gh-7569
…entManager
ReactiveOAuth2AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager is reactive
version of AuthorizedClientServiceOAuth2AuthorizedClientManager
Fixes: gh-7569