123456789101112131415161718192021222324252627282930313233343536 |
- package middleware
- import (
- "time"
- "git.cestong.com.cn/cecf/config-center-server/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,
- TokenLookup: "header: Authorization, query: token, cookie: jwt",
- TokenHeadName: "Bearer",
- TimeFunc: time.Now,
- })
- }
|