SpringBoot集成Spring Security、OAuth2实现授权码模式
项目描述
springboot-security-oauth2
是一个基于SpringBoot的项目,集成了Spring Security和OAuth2,实现了资源访问的授权认证。该项目支持多种认证模式,包括client credentials
、password
和authorization code
。默认情况下,项目采用了最为复杂的authorization code
授权码认证模式,并实现了自定义的登录页、授权页、错误页,以及第三方用户登录功能。
主要功能
- 支持的OAuth2端点:
/oauth/authorize
/oauth/token
/oauth/refresh_token
/oauth/error
- Token存储:
- 默认使用
RedisTokenStore
将用户认证的accessToken
保存在Redis中。 - 代码中已经支持
JDBC
持久化存储Token,但目前处于注释状态。如果需要使用JDBCTokenStore
,可以使用以下SQL语句创建相应的数据表:USE `iot_boss`;
- 默认使用
使用说明
- 克隆项目:
git clone https://github.com/yourusername/springboot-security-oauth2.git
- 配置Redis:
- 确保本地或远程Redis服务正常运行。
- 在
application.properties
或application.yml
中配置Redis连接信息。
- 启动项目:
- 使用IDE(如IntelliJ IDEA或Eclipse)导入项目并启动。
- 或者使用Maven命令启动:
mvn spring-boot:run
- 访问应用:
- 打开浏览器访问
http://localhost:8080
,根据提示进行登录和授权操作。
- 打开浏览器访问
注意事项
- 如果需要切换到
JDBCTokenStore
,请取消相关代码的注释,并确保数据库中已创建相应的数据表。 - 项目默认使用
authorization code
模式,如果需要切换到其他认证模式,请修改相关配置。
贡献
欢迎提交Issue和Pull Request,共同完善该项目。
许可证
该项目采用MIT许可证,详情请参阅LICENSE
文件。