0

我正在尝试将示例 Spring Boot 应用程序与 IBM AppId 服务集成。我遵循了IBM Developer 门户网站上提供的教程。下面是我的配置

application.yml

spring:
  security:
    oauth2:
      client:
        registration:
          appid:
            clientId: <<clientId>>
            secret: <<secret>>
        provider:
          appid:
            issuerUri: <<issuer_uri>>

SecurityConfiguration.java

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login/**", "/user", "/userInfo").authenticated()
                .and()
                .oauth2Login();
    }
}

用户被重定向到 IBM 登录屏幕。成功验证后,用户被重定向回 Web 应用程序,但看到以下错误

[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 Unauthorized: [no body]

TRACE输出写入应用程序日志

2021-03-06 21:40:26.805 TRACE 2565 --- [nio-8080-exec-1] o.s.s.authentication.ProviderManager     : Authenticating request with OAuth2LoginAuthenticationProvider (1/3)
2021-03-06 21:40:26.807 DEBUG 2565 --- [nio-8080-exec-1] o.s.web.client.RestTemplate              : HTTP POST https://au-syd.appid.cloud.ibm.com/oauth/v4/<<tenantId>>/token
2021-03-06 21:40:26.807 DEBUG 2565 --- [nio-8080-exec-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2021-03-06 21:40:26.808 DEBUG 2565 --- [nio-8080-exec-1] o.s.web.client.RestTemplate              : Writing [{grant_type=[authorization_code], code=[wp1MU8O9wpnCj8Opw7wlfcOVwr5nF8OUwqfDqSpow51Fw48rV8ORwrJ6w65VEgI2wrVxHhshdcOfwpo8FsKXw795OcKDw43DjzJLAsK5w7sGwqHDiVjDm3LCkW7DnQN-w7fCl8OgKSTDocKVcMOIwprCvhnCvMK1wqdYe8OMNcKJw4g0w7VKwoA8w5FdGnLDlMOqfiZnw5N9w4g7w45qw4TDgD9Nw6UDacOyasO9S8OqwpkcNgh0w4PCnMOIw5TCvMO1w5IQUy5JQ1vDtWHChMOpKcOGH1fClMKfwo3CoxDCmSLCvnM1w4TDhsKGw57CmsOcPA_ChcKwwqfCpMOiwprDtUTDs8KFw7_Drg1EEsOXUMKTwpfDvBXDjsKIw5Rpw6N1TsO3QA], redirect_uri=[http://localhost:8080/login/oauth2/code/appid]}] as "application/x-www-form-urlencoded;charset=UTF-8"
2021-03-06 21:40:27.232 DEBUG 2565 --- [nio-8080-exec-1] o.s.web.client.RestTemplate              : Response 401 UNAUTHORIZED
2021-03-06 21:40:27.235 TRACE 2565 --- [nio-8080-exec-1] o.s.s.authentication.ProviderManager     : Authenticating request with OidcAuthorizationCodeAuthenticationProvider (2/3)
2021-03-06 21:40:27.235 DEBUG 2565 --- [nio-8080-exec-1] .s.a.DefaultAuthenticationEventPublisher : No event was found for the exception org.springframework.security.oauth2.core.OAuth2AuthenticationException
2021-03-06 21:40:27.235 TRACE 2565 --- [nio-8080-exec-1] .s.o.c.w.OAuth2LoginAuthenticationFilter : Failed to process authentication request

org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 Unauthorized: [no body]
    at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:113) ~[spring-security-oauth2-client-5.4.5.jar:5.4.5]
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:182) ~[spring-security-core-5.4.5.jar:5.4.5]
    at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:192) ~[spring-security-oauth2-client-5.4.5.jar:5.4.5]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:222) ~[spring-security-web-5.4.5.jar:5.4.5]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.4.5.jar:5.4.5]

有什么建议可以解决这个问题吗?

4

0 回答 0