title: How to set hosted domain parameter in Google OAuth2 AccountChooser with Java config?
body: <p>Currently I have working OAuth2 authentication flow with following Java config:</p>
  
  <pre><code>@Configuration
  @EnableOAuth2Client
  @Import(SecurityWebAppInitializer.class)
  public class OAuth2SecurityConfiguration {
  
      @Resource
      private GoogleClientSecrets googleClientSecrets;
  
      @Resource
      private AccessTokenRequest accessTokenRequest;
  
      @Bean
      public AuthorizationCodeResourceDetails googleResource() {
          AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
          GoogleClientSecrets.Details web = googleClientSecrets.getWeb();
          details.setId((String) web.get("project_id"));
          details.setClientId(web.getClientId());
          details.setClientSecret(web.getClientSecret());
          details.setAccessTokenUri(web.getTokenUri());
          details.setUserAuthorizationUri(web.getAuthUri());
          details.setTokenName((String) web.get("token_name"));
  
          String commaSeparatedScopes = (String) web.get("scope");
          details.setScope(parseScopes(commaSeparatedScopes));
          details.setPreEstablishedRedirectUri(web.getRedirectUris().get(0));
          details.setUseCurrentUri(false);
          details.setAuthenticationScheme(AuthenticationScheme.query);
          details.setClientAuthenticationScheme(AuthenticationScheme.form);
          return details;
      }
  
      private List&lt;String&gt; parseScopes(String commaSeparatedScopes) {
          List&lt;String&gt; scopes = newArrayList();
          Collections.addAll(scopes, commaSeparatedScopes.split(","));
          return scopes;
      }
  
      @Bean
      public OAuth2ClientAuthenticationProcessingFilter oAuth2AuthenticationProcessingFilter(
              OAuth2RestTemplate oAuth2RestTemplate, ResourceServerTokenServices resourceServerTokenServices) {
          OAuth2ClientAuthenticationProcessingFilter filter =
                  new OAuth2ClientAuthenticationProcessingFilter("/googleLogin");
          filter.setRestTemplate(oAuth2RestTemplate);
          filter.setTokenServices(resourceServerTokenServices);
          return filter;
      }
  
      @Bean
      public UserAuthenticationConverter userTokenConverter() {
          return new DefaultUserAuthenticationConverter();
      }
  
      @Bean
      public AccessTokenConverter accessTokenConverter(UserAuthenticationConverter userTokenConverter) {
          GoogleAccessTokenConverter accessTokenConverter = new GoogleAccessTokenConverter();
          accessTokenConverter.setUserTokenConverter(userTokenConverter);
          return new GoogleAccessTokenConverter();
      }
  
      @Bean
      public GoogleTokenServices tokenServices(AccessTokenConverter accessTokenConverter) {
          GoogleTokenServices tokenServices = new GoogleTokenServices();
          GoogleClientSecrets.Details web = googleClientSecrets.getWeb();
          tokenServices.setCheckTokenEndpointUrl("https://www.googleapis.com/oauth2/v1/tokeninfo");
          tokenServices.setClientId(web.getClientId());
          tokenServices.setClientSecret(web.getClientSecret());
          tokenServices.setAccessTokenConverter(accessTokenConverter);
          return tokenServices;
      }
  
      @Bean
      public OAuth2RestTemplate googleRestTemplate() {
          return new OAuth2RestTemplate(googleResource(), new DefaultOAuth2ClientContext(accessTokenRequest));
      }
  
      @Bean
      public OAuth2ClientContextFilter oauth2ClientContextFilter() {
          return new OAuth2ClientContextFilter();
      }
  
      @Bean
      public LoginUrlAuthenticationEntryPoint clientAuthenticationEntryPoint() {
          return new LoginUrlAuthenticationEntryPoint("/googleLogin");
      }
  }
  </code></pre>
  
  <p>and <code>client_secret.json</code> for my google service:</p>
  
  <pre><code>{
    "web": {
      "client_id": "...",
      "project_id": "...",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://accounts.google.com/o/oauth2/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_secret": "...",
      "redirect_uris": [
        "http://localhost:8888/googleLogin",
        "http://localhost:8888/googleLogin/"
      ],
      "scope": "https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile",
      "token_name": "authorization_code"
    }
  }
  </code></pre>
  
  <p>The problem is I don't know where to set <a href="https://developers.google.com/identity/protocols/OpenIDConnect#hd-param" rel="nofollow noreferrer">hosted domain</a> parameter in java code. I was trying to find solution over the stackoverflow, but only saw solutions with JS or PHP.</p>