Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring security oauth2 OAuth错误:无效的客户端和错误的客户端凭据_Spring Security Oauth2 - Fatal编程技术网

Spring security oauth2 OAuth错误:无效的客户端和错误的客户端凭据

Spring security oauth2 OAuth错误:无效的客户端和错误的客户端凭据,spring-security-oauth2,Spring Security Oauth2,我正在做关于春季安全的事情。但当我登录时,它总是会注意到: OAuth错误 error=“无效的客户端”,error\u description=“错误的客户端凭据” 关于堆栈溢出,我也问了很多同样的问题,但还没有解决这个问题 这是我的AuthorizationServerConfig类: @Configuration @EnableAuthorizationServer @PropertySource("application.properties") public class Authori

我正在做关于春季安全的事情。但当我登录时,它总是会注意到:

OAuth错误
error=“无效的客户端”,error\u description=“错误的客户端凭据”

关于堆栈溢出,我也问了很多同样的问题,但还没有解决这个问题

这是我的AuthorizationServerConfig类:

@Configuration
@EnableAuthorizationServer
@PropertySource("application.properties")
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    @Qualifier("authenticationManagerBean")
    private AuthenticationManager authenticationManager;

    @Autowired
    private Environment env;

    @Autowired
    private DataSource 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("ClientId")
            .secret("secret")
            .authorizedGrantTypes("authorization_code")
            .scopes("user_info")
            .autoApprove(true)
            .redirectUris("http://localhost:8000");
    }


    @Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
  endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
}

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
ResourceServerConfig类:

@Configuration
@EnableWebSecurity
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService customUserDetailsService; 

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

    http.requestMatchers()
            .antMatchers("/login", "/oauth/authorize")
            .and()
            .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .permitAll();
    }


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

       auth.userDetailsService(customUserDetailsService);
    }

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}
CustomUserDetails服务类:

@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private UsersRepository usersRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        Optional<Users> usersOptional = usersRepository.findByName(username);

        usersOptional
            .orElseThrow(() -> new UsernameNotFoundException("Username not found!"));
        return usersOptional
            .map(CustomUserDetails::new)
            .get();
    }
}
@服务
公共类CustomUserDetailsService实现UserDetailsService{
@自动连线
私人用户Repository用户Repository;
@凌驾
public UserDetails loadUserByUsername(字符串用户名)引发UsernameNotFoundException{
可选usersOptional=usersRepository.findByName(用户名);
用户选择
.orelsetrow(()->new UsernameNotFoundException(“找不到用户名!”);
返回用户可选
.map(CustomUserDetails::新建)
.get();
}
}