|
|
@@ -2,7 +2,6 @@ package auth
|
|
|
|
|
|
import (
|
|
|
"git.sxidc.com/go-framework/baize/convenient/domain/auth/jwt_tools"
|
|
|
- "git.sxidc.com/go-framework/baize/convenient/domain/auth/middlewares"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/domain/auth/permission"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/domain/auth/permission_group"
|
|
|
"git.sxidc.com/go-framework/baize/convenient/domain/auth/relations"
|
|
|
@@ -34,16 +33,17 @@ type Simple struct {
|
|
|
|
|
|
// JWT到期时间
|
|
|
JWTExpiredSec int64
|
|
|
+
|
|
|
+ // 鉴权中间件
|
|
|
+ AuthMiddleware binding.Middleware
|
|
|
}
|
|
|
|
|
|
func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
- jwt_tools.SetJWTSecretKey(simple.JWTSecretKey)
|
|
|
-
|
|
|
- (&permission.Simple{Schema: simple.Schema}).Bind(binder)
|
|
|
- (&permission_group.Simple{Schema: simple.Schema}).Bind(binder)
|
|
|
- (&role.Simple{Schema: simple.Schema}).Bind(binder)
|
|
|
- (&user.Simple{Schema: simple.Schema, AESKey: simple.AESKey}).Bind(binder)
|
|
|
- (&relations.Simple{Schema: simple.Schema}).Bind(binder)
|
|
|
+ (&permission.Simple{Schema: simple.Schema, AuthMiddleware: simple.AuthMiddleware}).Bind(binder)
|
|
|
+ (&permission_group.Simple{Schema: simple.Schema, AuthMiddleware: simple.AuthMiddleware}).Bind(binder)
|
|
|
+ (&role.Simple{Schema: simple.Schema, AuthMiddleware: simple.AuthMiddleware}).Bind(binder)
|
|
|
+ (&user.Simple{Schema: simple.Schema, AESKey: simple.AESKey, AuthMiddleware: simple.AuthMiddleware}).Bind(binder)
|
|
|
+ (&relations.Simple{Schema: simple.Schema, AuthMiddleware: simple.AuthMiddleware}).Bind(binder)
|
|
|
|
|
|
// 登录
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[map[string]any]{
|
|
|
@@ -89,7 +89,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
return errResponse, err
|
|
|
}
|
|
|
|
|
|
- token, err := jwt_tools.NewJWT(existUser.ID, simple.JWTExpiredSec)
|
|
|
+ token, err := jwt_tools.NewJWT(simple.JWTSecretKey, existUser.ID, simple.JWTExpiredSec)
|
|
|
if err != nil {
|
|
|
return errResponse, errors.New(err.Error())
|
|
|
}
|
|
|
@@ -131,7 +131,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
|
|
|
return nil, nil
|
|
|
},
|
|
|
- }, middlewares.Authentication())
|
|
|
+ }, simple.AuthMiddleware)
|
|
|
|
|
|
// Challenge
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[UserWithRoleInfo]{
|
|
|
@@ -200,7 +200,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
|
|
|
RoleInfos: roleInfos,
|
|
|
}, nil
|
|
|
},
|
|
|
- }, middlewares.Authentication())
|
|
|
+ }, simple.AuthMiddleware)
|
|
|
}
|
|
|
|
|
|
func BindAuth(binder *binding.Binder, simple *Simple) {
|