This commit is contained in:
PB
2025-10-20 17:11:36 +02:00
parent ddbb8bea25
commit f978db83ee
9 changed files with 30 additions and 103 deletions

View File

@@ -2,10 +2,6 @@ package service
import (
"errors"
"strconv"
baseCnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
"github.com/gofiber/fiber/v2"
)
var (
@@ -16,18 +12,14 @@ var (
)
func init() {
cookieExpireTime, _ := strconv.Atoi(baseCnf.GetEnv("AUTH_COOKIE_EXPIRE_TIME", "5"))
AuthService = &Auth{"jwt_token", "jwt_token_refresh", cookieExpireTime}
AuthService = &Auth{}
}
type Auth struct {
TokenCookieName string
RefreshTokenCookieName string
cookieExpireTime int
}
func (a *Auth) Login(login, pass string) (string, error) {
if login == "admin" && pass == "secret" {
func (a *Auth) Login(login, passwd string) (string, error) {
if login == "admin" && passwd == "secret" { // FIXME hardcoded
token, err := JWTService.CreateToken()
if err != nil {
return "", err
@@ -39,12 +31,7 @@ func (a *Auth) Login(login, pass string) (string, error) {
return "", ErrLoginIncorrect
}
// Cookie create fiber.Cookie struct
func (a *Auth) Cookie(name, value string) *fiber.Cookie {
return &fiber.Cookie{
Name: name,
Value: value,
MaxAge: a.cookieExpireTime * 300, // FIXME: env/config
Path: "/", // FIXME: env/config
}
func (a *Auth) Register(email, login, passwd string) (string, error) {
return "user-uuid", nil
}

View File

@@ -32,6 +32,7 @@ func (s *JWT) CreateToken() (string, error) {
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(s.tokenSecret)
}