|  | @@ -20,9 +20,12 @@ import org.springframework.security.oauth2.core.AuthenticationMethod;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.AuthorizationGrantType;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.Arrays;
 | 
	
		
			
				|  |  | -import java.util.LinkedHashSet;
 | 
	
		
			
				|  |  | +import java.util.Collections;
 | 
	
		
			
				|  |  | +import java.util.LinkedHashMap;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  import java.util.Set;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | +import java.util.stream.Stream;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import static org.assertj.core.api.Assertions.assertThat;
 | 
	
		
			
				|  |  |  import static org.assertj.core.api.Assertions.assertThatThrownBy;
 | 
	
	
		
			
				|  | @@ -37,11 +40,21 @@ public class ClientRegistrationTests {
 | 
	
		
			
				|  |  |  	private static final String CLIENT_ID = "client-1";
 | 
	
		
			
				|  |  |  	private static final String CLIENT_SECRET = "secret";
 | 
	
		
			
				|  |  |  	private static final String REDIRECT_URI = "https://example.com";
 | 
	
		
			
				|  |  | -	private static final Set<String> SCOPES = new LinkedHashSet<>(Arrays.asList("openid", "profile", "email"));
 | 
	
		
			
				|  |  | +	private static final Set<String> SCOPES = Collections.unmodifiableSet(
 | 
	
		
			
				|  |  | +			Stream.of("openid", "profile", "email").collect(Collectors.toSet()));
 | 
	
		
			
				|  |  |  	private static final String AUTHORIZATION_URI = "https://provider.com/oauth2/authorization";
 | 
	
		
			
				|  |  |  	private static final String TOKEN_URI = "https://provider.com/oauth2/token";
 | 
	
		
			
				|  |  |  	private static final String JWK_SET_URI = "https://provider.com/oauth2/keys";
 | 
	
		
			
				|  |  |  	private static final String CLIENT_NAME = "Client 1";
 | 
	
		
			
				|  |  | +	private static final Map<String, Object> PROVIDER_CONFIGURATION_METADATA =
 | 
	
		
			
				|  |  | +			Collections.unmodifiableMap(createProviderConfigurationMetadata());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	private static Map<String, Object> createProviderConfigurationMetadata() {
 | 
	
		
			
				|  |  | +		Map<String, Object> configurationMetadata = new LinkedHashMap<>();
 | 
	
		
			
				|  |  | +		configurationMetadata.put("config-1", "value-1");
 | 
	
		
			
				|  |  | +		configurationMetadata.put("config-2", "value-2");
 | 
	
		
			
				|  |  | +		return configurationMetadata;
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Test(expected = IllegalArgumentException.class)
 | 
	
		
			
				|  |  |  	public void buildWhenAuthorizationGrantTypeIsNullThenThrowIllegalArgumentException() {
 | 
	
	
		
			
				|  | @@ -73,6 +86,7 @@ public class ClientRegistrationTests {
 | 
	
		
			
				|  |  |  			.tokenUri(TOKEN_URI)
 | 
	
		
			
				|  |  |  			.userInfoAuthenticationMethod(AuthenticationMethod.FORM)
 | 
	
		
			
				|  |  |  			.jwkSetUri(JWK_SET_URI)
 | 
	
		
			
				|  |  | +			.providerConfigurationMetadata(PROVIDER_CONFIGURATION_METADATA)
 | 
	
		
			
				|  |  |  			.clientName(CLIENT_NAME)
 | 
	
		
			
				|  |  |  			.build();
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -87,6 +101,7 @@ public class ClientRegistrationTests {
 | 
	
		
			
				|  |  |  		assertThat(registration.getProviderDetails().getTokenUri()).isEqualTo(TOKEN_URI);
 | 
	
		
			
				|  |  |  		assertThat(registration.getProviderDetails().getUserInfoEndpoint().getAuthenticationMethod()).isEqualTo(AuthenticationMethod.FORM);
 | 
	
		
			
				|  |  |  		assertThat(registration.getProviderDetails().getJwkSetUri()).isEqualTo(JWK_SET_URI);
 | 
	
		
			
				|  |  | +		assertThat(registration.getProviderDetails().getConfigurationMetadata()).isEqualTo(PROVIDER_CONFIGURATION_METADATA);
 | 
	
		
			
				|  |  |  		assertThat(registration.getClientName()).isEqualTo(CLIENT_NAME);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -276,6 +291,46 @@ public class ClientRegistrationTests {
 | 
	
		
			
				|  |  |  				.build();
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Test
 | 
	
		
			
				|  |  | +	public void buildWhenAuthorizationCodeGrantProviderConfigurationMetadataIsNullThenDefaultToEmpty() {
 | 
	
		
			
				|  |  | +		ClientRegistration clientRegistration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
 | 
	
		
			
				|  |  | +				.clientId(CLIENT_ID)
 | 
	
		
			
				|  |  | +				.clientSecret(CLIENT_SECRET)
 | 
	
		
			
				|  |  | +				.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
 | 
	
		
			
				|  |  | +				.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
 | 
	
		
			
				|  |  | +				.redirectUriTemplate(REDIRECT_URI)
 | 
	
		
			
				|  |  | +				.scope(SCOPES.toArray(new String[0]))
 | 
	
		
			
				|  |  | +				.authorizationUri(AUTHORIZATION_URI)
 | 
	
		
			
				|  |  | +				.tokenUri(TOKEN_URI)
 | 
	
		
			
				|  |  | +				.userInfoAuthenticationMethod(AuthenticationMethod.HEADER)
 | 
	
		
			
				|  |  | +				.providerConfigurationMetadata(null)
 | 
	
		
			
				|  |  | +				.jwkSetUri(JWK_SET_URI)
 | 
	
		
			
				|  |  | +				.clientName(CLIENT_NAME)
 | 
	
		
			
				|  |  | +				.build();
 | 
	
		
			
				|  |  | +		assertThat(clientRegistration.getProviderDetails().getConfigurationMetadata()).isNotNull();
 | 
	
		
			
				|  |  | +		assertThat(clientRegistration.getProviderDetails().getConfigurationMetadata()).isEmpty();
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Test
 | 
	
		
			
				|  |  | +	public void buildWhenAuthorizationCodeGrantProviderConfigurationMetadataEmptyThenIsEmpty() {
 | 
	
		
			
				|  |  | +		ClientRegistration clientRegistration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
 | 
	
		
			
				|  |  | +				.clientId(CLIENT_ID)
 | 
	
		
			
				|  |  | +				.clientSecret(CLIENT_SECRET)
 | 
	
		
			
				|  |  | +				.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
 | 
	
		
			
				|  |  | +				.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
 | 
	
		
			
				|  |  | +				.redirectUriTemplate(REDIRECT_URI)
 | 
	
		
			
				|  |  | +				.scope(SCOPES.toArray(new String[0]))
 | 
	
		
			
				|  |  | +				.authorizationUri(AUTHORIZATION_URI)
 | 
	
		
			
				|  |  | +				.tokenUri(TOKEN_URI)
 | 
	
		
			
				|  |  | +				.userInfoAuthenticationMethod(AuthenticationMethod.HEADER)
 | 
	
		
			
				|  |  | +				.providerConfigurationMetadata(Collections.emptyMap())
 | 
	
		
			
				|  |  | +				.jwkSetUri(JWK_SET_URI)
 | 
	
		
			
				|  |  | +				.clientName(CLIENT_NAME)
 | 
	
		
			
				|  |  | +				.build();
 | 
	
		
			
				|  |  | +		assertThat(clientRegistration.getProviderDetails().getConfigurationMetadata()).isNotNull();
 | 
	
		
			
				|  |  | +		assertThat(clientRegistration.getProviderDetails().getConfigurationMetadata()).isEmpty();
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Test
 | 
	
		
			
				|  |  |  	public void buildWhenImplicitGrantAllAttributesProvidedThenAllAttributesAreSet() {
 | 
	
		
			
				|  |  |  		ClientRegistration registration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
 |