Fetch the repository succeeded.
This action will force synchronization from 东莞理工学院-黎志雄/基于Spring Security 5的OAuth2通用登录模块, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
使用本项目的演示Demo,请参考这个仓库:https://gitee.com/dgut-sai/security-oauth2-sample
mvn install
<dependency>
<groupId>com.gitee.dgut-sai</groupId>
<artifactId>security-oauth2</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
spring:
security:
oauth2:
client:
registration:
github:
client-id: *****
client-secret: *****
weixin:
client-id: *****
client-secret: ******
dgut:
client-id: *****
client-secret: *****
qq:
client-id: *****
client-secret: *****
# 进入 钉钉开发者平台 的页面,点击左侧菜单的【移动接入应用-登录】,然后点击右上角的【创建扫码登录应用授权】,创建用于免登过程中验证身份的appId及appSecret,创建后即可看到appId和appSecret。
dingding:
client-id: *****
client-secret: *****
# v2.2 增加码云 oauth2 登录
gitee:
client-id: ****
client-secret: ****
# 微信公众号平台 微信网页授权登录 , 可以在公众号管理后台申请测试号,以获取appid与secret。
# 测试时,网页需要在 微信开发者工具中 打开。
WXMP:
client-id: ****
client-secret: ****
# 下面的属性设置获取code后的回调地址的前缀,最终根据注册ID解释后的地址如:/uaa/login/qq、/uaa/login/weixin
# 默认值是:/login/oauth2/code,最终值为:/login/oauth2/code/qq、/login/oauth2/code/weixin
# 把最终的url设置在OAuth2提供商的回调地址那, 如:http://localhost/uaa/login/weixin
sai:
security:
oauth2:
authorizationResponseBasePath: /uaa/login
@EnableSaiOAuth2Login
@Configuration
public class SaiOAuth2LoginConfiguration extends WebSecurityConfigurerAdapter {
// 设置security的拦截规则 START
@Override
public void configure(WebSecurity web) {
// 不能在这个方法里忽略登录login的路径
// 否则security的filter都不匹配login路径造成不能登录
// 在这里忽略掉静态资源的路径是比较好的选择
// 这与在配置文件设置security.ignoring是一样的
web.ignoring().antMatchers("/css/**", "/js/**", "/fonts/**", "/images/**", "/favicon.ico", "/webjars/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.apply(new SaiOAuth2LoginSecurityConfigurer())
.and()
.oauth2Login().loginPage("/login").permitAll()
// .defaultSuccessUrl("/",true)
.successHandler((request, response, authentication) -> {
// 一般登录成功后,我们会根据业务要求作一些处理。我们可以定义successHandler完成这个需求。
// 当我们定义了 successHandler 后,defaultSuccessUrl会失效。
// 注意,authentication 变量的实际类型是 OAuth2AuthenticationToken 。
// 同时,SecurityContextHolder.getContext().getAuthentication() 也引用了这个对象,这里只是作示例提醒一下。
log.info("SecurityContextHolder.getContext().getAuthentication() = " + SecurityContextHolder.getContext().getAuthentication());
log.info("authentication = " + authentication);
response.sendRedirect("/");
})
;
// @formatter:on
}
}
微信:13026844888 QQ:2231068
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。