我正在使用webflux和keycloak构建OIDC客户端。我的spring应用无法启动,因为无法在下面找到Bean:
Consider defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' in your configuration.
然后...
build.gradle
dependencies {
compile "org.springframework.boot:spring-boot-starter-webflux:2.0.3.RELEASE"
compile "org.springframework.security:spring-security-oauth2-client"
compile "org.springframework.security:spring-security-oauth2-jose"
compile "org.springframework.boot:spring-boot-devtools"
compile group: 'org.keycloak', name: 'keycloak-services', version: '4.0.0.Final'
compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '4.0.0.Final'
compile "org.projectlombok:lombok"
compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '4.0.0.Beta4'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
application.yml
spring:
security:
oauth2:
client:
registration:
google:
client-id: your-app-client-id
client-secret: your-app-client-secret
facebook:
client-id: your-app-client-id
client-secret: your-app-client-secret
keycloak:
provider: keycloak
client-id: auth-api
client-secret: 727bea9d-6e01-433a-960b-83ac5d939adf
client-name: auth-api
client-authentication-method: basic
authorization-grant-type: authorization_code
redirect-uri-template: '{baseUrl}/login/oauth2/code/{registrationId}'
scope:
- openid
- profile
- email
provider:
keycloak:
authorization-uri: http://70.314.280.xxx/auth/realms/master/protocol/openid-connect/auth
token-uri: http://70.314.280.xxx/auth/realms/master/protocol/openid-connect/token
user-info-uri: http://70.314.280.xxx/auth/realms/master/protocol/openid-connect/userinfo
jwk-set-uri: http://70.314.280.xxx/auth/realms/master/protocol/openid-connect/certs
user-name-attribute: preferred_username
很明显它无法创建ClientRegistration对象,但不确定为什么spring不会从yaml文件中选择oauth2设置部分吗?
感谢您的帮助。
答案 0 :(得分:0)
我今天遇到了同样的问题,像往常一样使用Spring + IntelliJ调试源代码非常容易,原因是这行代码:
map.from(properties::getRedirectUri).to(builder::redirectUriTemplate);
代码也可以在这里找到:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java#L57
因此,您不应在yaml文件中使用redirect-uri-template
,而应使用redirect-uri
。
在学习完教程并粘贴其yaml文件后,我陷入了这个问题。