auth.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package auth
  2. import (
  3. "context"
  4. "errors"
  5. )
  6. // TokenResponse represents the response containing both access and refresh tokens
  7. type TokenResponse struct {
  8. AccessToken string `json:"access_token"`
  9. RefreshToken string `json:"refresh_token"`
  10. ExpiresIn int64 `json:"expires_in"` // Expiration time in seconds
  11. TokenType string `json:"token_type"` // Usually "Bearer"
  12. }
  13. var (
  14. ErrTokenExpired = errors.New("token has expired")
  15. ErrInvalidToken = errors.New("token is invalid")
  16. ErrTokenBlacklisted = errors.New("token has been revoked")
  17. )
  18. // Service defines the interface for authentication operations
  19. type Service interface {
  20. // GenerateToken creates new access and refresh tokens for a user
  21. GenerateToken(ctx context.Context, clientID string, role string) (*TokenResponse, error)
  22. // ValidateToken verifies a token and returns the client ID if valid
  23. ValidateToken(ctx context.Context, token string) (string, error)
  24. // RefreshToken creates a new access token based on a valid refresh token
  25. RefreshToken(ctx context.Context, refreshToken string) (*TokenResponse, error)
  26. // Logout invalidates both access and refresh tokens
  27. Logout(ctx context.Context, token string) error
  28. }