auth.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package service
  2. import (
  3. "git.sxidc.com/go-framework/baize/convenient/domain/auth"
  4. "git.sxidc.com/go-framework/baize/convenient/domain/auth/middlewares"
  5. "git.sxidc.com/go-framework/baize/framework/core/api"
  6. "git.sxidc.com/go-framework/baize/framework/core/application"
  7. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  8. )
  9. func AuthMiddleware(i *infrastructure.Infrastructure) api.Handler {
  10. return func(c *api.Context) {
  11. middlewares.Authentication(dbSchema, jwtSecretKey)(c, i)
  12. }
  13. }
  14. var authService = &AuthService{}
  15. type AuthService struct{}
  16. func (svc *AuthService) Init(appInstance *application.App) error {
  17. svc.prefixRoot(appInstance)
  18. return nil
  19. }
  20. func (svc *AuthService) Destroy() error {
  21. return nil
  22. }
  23. func (svc *AuthService) prefixRoot(appInstance *application.App) {
  24. auth.BindAuth(appInstance, &auth.Simple{
  25. Schema: dbSchema,
  26. AESKey: aesKey,
  27. JWTSecretKey: jwtSecretKey,
  28. JWTExpiredSec: 24 * 3600,
  29. AuthMiddleware: middlewares.Authentication(dbSchema, jwtSecretKey),
  30. AdminUserPassword: "123456",
  31. })
  32. }