Skip to content

Commit

Permalink
✨ Remove viper
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Jul 7, 2024
1 parent 2794a54 commit bec42f6
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/configs"
"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/dao"
"github.com/go-sigma/sigma/pkg/utils/password"
Expand All @@ -50,8 +50,8 @@ func AuthWithConfig(config AuthConfig) echo.MiddlewareFunc {
return next(c)
}

privateKey := viper.GetString("auth.jwt.privateKey")
tokenService, err := token.NewTokenService(privateKey)
cfg := configs.GetConfiguration()
tokenService, err := token.NewTokenService(cfg.Auth.Jwt.PrivateKey)
if err != nil {
log.Error().Err(err).Msg("Create token service failed")
if config.DS {
Expand Down Expand Up @@ -163,18 +163,14 @@ func AuthWithConfig(config AuthConfig) echo.MiddlewareFunc {
}

func genWwwAuthenticate(host, schema string) string {
if viper.GetString("server.domain") != "" {
host = viper.GetString("server.domain")
}
cfg := configs.GetConfiguration()
realm := fmt.Sprintf("%s://%s%s/tokens", schema, host, consts.APIV1)
rRealm := viper.GetString("auth.token.realm")
if rRealm != "" {
realm = rRealm
if cfg.Auth.Token.Realm != "" {
realm = cfg.Auth.Token.Realm
}
service := consts.AppName
rService := viper.GetString("auth.token.service")
if rService != "" {
service = rService
if cfg.Auth.Token.Service != "" {
service = cfg.Auth.Token.Service
}
return fmt.Sprintf("Bearer realm=\"%s\",service=\"%s\"", realm, service)
}

0 comments on commit bec42f6

Please sign in to comment.