-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Description
Summary
When I configure my client registration in the application.yml, the following property is not taken into account: spring.security.oauth2.client.provider.[providerId].userNameAttribute
Actual Behavior
clientRegistration.getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName() is null.
Other properties work just fine: clientRegistration.getProviderDetails().getUserInfoEndpoint().getUri()
Expected Behavior
clientRegistration.getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName() should have the value configured in the application.yml by the following property: spring.security.oauth2.client.provider.[providerId].userNameAttribute as documented here: https://docs.spring.io/spring-security/site/docs/5.0.0.BUILD-SNAPSHOT/reference/htmlsingle/#jc-oauth2login-client-registration
Version
5.0.0.RELEASE
Sample
@Configuration
public class OAuth2LoginConfig {
@Autowired
private ClientRegistrationRepository repo;
@PostConstruct
public void init() {
ClientRegistration r = repo.findByRegistrationId("test");
Assert.notNull(r.getProviderDetails().getUserInfoEndpoint().getUri(), "uri is null");
Assert.notNull(r.getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName(), "userAttributeName is null");
}
}
spring:
security:
oauth2:
client:
registration:
test:
clientName: my-client-name
clientId: myauthserver
clientSecret: verysecretpassword
authorization-grant-type: authorization_code
redirectUriTemplate: http://localhost:8080/login/oauth2/code/test
scope: myscope
provider:
test:
tokenUri: http://localhost:9090/auth/oauth/token
authorizationUri: http://localhost:9090/auth/oauth/authorize
user-info-uri: http://localhost:9090/auth/user
userNameAttribute: user
buildscript {
ext {
springBootVersion = '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
apply plugin: 'war'
war {
baseName = 'my-website'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
configurations {
providedRuntime
}
ext {
springCloudVersion = 'Finchley.M5'
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile('org.springframework.security:spring-security-oauth2-client')
compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}