auth.go 737 B

123456789101112131415161718192021222324252627
  1. package middleware
  2. import (
  3. "time"
  4. "device-manage/app/admin/middleware/handler"
  5. jwt "device-manage/pkg/jwtauth"
  6. "device-manage/tools/config"
  7. )
  8. func AuthInit() (*jwt.GinJWTMiddleware, error) {
  9. return jwt.New(&jwt.GinJWTMiddleware{
  10. Realm: "test zone",
  11. Key: []byte(config.ApplicationConfig.JwtSecret),
  12. Timeout: time.Hour,
  13. MaxRefresh: time.Hour,
  14. PayloadFunc: handler.PayloadFunc,
  15. IdentityHandler: handler.IdentityHandler,
  16. Authenticator: handler.Authenticator,
  17. Authorizator: handler.Authorizator,
  18. Unauthorized: handler.Unauthorized,
  19. TokenLookup: "header: Authorization, query: token, cookie: jwt",
  20. TokenHeadName: "Bearer",
  21. TimeFunc: time.Now,
  22. })
  23. }