我从默认的Spring Security OAuth2登录实现(不使用Spring Boot)中收到此错误:
[invalid_token_response]尝试检索OAuth 2.0访问令牌响应时发生错误:提取类型[class org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse]和内容类型[application / json; charset = utf]的响应时出错-8];嵌套异常是org.springframework.http.converter.HttpMessageNotReadableException:读取OAuth 2.0访问令牌响应时出错:null;嵌套异常是java.lang.NullPointerException
情节是:我去任何受保护的页面,它重定向到谷歌“选择一个帐户”thingy,我选择帐户和爆炸,重定向到/登录?错误显示上面提到的文本。
Spring Security配置:
@Configuration
@EnableWebSecurity()
@PropertySource("classpath:application.properties")
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/tlog/**").authenticated()
.and().oauth2Login();
}
@Bean
public OAuth2AuthorizedClientService authorizedClientService() {
return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository());
}
@Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository(OAuth2AuthorizedClientService authorizedClientService) {
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
}
@Bean
public ClientRegistrationRepository clientRegistrationRepository() {
return new InMemoryClientRegistrationRepository(googleClientRegistration());
}
private ClientRegistration googleClientRegistration() {
return CommonOAuth2Provider.GOOGLE.getBuilder("google")
.clientId("XXX")
.clientSecret("ZZZ")
.build();
}
}
我在这里错过了什么?找不到任何体面的教程,不使用真正有用的Spring Boot。
我遇到了同样的问题。杰克逊的依赖解决了它
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>