简体   繁体   English

Spring boot 找不到 bean OAuth2AuthorizedClientService

[英]Spring boot unable to find bean OAuth2AuthorizedClientService

I am building an OIDC client with webflux and keycloak.我正在使用 webflux 和 keycloak 构建 OIDC 客户端。 My spring app wont start as it cant find the bean below:我的 spring 应用程序无法启动,因为它找不到下面的 bean:

Consider defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' in your configuration.

now then...接着...

build.gradle构建.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应用程序.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

Clearly it cant create the ClientRegistration object but not sure why spring wont pick the oauth2 settings section from the yaml file?显然它无法创建 ClientRegistration 对象,但不确定为什么 spring 不会从 yaml 文件中选择 oauth2 设置部分?

Thanks for your help.谢谢你的帮助。

I ran into the same issue today, debugging the source is very easy with Spring + IntelliJ as usual, the reason is this line of code:我今天遇到了同样的问题,像往常一样使用 Spring + IntelliJ 调试源代码非常容易,原因是这行代码:

map.from(properties::getRedirectUri).to(builder::redirectUriTemplate);

The code can also be found here: 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代码也可以在这里找到: 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
So, You should not be using redirect-uri-template but redirect-uri in your yaml file.所以,你不应该使用redirect-uri-template ,但redirect-uri在YAML文件。
I fell into this issue following a tutorial and pasting their yaml file.我按照教程并粘贴了他们的 yaml 文件后陷入了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 考虑在您的配置中定义 OAuth2AuthorizedClientService 类型的 bean。 LoginController 中构造函数的参数 0 需要一个 Bean - Defining a bean of type OAuth2AuthorizedClientService in your configuration consider. Parameter 0 of constructor in LoginController required a Bean Spring OAuth2 / OIDC-OAuth2AuthorizedClientService未注册用户主体(authroizedClient) - Spring OAuth2/OIDC - OAuth2AuthorizedClientService is not registering the User Principal (authroizedClient) 没有为接口 OAuth2AuthorizedClientService 找到主构造函数或单个唯一构造函数 - No primary or single unique constructor found for interface OAuth2AuthorizedClientService 无法在spring boot中定义bean - Unable to define bean in spring boot 无法在Spring Boot中初始化Bean - Unable to initialize bean in spring boot 无法在春季启动中创建Bean - Unable to create bean in spring boot Spring Boot Controller无法找到Bean类 - Spring boot Controller is not able to find the bean class 春季靴找不到类型的豆 - spring boot could not find bean of type Spring Boot找不到嵌入式KafkaBroker Bean - Spring Boot Cannot Find EmbeddedKafkaBroker Bean Spring 引导:无法访问 Spring 调度程序中的请求 scope bean - Spring Boot: Unable to access the request scope bean in Spring Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM