# Spring Cloud Alibaba Gateway OAuth2 **Repository Path**: tswdya/vains ## Basic Information - **Project Name**: Spring Cloud Alibaba Gateway OAuth2 - **Description**: Spring Cloud Alibaba OAuth2 整合。使用SpringBoot Admin 监控项目,使用Swagger生成接口文档。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2022-03-23 - **Last Updated**: 2022-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # vains 本项目可作为学习或是一个脚手架使用。如果觉得项目不错,可以点个star,有什么问题也可以在下方评论区中提出。 #### 介绍 Spring Cloud Alibaba Gateway OAuth2 整合。 这个项目开发的目的是为了学习SpringCloud Alibaba的分布式框架,同时也是为了在分布式的情况下实现一次Oauth2(之前也尝试过,但因为各种原因最后都是不了了之),这一次也算是完整的实现了OAuth2的认证与鉴权。 其中也整合了SpringBoot Admin这个框架,用于管理和监控SpringBoot应用程序。 项目中Token的存储方式是存储在redis中,所以启动该项目前要保证redis可用。 #### 技术栈 | 技术 | 版本 | | --- | --- | | lombok | 1.18.12 | | springfox | 3.0.0 | | mybatis-plus | 3.4.2 | | Spring boot | 2.3.2.RELEASE | | Spring boot Admin | 2.3.1 | | Spring Cloud | Hoxton.SR9 | | Spring Cloud Alibaba | 2.2.5.RELEASE | | Spring Cloud OAuth2 | 2.2.4.RELEASE | | Spring Cloud Gateway | 2.2.6.RELEASE | | Spring Cloud openfeign | 2.2.6.RELEASE | #### 开发环境 MySQL 5.7.17 JDK 1.8.0_202 Redis 3.0.504 Apache Maven 3.6.3 IntelliJ IDEA 2019.3.5 #### 安装教程 1. 通过 https://gitee.com/vains-Sofia/vains.git 将项目克隆到本地。 2. 执行项目中的两个SQL文件:cloud_auth.sql和cloud_security.sql; 文件名即为数据库名。 3. 启动nacos,导入项目中的nacos配置:nacos_config_export_20210412153243.zip 4. 依次启动 AuthServerApplication --->>> TestApplication --->>> UserApplication --->>> GatewayApplication; 前三个顺序无所谓,但是要保证网关最后启动。 5. 访问 http://localhost:5000/swagger-ui/ 来查看swagger文档 6. 访问 http://localhost:5000 查看SpringBoot Admin提供的监控页面,可以查看在线日志。 #### 使用说明 1. vains-auth是认证模块,其中子模块vains-auth-server是认证中心,auth-spring-boot-starter是资源服务器配置,任何导入该模块的模块都是资源服务器,需在yml中添加几个简单的配置。 2. vains-common是一个公共模块,里边封装了一个常量类、工具类、异常处理和公共的swagger配置等。 3. vains-test是一个测试模块,他是一个资源服务器,里边提供了几个测试接口,提供鉴权测试,还有个授权码模式的回调接口,登录之后自动跳转并返回授权码。 4. vains-user是用户管理模块,认证中心从该模块中获取用户的信息和权限信息等。通过feign来实现模块之间的调用。 5. vains-gateway是网关模块,所有请求都发送到该模块(授权码模式除外),再由该模块转发到下游对应的服务。 #### 获取Token的几个接口 ##### 密码模式登陆 http://localhost:5000/auth-server/oauth/token?username=123&password=123456&grant_type=password&client_secret=123456&client_id=auth-server ##### 授权码模式登陆 http://localhost:5001/oauth/authorize?client_id=authorizeResource&response_type=code 访问改地址后会自动跳转到登录页面,这里使用了X-admin的登录页面。然后输入账号密码点击登录,会自动跳转到client_id对应的redirect_uri中,我配置的是test模块,在回调接口中做出对应的逻辑处理。 ##### 发起请求 请求时携带获取到的token,有两种方式: ?access_token=token字符串 请求头中: Authorization: Bearer token字符串 ###### 参与贡献 1. Fork 本仓库 2. 新建 vains_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)