mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-16 07:36:15 +00:00
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
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// BearerToken represents a bearer token response from the device
|
|
type BearerToken struct {
|
|
XMLName xml.Name `xml:"bearertoken"`
|
|
Value string `xml:"value,attr"`
|
|
}
|
|
|
|
// GetToken returns the bearer token value
|
|
func (b *BearerToken) GetToken() string {
|
|
return b.Value
|
|
}
|
|
|
|
// GetTokenWithoutPrefix returns the bearer token value without the "Bearer " prefix
|
|
func (b *BearerToken) GetTokenWithoutPrefix() string {
|
|
token := b.Value
|
|
if strings.HasPrefix(token, "Bearer ") {
|
|
return token[7:]
|
|
}
|
|
|
|
return token
|
|
}
|
|
|
|
// IsValid returns true if the bearer token has a valid value
|
|
func (b *BearerToken) IsValid() bool {
|
|
return b.Value != "" && strings.HasPrefix(b.Value, "Bearer ")
|
|
}
|
|
|
|
// String returns a string representation of the bearer token
|
|
func (b *BearerToken) String() string {
|
|
if !b.IsValid() {
|
|
return "Invalid bearer token"
|
|
}
|
|
|
|
// Show only first and last 10 characters for security
|
|
token := b.GetTokenWithoutPrefix()
|
|
if len(token) > 20 {
|
|
return fmt.Sprintf("Bearer %s...%s", token[:10], token[len(token)-10:])
|
|
}
|
|
|
|
return b.Value
|
|
}
|
|
|
|
// GetAuthHeader returns the token formatted for use in Authorization headers
|
|
func (b *BearerToken) GetAuthHeader() string {
|
|
if !b.IsValid() {
|
|
return ""
|
|
}
|
|
|
|
return b.Value
|
|
}
|
|
|
|
// NewBearerToken creates a new BearerToken with the given token value
|
|
func NewBearerToken(token string) *BearerToken {
|
|
// Ensure token has "Bearer " prefix
|
|
if !strings.HasPrefix(token, "Bearer ") {
|
|
token = "Bearer " + token
|
|
}
|
|
|
|
return &BearerToken{
|
|
Value: token,
|
|
}
|
|
}
|