add config to deps
This commit is contained in:
@@ -3,6 +3,8 @@ package token
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||
)
|
||||
|
||||
type TokenStore interface {
|
||||
@@ -11,20 +13,29 @@ type TokenStore interface {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
cfg *config.Auth
|
||||
store TokenStore
|
||||
}
|
||||
|
||||
func NewTokenService(store TokenStore) (*Service, error) {
|
||||
func NewTokenService(cfg *config.Auth, store TokenStore) (*Service, error) {
|
||||
if store == 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 {
|
||||
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) {
|
||||
return s.store.isRevoked(jti)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user