spring - Springboot 2 Oauth2 无法重定向到 SSO 客户端
问题描述
我目前正在研究 Springboot 2.x oauth2 的实现。但是我遇到了一些棘手的问题。
该项目包括 auth-server 和 sso-client(底部提供 GitHub 链接)。问题是:当我输入一个受保护的 URL(例如 localhost:9000/)时,它将被重定向到在 auth-server 中配置的登录页面。但是,成功登录后它不会重定向回 sso-client。
auth-server 的授权服务器配置:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
private AuthenticationManager authenticationManager;
public AuthorizationServerConfig(AuthenticationConfiguration authenticationConfiguration) throws Exception {
this.authenticationManager = authenticationConfiguration.getAuthenticationManager();
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
super.configure(security);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
.secret("secret")
.authorizedGrantTypes("authorization_code")
.scopes("all")
.autoApprove(true);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
}
auth-server 的安全配置:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("root")
.password(passwordEncoder().encode("root"))
.roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.csrf().disable();
}
}
sso 客户端的安全配置:
@Configuration
@EnableOAuth2Sso
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.anyRequest().authenticated();
}
}
sso 客户端的 application.yml:
auth-server: http://localhost:9090
server:
port: 9000
security:
oauth2:
client:
client-id: client
client-secret: secret
scope: all
user-authorization-uri: ${auth-server}/oauth/authorize
access-token-uri: ${auth-server}/oauth/token
resource:
token-info-uri: ${auth-server}/oauth/check_token
preferTokenInfo: false
这是该项目的链接:https ://github.com/paul8263/SpringBoot2Oauth2
PS:我使它与 Spring Boot 1.5.8 一起工作:https ://github.com/paul8263/SsoDemo2
我将代码与 Springboot2(第一个链接)进行了比较,但我几乎没有注意到任何明显的区别。
有人可以通过使简单的演示工作来帮助我解决这个问题吗?非常感谢。
解决方案
推荐阅读
- node.js - 使用本地开发 npm 模块
- ruby - 拆分字符串时忽略空捕获
- c# - 在 IIS 服务器上部署站点在为 umbraco 休息服务保存样式表时抛出 404
- angular - 如何读取角度 5 中可观察的值以显示或隐藏错误消息
- javascript - Angular - 动态注入内容到
零件 - c# - 如何解决限制为从 Azure ServiceBus 读取 1 个客户端的问题
- java - Proteus 中的 Arduino Uno 发送 � 字符
- vhdl - VHDL 按钮和 LED
- javascript - Office365 胖客户端中使用的 DOM 和 JavaScript 引擎
- mongodb - 我怎样才能在 mongodb 中得到这个结果?