我加了网关之后,自定义登录页面,登录成功跳转不回/oauth/authorize 这个页面了。直接访问授权服务是可以的
来源:5-11 实现基于token的SSO(1)
qq_华仔很忙_14340718
2019-11-06
登录页面
<form class="form-signin" action="./login" method="post">
<h2 class="form-signin-heading">请 登 录</h2>
<input type="text" class="form-control" placeholder="账号" name="username"/>
<input type="password" class="form-control" placeholder="密码" name="password"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
</form>
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailServiceImpl();
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/oauth/**").permitAll() //此处不太对
.and()
.formLogin()
.loginPage("/login") ;
http .csrf().disable();
}
}
public class ClientDetailsConfig implements ClientDetailsService {
private Map<String, ClientDetails> clientDetailsStore = new HashMap<String, ClientDetails>();
/**
* @method
* @description 项目管理service
* @date: 2019-10-13 19:37
* @author: zhangzhenhua
* @Param: null
* @return
*/
@Autowired
private SysProjectService sysProjectService;
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
QueryWrapper<SysProjectPO> queryWrapper = new QueryWrapper<SysProjectPO>();
queryWrapper.eq("code", clientId);
SysProjectPO projectModel = sysProjectService.getOne(queryWrapper);
if (projectModel == null) {
throw new ClientRegistrationException("该客户端不存在");
}
BaseClientDetails baseClientDetails = new BaseClientDetails(projectModel.getCode(),
projectModel.getCode(),
"all",
projectModel.getAuthorizedType(),
projectModel.getSecret(),
projectModel.getReturnUrl()
);
baseClientDetails.setAccessTokenValiditySeconds(20);
baseClientDetails.setRefreshTokenValiditySeconds(20);
return baseClientDetails;
}
}
我在详细说下:
第一步:http://localhost:9000/authorization/oauth/authorize?client_id=back&response_type=token 9000这个是网关服务,
routes:
- id: authorization
uri: lb://authorization-server
predicates:
- Path=/authorization/**
filters:
- StripPrefix=1
第二步:跳转到授权服务/login,正常登录成功之后应该调回 http://localhost:8300/oauth/authorize,点击授权然后跳转到项目returnurl,但是跳转不回去了。
写回答
2回答
-
JoJo
2019-11-07
不能这么做,/oauth/authorize这个请求不能走网关,不然会出现你的这个问题。原因是网关转发这个请求时,在服务器端的session和login的session不同,而auth server是通过session获取login之前的原始请求的。如果要修正,需要修改服务端获取login之前请求的方式。
112019-11-24 -
慕沐4323715
2019-11-07
请问后来怎么解决的
00
相似问题