content: package co.airy.spring.auth.oidc;
  
  import co.airy.spring.auth.oidc.github.GithubApi;
  import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService;
  import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
  import org.springframework.security.oauth2.client.oidc.web.logout.OidcClientInitiatedLogoutSuccessHandler;
  import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
  import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
  import org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository;
  import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
  import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
  
  @Configuration
  public class ClientConfig {
      @Bean
      @ConditionalOnProperty({"oidc.provider", "oidc.allowedEmailPatterns"})
      public ClientRegistrationRepository clientRegistrationRepository(ConfigProvider config) {
          return new InMemoryClientRegistrationRepository(config.getRegistration());
      }
  
      @Bean
      @ConditionalOnBean(ClientRegistrationRepository.class)
      public OAuth2AuthorizedClientService authorizedClientService(
              ClientRegistrationRepository clientRegistrationRepository) {
          return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository);
      }
  
      @Bean
      @ConditionalOnBean(OAuth2AuthorizedClientService.class)
      public OAuth2AuthorizedClientRepository authorizedClientRepository(
              OAuth2AuthorizedClientService authorizedClientService) {
          return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
      }
  
      @Bean
      public UserService userService(GithubApi githubApi) {
          return new UserService(githubApi);
      }
  }
  