spring-boot - OAUTH2:成功表单登录后没有出现授权决策页面
问题描述
我正在为获取授权代码编写基于表单的 OAUTH 身份验证。在资源服务器要求资源所有者进行身份验证以及授权共享数据之后,它应该有一个“授权决策页面”。
以下是服务器端配置
授权服务器
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("javainuse").secret("{noop}secret").authorizedGrantTypes("authorization_code")
.scopes("read").authorities("CLIENT");
}
}
网络安全配置器
@Configuration
@EnableWebSecurity
public class EmployeeSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
@Override
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/user/getEmployeesList")
.hasAnyRole("ADMIN").anyRequest().authenticated().and().formLogin()
.permitAll().and().logout().permitAll();
http.csrf().disable();
}
@Override
public void configure(AuthenticationManagerBuilder authenticationMgr) throws Exception {
authenticationMgr.inMemoryAuthentication().withUser("admin").password(passwordEncoder.encode("admin"))
.authorities("ROLE_ADMIN");
}
}
以下是客户端配置
控制器
@Controller
public class EmployeeController {
@RequestMapping(value = "/getEmployees", method = RequestMethod.GET)
public ModelAndView getEmployeeInfo() {
return new ModelAndView("getEmployees");
}
@RequestMapping(value = "/showEmployees", method = RequestMethod.GET)
public String getEmployeeInfo1() {
return "showEmployees";
}
}
获取雇员.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Employee</title>
</head>
<body>
<h3 style="color: red;">Add New Employee</h3>
<div id="addEmployee">
<form:form action="http://localhost:8081/oauth/authorize"
method="post" modelAttribute="emp">
<p>
<label>Enter Employee Id</label>
<input type="text" name="response_type" value="code" />
<input type="text" name="client_id" value="javainuse" />
<input type="text" name="redirect_uri" value="http://localhost:8090/showEmployees" />
<input type="text" name="scope" value="read" />
<input type="SUBMIT" value="Get Employee info" />
</form:form>
</div>
</body>
</html>
在登录提示上提供登录详细信息后
我提供了详细信息,在它应该在http://localhost:8081/oauth/authorize向我提供提示之后
它给了我关于日志的信息
INFO AuthorizationEndpoint : Handling OAuth2 error: error="invalid_request", error_description="At least one redirect_uri must be registered with the client."
非常感谢任何帮助,不知道我在哪里做错了。我正在使用 Spring Boot 2.0.2.RELEASE。
解决方案
输入标签中给出的redirect_uri值http://localhost:8090/showEmployees也需要在上面的授权服务器配置中映射,所以
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("javainuse").secret("secret").authorizedGrantTypes("authorization_code")
.scopes("read").authorities("CLIENT").redirectUris("http://localhost:8090/showEmployees");
}
推荐阅读
- c# - 语义搜索技术 3
- django - 在 Django admin 中的操作选择上从另一个模型中删除记录
- forms - 将表单链接到 AppDrag 上的后端 API
- java - 设计一个在类级别使用通配符定义类型的类,并在使用该类时将通配符与特定类型相关联
- java - 在 Spring Boot 中创建数据源时出错
- c# - 用于自定义值类型的 DataContractSerializer
- python - 从同一目录导入初始化对象保持无 - Python
- python - 由于缺少“functools_lru_cache”,更新到 Ubuntu 18.04 后无法导入 matplotlib
- php - 在 Woocommerce 中检查产品变体是否在购物车中
- javascript - 可编辑表 - 行扩展器 - Javascript / OJET