package middleware import ( "time" "git.ilapage.cn/OPC/chorus/admin/common/middleware/handler" "github.com/go-admin-team/go-admin-core/sdk/config" jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" ) // AuthInit jwt验证new func AuthInit() (*jwt.GinJWTMiddleware, error) { timeout := time.Hour if config.ApplicationConfig.Mode == "dev" { timeout = time.Duration(876010) * time.Hour } else { if config.JwtConfig.Timeout != 0 { timeout = time.Duration(config.JwtConfig.Timeout) * time.Second } } return jwt.New(&jwt.GinJWTMiddleware{ Realm: "test zone", Key: []byte(config.JwtConfig.Secret), Timeout: timeout, MaxRefresh: time.Hour, PayloadFunc: handler.PayloadFunc, IdentityHandler: handler.IdentityHandler, Authenticator: handler.Authenticator, Authorizator: handler.Authorizator, Unauthorized: handler.Unauthorized, // Management APIs use bearer headers only. Query and cookie tokens leak // into access logs or turn state-changing requests into CSRF targets. TokenLookup: "header: Authorization", TokenHeadName: "Bearer", TimeFunc: time.Now, }) }