add config to deps

This commit is contained in:
2025-12-18 19:59:22 +02:00
parent 99fd0f5776
commit f65150cec3

View File

@@ -3,6 +3,8 @@ package token
import ( import (
"fmt" "fmt"
"time" "time"
"git.oblat.lv/alex/triggerssmith/internal/config"
) )
type TokenStore interface { type TokenStore interface {
@@ -11,20 +13,29 @@ type TokenStore interface {
} }
type Service struct { type Service struct {
cfg *config.Auth
store TokenStore store TokenStore
} }
func NewTokenService(store TokenStore) (*Service, error) { func NewTokenService(cfg *config.Auth, store TokenStore) (*Service, error) {
if store == nil { if store == nil {
return nil, fmt.Errorf("store is nil") return nil, fmt.Errorf("store is nil")
} }
return &Service{store: store}, nil if cfg == nil {
return nil, fmt.Errorf("config is nil")
}
return &Service{cfg: cfg, store: store}, nil
} }
func (s *Service) Revoke(jti string, exp time.Time) error { func (s *Service) Revoke(jti string, exp time.Time) error {
return s.store.revoke(jti, exp) return s.store.revoke(jti, exp)
} }
func (s *Service) RevokeByRefreshDefault(jti string) error {
expiryTime := time.Now().Add(-time.Duration(s.cfg.RefreshTokenTTL))
return s.store.revoke(jti, expiryTime)
}
func (s *Service) IsRevoked(jti string) (bool, error) { func (s *Service) IsRevoked(jti string) (bool, error) {
return s.store.isRevoked(jti) return s.store.isRevoked(jti)
} }