|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
59 | 59 | * @author Joe Grandja
|
60 | 60 | * @author Rafael Dominguez
|
61 | 61 | * @author Mark Heckler
|
| 62 | + * @author Ubaid ur Rehman |
62 | 63 | * @since 5.2
|
63 | 64 | * @see ReactiveJwtDecoderFactory
|
64 | 65 | * @see ClientRegistration
|
@@ -90,7 +91,8 @@ public final class ReactiveOidcIdTokenDecoderFactory implements ReactiveJwtDecod
|
90 | 91 | private Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> claimTypeConverterFactory = (
|
91 | 92 | clientRegistration) -> DEFAULT_CLAIM_TYPE_CONVERTER;
|
92 | 93 |
|
93 |
| - private WebClient webClient = WebClient.create(); |
| 94 | + private Function<ClientRegistration, WebClient> webClientResolver = (clientRegistration) -> WebClient.create(); |
| 95 | + |
94 | 96 | /**
|
95 | 97 | * Returns the default {@link Converter}'s used for type conversion of claim values
|
96 | 98 | * for an {@link OidcIdToken}.
|
@@ -166,8 +168,7 @@ private NimbusReactiveJwtDecoder buildDecoder(ClientRegistration clientRegistrat
|
166 | 168 | throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
|
167 | 169 | }
|
168 | 170 | return NimbusReactiveJwtDecoder.withJwkSetUri(jwkSetUri).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm)
|
169 |
| - .webClient(webClient) |
170 |
| - .build(); |
| 171 | + .webClient(this.webClientResolver.apply(clientRegistration)).build(); |
171 | 172 | }
|
172 | 173 | if (jwsAlgorithm != null && MacAlgorithm.class.isAssignableFrom(jwsAlgorithm.getClass())) {
|
173 | 174 | // https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation
|
@@ -243,14 +244,16 @@ public void setClaimTypeConverterFactory(
|
243 | 244 | }
|
244 | 245 |
|
245 | 246 | /**
|
246 |
| - * Sets the custom web client that will be used in {@link NimbusReactiveJwtDecoder}. |
247 |
| - * The default webClient is created by {@code WebClient.create()}. |
248 |
| - * This is optional method if we need to set custom web client in {@link NimbusReactiveJwtDecoder}. |
249 |
| - * |
250 |
| - * @param webClient webclient |
| 247 | + * Sets the resolver that provides the {@link WebClient} that will be used in |
| 248 | + * {@link NimbusReactiveJwtDecoder}. The default resolver provides {@link WebClient} |
| 249 | + * that is created by {@code WebClient.create()}. This is optional method if we need |
| 250 | + * to set custom web client in {@link NimbusReactiveJwtDecoder}. |
| 251 | + * @param webClientResolver a function that will provide {@link WebClient} for a |
| 252 | + * {@link ClientRegistration} |
251 | 253 | */
|
252 |
| - public void setWebClient(WebClient webClient) { |
253 |
| - this.webClient = webClient; |
| 254 | + public void setWebClientResolver(Function<ClientRegistration, WebClient> webClientResolver) { |
| 255 | + Assert.notNull(webClientResolver, "webClientResolver cannot be null"); |
| 256 | + this.webClientResolver = webClientResolver; |
254 | 257 | }
|
255 | 258 |
|
256 | 259 | }
|
0 commit comments