# easy-auth-project **Repository Path**: kun_gege/easy-auth-project ## Basic Information - **Project Name**: easy-auth-project - **Description**: 微服务的基本架构搭建 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 0 - **Created**: 2021-11-23 - **Last Updated**: 2022-05-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringBoot, SpringCloud, nacos, MyBatis ## README SpringCloud Gateway+SpringSecurity OAuth2 +三方登陆 (gitee) +nacos (注册和配置) +redis +mysql+ Mybatis 实现基础框架的搭建 \ 通过网关做统一认证授权和路由转发+接口重试+限流 ## 介绍 oauth2 使用的是数据库模式进行的存储\ 此框架实现了网关的统一认证授权 \ 和每个资源服务如果不通过网关直接访问资源服务也需要认证token(需要集成auth-resource-services)\ 否则提示认证失败的两种模式\ 具体案例请查看 auth-test 进行了解 \ 数据库文件在db 中 uaa 负责用户的登陆认证(集成资源服务器和授权服务器) \ auth-comomons - auth-common-core-api 封装通用的方法 - auth-common-feign 封装feign的配置 - auth-common-swagger 封装swagger配置 auth-config 封装通用的配置 \ auth-gateway 统一认证授权和路由转发 \ auth-order 订单测试模块 \ auth-resource-services 这个模块是封装的权限资源服务器 \ auth-test 使用feign调用order的测试模块 \ uaa-system 登录用户信息相关 \ db 数据库文件 ## 使用 nacos上的配置列表 ![img_6.png](pic/img_6.png) 网关的nacos配置 ![img_7.png](pic/img_7.png) uaa的nacos配置 ![img_8.png](pic/img_8.png) auth-test的nacos配置 ![img_9.png](pic/img_9.png) `使用网关时不要忘记将 /**/oauth/** 路径配置白名单` \ 经过网关进行登录 ![img.png](pic/img.png) 通过网关进行访问资源服务器 ![img_1.png](pic/img_1.png) 通过网关移除token ![img_2.png](pic/img_2.png) 不经过网关进行登录 ![img_3.png](pic/img_3.png) 访问资源服务 ![img_4.png](pic/img_4.png) 移除token ![img_5.png](pic/img_5.png) 使用feign调用另一个资源服务时请加上 @EnableBaseFeignInterceptor \ 增加整合swagger 如果使用的网关统一授权则只需要在网关模块中配置白名单即可访问对应的swagger路径 /doc.html ![img.png](pic/img_12.png) 如果 不是使用网关的统一授权或者是这两者都使用了 则需要分别在网关中配置白名单和对应的资源服务中也要配置白名单 \ 引入auth-common-swagger 模块进行集成swagger文档 \ 案例参照 auth-order 服务 ## 可能出现的问题 密码认证模式中的 实现UserServiceDetail时 \ 进行设置权限时 数据库的列不能有一个为null 否则会报错 集成auth-resource-services时需要配置一个默认的白名单 ![img_10.png](pic/img_10.png) oauth2 的这个类OAuth2SecurityExpressionMethods 利用的的是el表达式来判断权限信息 是在下面使用 \ ![img.png](pic/img_11.png) ### 如果对你有帮助,请伸出你的小手点个start😊