- Added Oauth2LogLoginService for managing user authorization logs. - Implemented methods for inserting logs, cleaning logs, and exporting log data. - Created a new file for Oauth2 login log service. refactor: Remove unused open_api module - Deleted the open_api.go file as it was not utilized in the project. fix: Update error codes in SysProfileController - Changed error codes for binding errors and user authentication errors to more descriptive values. fix: Update cache handling in SysConfig and SysDictType services - Modified Redis set operations to include expiration time for cached values. refactor: Update middleware authorization checks - Replaced PreAuthorize middleware with AuthorizeUser across multiple routes in system and tool modules for consistency. chore: Clean up trace and ws modules - Updated middleware authorization in trace and ws modules to use AuthorizeUser.
84 lines
2.3 KiB
Go
84 lines
2.3 KiB
Go
package oauth2
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"be.ems/src/framework/logger"
|
|
"be.ems/src/framework/middleware"
|
|
monitorController "be.ems/src/modules/monitor/controller"
|
|
"be.ems/src/modules/oauth2/controller"
|
|
)
|
|
|
|
// Setup 模块路由注册
|
|
func Setup(router *gin.Engine) {
|
|
logger.Infof("开始加载 ====> oauth2 模块路由")
|
|
|
|
// 客户端授权管理
|
|
oauth2ClientGroup := router.Group("/oauth2/client")
|
|
{
|
|
oauth2ClientGroup.GET("/list",
|
|
middleware.AuthorizeUser(map[string][]string{"matchRoles": {"admin"}}),
|
|
controller.NewOauth2Client.List,
|
|
)
|
|
oauth2ClientGroup.GET("/:clientId",
|
|
middleware.AuthorizeUser(map[string][]string{"matchRoles": {"admin"}}),
|
|
controller.NewOauth2Client.Info,
|
|
)
|
|
oauth2ClientGroup.POST("",
|
|
middleware.AuthorizeUser(map[string][]string{"matchRoles": {"admin"}}),
|
|
middleware.OperateLog(middleware.OptionNew("log.operate.title.oauth2client", middleware.BUSINESS_TYPE_INSERT)),
|
|
controller.NewOauth2Client.Add,
|
|
)
|
|
oauth2ClientGroup.PUT("",
|
|
middleware.AuthorizeUser(map[string][]string{"matchRoles": {"admin"}}),
|
|
middleware.OperateLog(middleware.OptionNew("log.operate.title.oauth2client", middleware.BUSINESS_TYPE_UPDATE)),
|
|
controller.NewOauth2Client.Edit,
|
|
)
|
|
oauth2ClientGroup.DELETE("/:id",
|
|
middleware.AuthorizeUser(map[string][]string{"matchRoles": {"admin"}}),
|
|
middleware.OperateLog(middleware.OptionNew("log.operate.title.oauth2client", middleware.BUSINESS_TYPE_DELETE)),
|
|
controller.NewOauth2Client.Remove,
|
|
)
|
|
}
|
|
|
|
// 授权认证
|
|
oauth2Group := router.Group("/oauth2")
|
|
{
|
|
oauth2Group.GET("/authorize",
|
|
middleware.RateLimit(middleware.LimitOption{
|
|
Time: 60,
|
|
Count: 30,
|
|
Type: middleware.LIMIT_IP,
|
|
}),
|
|
controller.NewOauth2.Authorize,
|
|
)
|
|
oauth2Group.POST("/token",
|
|
middleware.RateLimit(middleware.LimitOption{
|
|
Time: 180,
|
|
Count: 15,
|
|
Type: middleware.LIMIT_IP,
|
|
}),
|
|
controller.NewOauth2.Token,
|
|
)
|
|
oauth2Group.POST("/refresh-token",
|
|
middleware.RateLimit(middleware.LimitOption{
|
|
Time: 60,
|
|
Count: 5,
|
|
Type: middleware.LIMIT_IP,
|
|
}),
|
|
controller.NewOauth2.RefreshToken,
|
|
)
|
|
}
|
|
|
|
// ==== 开放接口 ====
|
|
|
|
openApiGroup := router.Group("/open-api")
|
|
{
|
|
openApiGroup.GET("/monitor/system",
|
|
middleware.AuthorizeOauth2(nil),
|
|
monitorController.NewSystem.Info,
|
|
)
|
|
}
|
|
|
|
}
|