Files
Tobias Gesellchen 6a815219f6 Implement /requestToken API and fix clock time display
Major Features:
• Implement complete /requestToken API endpoint for bearer token generation
• Fix clock time parsing and display with comprehensive time information
• Add comprehensive API documentation for 103 discovered endpoints

/requestToken Implementation:
• Add BearerToken model with full XML marshaling support
• Add RequestToken() client method with proper error handling
• Add 'soundtouch-cli token request' CLI command with security features
• Token validation, formatting, and secure display (truncated for security)
• Comprehensive unit tests and integration tests
• Support for Authorization header formatting and raw token extraction

Clock Time Fixes:
• Fix ClockTime model to match actual device XML response structure
• Add LocalTime component for nested time details
• Support for utcTime, timeFormat, brightness, clockError attributes
• Enhanced CLI display with comprehensive time information
• Fixed month conversion (device uses 0-11, Go uses 1-12)

Documentation Enhancements:
• Add comprehensive /supportedURLs endpoint analysis (103 endpoints discovered)
• Create detailed unimplemented endpoints documentation with examples
• Update API coverage from 34% implemented to full endpoint catalog
• Add SoundTouch End of Life notice with May 6, 2026 details
• Enhanced endpoint descriptions with real device response examples

Security:
• All tests use generic token examples (no real tokens exposed)
• Integration tests validate token properties without exposing values
• Secure token display with truncation in CLI and string representations
• Environment variable based testing for real devices

Testing:
• 15+ new test functions with comprehensive coverage
• Real device validation on 192.168.178.28 and 192.168.178.35
• Mock server tests and XML marshaling validation
• Integration tests with SOUNDTOUCH_TEST_HOST environment variable

CLI Enhancements:
• Enhanced clock time display with local time details and device settings
• New token management commands with usage instructions
• Improved error handling and user-friendly output formatting
2026-01-11 23:09:29 +01:00

57 lines
1.8 KiB
Go

package main
import (
"fmt"
"github.com/urfave/cli/v2"
)
// requestToken requests a new bearer token from the device
func requestToken(c *cli.Context) error {
clientConfig := GetClientConfig(c)
PrintDeviceHeader("Requesting bearer token", clientConfig.Host, clientConfig.Port)
client, err := CreateSoundTouchClient(clientConfig)
if err != nil {
PrintError(fmt.Sprintf("Failed to create client: %v", err))
return err
}
token, err := client.RequestToken()
if err != nil {
PrintError(fmt.Sprintf("Failed to request token: %v", err))
return err
}
fmt.Println("Bearer Token Information:")
if token.IsValid() {
fmt.Printf(" Status: Valid\n")
fmt.Printf(" Token: %s\n", token.String())
fmt.Printf(" Full value: %s\n", token.GetToken())
fmt.Printf(" Authorization header: %s\n", token.GetAuthHeader())
// Display token without Bearer prefix for API usage
fmt.Println("\nFor API Usage:")
fmt.Printf(" Raw token: %s\n", token.GetTokenWithoutPrefix())
// Usage instructions
fmt.Println("\nUsage Instructions:")
fmt.Println(" • Use the 'Authorization header' value in HTTP Authorization headers")
fmt.Println(" • Use the 'Raw token' value when an API requires token without 'Bearer ' prefix")
fmt.Println(" • Tokens are generated per request and may have expiration times")
// Security notice
fmt.Println("\nSecurity Notice:")
fmt.Println(" • Store tokens securely and avoid logging them in plain text")
fmt.Println(" • Tokens provide authentication - treat them as passwords")
fmt.Println(" • Request new tokens when needed rather than reusing old ones")
} else {
fmt.Printf(" Status: Invalid\n")
fmt.Printf(" Raw response: %s\n", token.GetToken())
PrintError("Received invalid bearer token from device")
}
return nil
}