Java 无法将访问令牌转换为JSON
我在spring cloud(我的授权服务器)中使用Oauth2.0,我使用jdbcTokenStore(而不是JwtTokenStore)将令牌存储在数据库中,它工作正常,但当我发出http请求时,postman返回此错误。 { “错误”:“无效的\u令牌”, “错误描述”:“无法将访问令牌转换为JSON” } 这是因为我还没有实现方法accesstokenconverter 我一直在寻找如何实现这个方法,但我还不走运。 你们能帮帮我吗Java 无法将访问令牌转换为JSON,java,jdbc,oauth,token,spring-cloud,Java,Jdbc,Oauth,Token,Spring Cloud,我在spring cloud(我的授权服务器)中使用Oauth2.0,我使用jdbcTokenStore(而不是JwtTokenStore)将令牌存储在数据库中,它工作正常,但当我发出http请求时,postman返回此错误。 { “错误”:“无效的\u令牌”, “错误描述”:“无法将访问令牌转换为JSON” } 这是因为我还没有实现方法accesstokenconverter 我一直在寻找如何实现这个方法,但我还不走运。 你们能帮帮我吗 package com.restaurants.serv
package com.restaurants.serviciooauth.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import javax.sql.DataSource;
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Autowired
AuthenticationManager authenticationManager;
//configuration to jdbc
@Autowired
private DataSource dataSource;
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource);
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("frontendapp")
.secret(passwordEncoder.encode("12345"))
.scopes("read","write")
.authorizedGrantTypes("password","refresh_token")
.accessTokenValiditySeconds(3600)
.refreshTokenValiditySeconds(3600)
.and()
.withClient("androidapp")
.secret(passwordEncoder.encode("12345"))
.scopes("read","write")
.authorizedGrantTypes("password","refresh_token")
.accessTokenValiditySeconds(3600)
.refreshTokenValiditySeconds(3600);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager)
.tokenStore(tokenStore());
}
}