Files
go-admin/middleware/auth.go
T
2020-04-18 10:06:44 +08:00

28 lines
733 B
Go

package middleware
import (
"go-admin/handler"
jwt "go-admin/pkg/jwtauth"
"go-admin/tools/config"
"time"
)
func AuthInit() (*jwt.GinJWTMiddleware, error) {
return jwt.New(&jwt.GinJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Timeout: time.Hour,
MaxRefresh: time.Hour,
IdentityKey: config.ApplicationConfig.JwtSecret,
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,
})
}