|
| 1 | +package graphql.kickstart.spring.webclient.boot; |
| 2 | + |
| 3 | +import static java.util.Optional.ofNullable; |
| 4 | + |
| 5 | +import java.util.Set; |
| 6 | +import lombok.Data; |
| 7 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 8 | +import org.springframework.context.annotation.Primary; |
| 9 | +import org.springframework.security.oauth2.client.registration.ClientRegistration; |
| 10 | +import org.springframework.security.oauth2.core.AuthenticationMethod; |
| 11 | +import org.springframework.security.oauth2.core.AuthorizationGrantType; |
| 12 | +import org.springframework.security.oauth2.core.ClientAuthenticationMethod; |
| 13 | + |
| 14 | +@Data |
| 15 | +@Primary |
| 16 | +@ConfigurationProperties(prefix = "graphql.client.oauth2") |
| 17 | +class OAuth2ClientRegistrationProperties { |
| 18 | + |
| 19 | + private String provider; |
| 20 | + private String clientId; |
| 21 | + private String clientSecret; |
| 22 | + private String clientAuthenticationMethod; |
| 23 | + private String authorizationGrantType = "client_credentials"; |
| 24 | + private String redirectUri; |
| 25 | + private Set<String> scope; |
| 26 | + private String clientName; |
| 27 | + |
| 28 | + private String authorizationUri; |
| 29 | + private String tokenUri; |
| 30 | + private String userInfoUri; |
| 31 | + private String userInfoAuthenticationMethod; |
| 32 | + private String userNameAttribute; |
| 33 | + private String jwkSetUri; |
| 34 | + private String issuerUri; |
| 35 | + |
| 36 | + ClientRegistration getClientRegistration() { |
| 37 | + ClientRegistration.Builder builder = ClientRegistration.withRegistrationId("graphql") |
| 38 | + .clientId(getClientId()) |
| 39 | + .clientSecret(getClientSecret()) |
| 40 | + .redirectUriTemplate(getRedirectUri()) |
| 41 | + .scope(getScope()) |
| 42 | + .clientName(getClientName()) |
| 43 | + .authorizationUri(getAuthorizationUri()) |
| 44 | + .tokenUri(getTokenUri()) |
| 45 | + .userInfoUri(getUserInfoUri()) |
| 46 | + .jwkSetUri(getJwkSetUri()); |
| 47 | + |
| 48 | + ofNullable(getClientAuthenticationMethod()) |
| 49 | + .map(ClientAuthenticationMethod::new) |
| 50 | + .ifPresent(builder::clientAuthenticationMethod); |
| 51 | + |
| 52 | + ofNullable(getAuthorizationGrantType()) |
| 53 | + .map(AuthorizationGrantType::new) |
| 54 | + .ifPresent(builder::authorizationGrantType); |
| 55 | + |
| 56 | + ofNullable(getUserInfoAuthenticationMethod()) |
| 57 | + .map(AuthenticationMethod::new) |
| 58 | + .ifPresent(builder::userInfoAuthenticationMethod); |
| 59 | + |
| 60 | + return builder.build(); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments