mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Expose property to configure OAuth2 provider configurationMetadata
Closes gh-21375
This commit is contained in:
parent
6b8d08a6e3
commit
7b79029949
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure.security.oauth2.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -219,6 +220,11 @@ public class OAuth2ClientProperties {
|
||||
*/
|
||||
private String issuerUri;
|
||||
|
||||
/**
|
||||
* Additional metadata describing the provider's configuration.
|
||||
*/
|
||||
private Map<String, Object> configurationMetadata = new LinkedHashMap<>();
|
||||
|
||||
public String getAuthorizationUri() {
|
||||
return this.authorizationUri;
|
||||
}
|
||||
@ -275,6 +281,10 @@ public class OAuth2ClientProperties {
|
||||
this.issuerUri = issuerUri;
|
||||
}
|
||||
|
||||
public Map<String, Object> getConfigurationMetadata() {
|
||||
return this.configurationMetadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
|
||||
.to(builder::userInfoAuthenticationMethod);
|
||||
map.from(provider::getJwkSetUri).to(builder::jwkSetUri);
|
||||
map.from(provider::getUserNameAttribute).to(builder::userNameAttributeName);
|
||||
map.from(provider::getConfigurationMetadata).to(builder::providerConfigurationMetadata);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@ -238,6 +238,20 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
||||
testIssuerConfiguration(login, "okta", 2, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationMetadataFromProviderIsAdapted() {
|
||||
Provider provider = createProvider();
|
||||
provider.getConfigurationMetadata().put("end_session_endpoint", "https://myendsessionendpoint");
|
||||
OAuth2ClientProperties.Registration registration = createRegistration("my-oauth-provider");
|
||||
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
||||
properties.getRegistration().put("registration", registration);
|
||||
properties.getProvider().put("my-oauth-provider", provider);
|
||||
Map<String, ClientRegistration> registrations = OAuth2ClientPropertiesRegistrationAdapter
|
||||
.getClientRegistrations(properties);
|
||||
assertThat(registrations.get("registration").getProviderDetails().getConfigurationMetadata()
|
||||
.get("end_session_endpoint")).isEqualTo("https://myendsessionendpoint");
|
||||
}
|
||||
|
||||
@Test
|
||||
void oidcProviderConfigurationWithCustomConfigurationOverridesProviderDefaults() throws Exception {
|
||||
this.server = new MockWebServer();
|
||||
|
@ -3219,6 +3219,7 @@ You can register multiple OAuth2 clients and providers under the `spring.securit
|
||||
spring.security.oauth2.client.provider.my-oauth-provider.user-info-authentication-method=header
|
||||
spring.security.oauth2.client.provider.my-oauth-provider.jwk-set-uri=https://my-auth-server/token_keys
|
||||
spring.security.oauth2.client.provider.my-oauth-provider.user-name-attribute=name
|
||||
spring.security.oauth2.client.provider.my-oauth-provider.configuration-metadata.end_session_endpoint=https://my-end-session-endpoint
|
||||
----
|
||||
|
||||
For OpenID Connect providers that support https://openid.net/specs/openid-connect-discovery-1_0.html[OpenID Connect discovery], the configuration can be further simplified.
|
||||
|
Loading…
Reference in New Issue
Block a user