无法检索远程JWK集:org.springframework.web.client.HttpClientErrorException$NotFound:404未找到

问题描述 投票:0回答:1

我正在使用 docker 开发带有 keyclock 的 springboot 应用程序 在应用程序 yml 文件中,我指定了发行者和 jwk

  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: http://localhost:8080/realms/backend
          jwk-set-uri: http://localhost:8080/realms/backend/protocol/openid-connect/certs

这是我的安全过滤器链:

@Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        return http
                .cors(Customizer.withDefaults())
                .authorizeHttpRequests(ar->ar.anyRequest().authenticated())
                .oauth2ResourceServer(oauth2ResourceServer -> oauth2ResourceServer.jwt(Customizer.withDefaults()))
                .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .build();
    }

但是,当我尝试使用来自的令牌获取 api 时

我总是得到 尝试解码 Jwt 时发生错误:无法检索远程 JWK 集

application.yml中提到的jswk-set-uri是这样读取的

“404 未找到

未找到

在此服务器上找不到请求的 URL /realms/backend/protocol/openid-connect/certs”

我的项目信息:

-Springboot:3.2.3 -Jdk 17

Docker 编写 yml :

  keycloak:
    image: docker.io/bitnami/keycloak:latest
    ports:
      - "8080:8080"
    environment:
      - KEYCLOAK_CREATE_ADMIN_USER=true
      - KEYCLOAK_ADMIN_USER=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    depends_on:
      - postgresql
    volumes:
      - ./mynewtheme:/opt/bitnami/keycloak/themes/mynewtheme
      - /path/to/init-scripts:/docker-entrypoint-initdb.d
spring spring-boot oauth-2.0 keycloak
1个回答
0
投票

网址正确吗?我在错误的道路上犯了这样的错误

© www.soinside.com 2019 - 2024. All rights reserved.