|
36 | 36 | import org.springframework.security.oauth2.core.OAuth2AuthorizationException; |
37 | 37 | import org.springframework.security.oauth2.core.OAuth2Token; |
38 | 38 | import org.springframework.util.Assert; |
| 39 | +import org.springframework.util.ClassUtils; |
39 | 40 |
|
40 | 41 | /** |
41 | 42 | * An implementation of a {@link ReactiveOAuth2AuthorizedClientProvider} for the |
|
50 | 51 | public final class RefreshTokenReactiveOAuth2AuthorizedClientProvider |
51 | 52 | implements ReactiveOAuth2AuthorizedClientProvider { |
52 | 53 |
|
| 54 | + private static final boolean josePresent = ClassUtils.isPresent( |
| 55 | + "org.springframework.security.oauth2.jwt.ReactiveJwtDecoder", |
| 56 | + RefreshTokenReactiveOAuth2AuthorizedClientProvider.class.getClassLoader()); |
| 57 | + |
53 | 58 | private ReactiveOAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient = new WebClientReactiveRefreshTokenTokenResponseClient(); |
54 | 59 |
|
55 | | - private ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler = new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler(); |
| 60 | + private ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler = (authorizedClient, principal, |
| 61 | + attributes) -> Mono.empty(); |
56 | 62 |
|
57 | 63 | private Duration clockSkew = Duration.ofSeconds(60); |
58 | 64 |
|
59 | 65 | private Clock clock = Clock.systemUTC(); |
60 | 66 |
|
| 67 | + public RefreshTokenReactiveOAuth2AuthorizedClientProvider() { |
| 68 | + if (josePresent) { |
| 69 | + this.authorizationSuccessHandler = new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler(); |
| 70 | + } |
| 71 | + } |
| 72 | + |
61 | 73 | /** |
62 | 74 | * Attempt to re-authorize the |
63 | 75 | * {@link OAuth2AuthorizationContext#getClientRegistration() client} in the provided |
@@ -128,8 +140,9 @@ public void setAccessTokenResponseClient( |
128 | 140 |
|
129 | 141 | /** |
130 | 142 | * Sets a {@link ReactiveOAuth2AuthorizationSuccessHandler} to use for handling |
131 | | - * successful refresh token response, defaults to |
132 | | - * {@link RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler}. |
| 143 | + * successful refresh token response. Defaults to |
| 144 | + * {@link RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler}, when |
| 145 | + * {@code spring-security-oauth2-jose} is available on the classpath. |
133 | 146 | * @param authorizationSuccessHandler the |
134 | 147 | * {@link ReactiveOAuth2AuthorizationSuccessHandler} to use |
135 | 148 | * @since 7.1 |
|
0 commit comments