簡體   English   中英

Spring boot 找不到 bean OAuth2AuthorizedClientService

[英]Spring boot unable to find bean OAuth2AuthorizedClientService

我正在使用 webflux 和 keycloak 構建 OIDC 客戶端。 我的 spring 應用程序無法啟動,因為它找不到下面的 bean:

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

接着...

構建.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')
}

應用程序.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 設置部分?

謝謝你的幫助。

我今天遇到了同樣的問題,像往常一樣使用 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
所以,你不應該使用redirect-uri-template ,但redirect-uri在YAML文件。
我按照教程並粘貼了他們的 yaml 文件后陷入了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM