The problem I encountered was solved by myself:
using grant in spring cloud oauth2 project_ The type is password/OAuth/token to access and obtain the token_ error。 In postman, as shown in the figure below:
{
"error": "server_error",
"error_description": "Internal Server Error"
}
Java background error is as follows:
endpoint.TokenEndpoint : Handling error: NestedServletException, Handler dispatch failed; nested exception is java.lang.StackOverflowError
This problem is due to grant_ Type = password represents the user name and password authorization
/**
* This configuration class, which mainly handles the verification of user names and passwords, etc.
*/
@Configuration
public class SecurityConfiger extends WebSecurityConfigurerAdapter {
@Autowired
private PasswordEncoder passwordEncoder;
//register 1 authentication manager object to the container
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
/**
* Password encoding object (passwords are not encrypted)
*/
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
/**
* Handle username and password authentication
* 1) The client passes username and password parameters to the authentication server
* 2) Generally, username and password are stored in the database in the user table
* 3) Verify the legitimacy of the currently passed user information based on the data in the user table
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
super.configure(auth);
// In this method you can go to the associated database, currently we first configure the user information in memory
// instantiate 1 user object (equivalent to 1 user record in the data table)
UserDetails user = new User("admin","123456",new ArrayList<>());
auth.inMemoryAuthentication()
.withUser(user).passwordEncoder(passwordEncoder);
}
}
Problem solving: the following are purely personal views: