Documentation
¶
Index ¶
- Variables
- func ExtractAPIKey(authHeader string) string
- type APIKeyService
- type APIKeyServiceV2
- func (s *APIKeyServiceV2) CreateAPIKey(ctx context.Context, userID uuid.UUID, name string, ...) (string, *storage.APIKey, error)
- func (s *APIKeyServiceV2) DeleteAPIKey(ctx context.Context, keyID uuid.UUID) error
- func (s *APIKeyServiceV2) DeleteAPIKeyPermanently(ctx context.Context, keyID uuid.UUID) error
- func (s *APIKeyServiceV2) ListAPIKeysByUser(ctx context.Context, userID uuid.UUID) ([]*storage.APIKey, error)
- func (s *APIKeyServiceV2) ValidateAPIKey(ctx context.Context, key string) (*storage.APIKey, error)
- type AuthRateLimiter
- func (r *AuthRateLimiter) CheckAuthRateLimit(ctx context.Context, identifier string, maxAttempts int) (allowed bool, waitTime int, blocked bool, err error)
- func (r *AuthRateLimiter) GetWaitTime(ctx context.Context, identifier string) (waitTime int, blocked bool, err error)
- func (r *AuthRateLimiter) RecordFailedAttempt(ctx context.Context, identifier string) error
- func (r *AuthRateLimiter) RecordSuccess(ctx context.Context, identifier string) error
- type Claims
- type JWTService
- type ProviderKeyRepositoryInterface
- type ProviderKeyService
- func (s *ProviderKeyService) AddProviderKey(ctx context.Context, userID uuid.UUID, provider string, apiKey string) error
- func (s *ProviderKeyService) DeleteProviderKey(ctx context.Context, userID uuid.UUID, provider string) error
- func (s *ProviderKeyService) DeleteProviderKeyByID(ctx context.Context, userID uuid.UUID, keyID uuid.UUID) error
- func (s *ProviderKeyService) GetProviderKey(ctx context.Context, userID uuid.UUID, provider string) (string, error)
- func (s *ProviderKeyService) ListProviderKeys(ctx context.Context, userID uuid.UUID) ([]*storage.UserProviderKey, error)
- func (s *ProviderKeyService) UpdateProviderKey(ctx context.Context, userID uuid.UUID, provider string, apiKey string) error
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("invalid token") ErrExpiredToken = errors.New("token expired") )
Functions ¶
func ExtractAPIKey ¶
Types ¶
type APIKeyService ¶
type APIKeyService struct {
// contains filtered or unexported fields
}
func NewAPIKeyService ¶
func NewAPIKeyService(secret string) *APIKeyService
func (*APIKeyService) GenerateAPIKey ¶
func (s *APIKeyService) GenerateAPIKey() (string, error)
func (*APIKeyService) ValidateAPIKey ¶
func (s *APIKeyService) ValidateAPIKey(key string) bool
type APIKeyServiceV2 ¶
type APIKeyServiceV2 struct {
// contains filtered or unexported fields
}
func NewAPIKeyServiceV2 ¶
func NewAPIKeyServiceV2(repo storage.APIKeyRepositoryInterface, secret string) *APIKeyServiceV2
func (*APIKeyServiceV2) CreateAPIKey ¶
func (*APIKeyServiceV2) DeleteAPIKey ¶
func (*APIKeyServiceV2) DeleteAPIKeyPermanently ¶ added in v1.0.63
func (*APIKeyServiceV2) ListAPIKeysByUser ¶
func (*APIKeyServiceV2) ValidateAPIKey ¶
type AuthRateLimiter ¶
type AuthRateLimiter struct {
// contains filtered or unexported fields
}
func NewAuthRateLimiter ¶
func NewAuthRateLimiter(redis *storage.RedisClient) *AuthRateLimiter
func (*AuthRateLimiter) CheckAuthRateLimit ¶
func (r *AuthRateLimiter) CheckAuthRateLimit(ctx context.Context, identifier string, maxAttempts int) (allowed bool, waitTime int, blocked bool, err error)
identifier can be IP-based ("ip:...") or email-based ("email:..."). Returns: allowed, waitTime (seconds), blocked, error. - waitTime: how long to wait before next attempt (if not allowed) - blocked: whether the account is temporarily blocked
func (*AuthRateLimiter) GetWaitTime ¶
func (*AuthRateLimiter) RecordFailedAttempt ¶
func (r *AuthRateLimiter) RecordFailedAttempt(ctx context.Context, identifier string) error
func (*AuthRateLimiter) RecordSuccess ¶
func (r *AuthRateLimiter) RecordSuccess(ctx context.Context, identifier string) error
type Claims ¶
type Claims struct {
UserID string `json:"user_id"`
Email string `json:"email"`
Roles []string `json:"roles"` // Array of roles: ['user'], ['admin'], or ['user', 'admin']
jwt.RegisteredClaims
}
type JWTService ¶
type JWTService struct {
// contains filtered or unexported fields
}
func NewJWTService ¶
func NewJWTService(secret string) *JWTService
func (*JWTService) GenerateToken ¶
func (*JWTService) ValidateToken ¶
func (j *JWTService) ValidateToken(tokenString string) (*Claims, error)
type ProviderKeyRepositoryInterface ¶
type ProviderKeyRepositoryInterface interface {
Create(ctx context.Context, key *storage.UserProviderKey) error
FindByUserAndProvider(ctx context.Context, userID uuid.UUID, provider string) (*storage.UserProviderKey, error)
ListByUserID(ctx context.Context, userID uuid.UUID) ([]*storage.UserProviderKey, error)
Update(ctx context.Context, key *storage.UserProviderKey) error
Delete(ctx context.Context, userID uuid.UUID, provider string) error
DeleteByID(ctx context.Context, userID uuid.UUID, keyID uuid.UUID) error
}
type ProviderKeyService ¶
type ProviderKeyService struct {
// contains filtered or unexported fields
}
func NewProviderKeyService ¶
func NewProviderKeyService(repo ProviderKeyRepositoryInterface, encryptionKey string) (*ProviderKeyService, error)
func (*ProviderKeyService) AddProviderKey ¶
func (*ProviderKeyService) DeleteProviderKey ¶
func (s *ProviderKeyService) DeleteProviderKey(ctx context.Context, userID uuid.UUID, provider string) error
DeleteProviderKey removes a provider key (soft delete)
func (*ProviderKeyService) DeleteProviderKeyByID ¶
func (s *ProviderKeyService) DeleteProviderKeyByID(ctx context.Context, userID uuid.UUID, keyID uuid.UUID) error
DeleteProviderKeyByID removes a provider key by ID
func (*ProviderKeyService) GetProviderKey ¶
func (*ProviderKeyService) ListProviderKeys ¶
func (s *ProviderKeyService) ListProviderKeys(ctx context.Context, userID uuid.UUID) ([]*storage.UserProviderKey, error)
func (*ProviderKeyService) UpdateProviderKey ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter(redis *storage.RedisClient) *RateLimiter
func (*RateLimiter) CheckRateLimit ¶
func (*RateLimiter) GetRemainingRequests ¶
Click to show internal directories.
Click to hide internal directories.