A Go library for Skyspark API authentication using SCRAM (Salted Challenge Response Authentication Mechanism).
This library provides a Go implementation of the SCRAM authentication protocol used by Skyspark servers. It translates the original PHP implementation into idiomatic Go code with proper error handling and modern Go practices.
- SCRAM Authentication: Complete implementation of SCRAM-SHA-256 authentication
- PBKDF2 Key Derivation: Secure password-based key derivation
- HMAC-SHA256: Cryptographic message authentication
- HTTP Client: Built-in HTTP client with timeout and proper headers
- API Integration: High-level API for making authenticated requests
- Error Handling: Comprehensive error handling with detailed error messages
go get gosparkpackage main
import (
"fmt"
"log"
"gospark"
)
func main() {
// Create a new client
client := gospark.NewSkysparkClient(
"https://your-skyspark-server.com/api",
"your-username",
"your-password",
)
// Perform authentication
authToken, err := client.Scram()
if err != nil {
log.Fatalf("Authentication failed: %v", err)
}
fmt.Printf("Authenticated! Token: %s\n", authToken)
}Creates a new Skyspark client instance.
func NewSkysparkClient(uri, username, password string) *SkysparkClientParameters:
uri: The Skyspark server URI (e.g., "https://server.com/api")username: Your Skyspark usernamepassword: Your Skyspark password
Performs SCRAM authentication and returns an auth token.
func (s *SkysparkClient) Scram() (string, error)Returns:
string: Authentication token for subsequent requestserror: Any error that occurred during authentication
Makes authenticated API calls with automatic authentication handling.
func (s *SkysparkClient) HuckleberryAPI(function string, values []map[string]interface{}, debug bool) (interface{}, error)Parameters:
function: The API function name to callvalues: Array of parameter maps (can be nil for no parameters)debug: Whether to enable debug output
Returns:
interface{}: The API response (parsed JSON)error: Any error that occurred
Makes authenticated HTTP requests directly.
func (s *SkysparkClient) Curl(authToken, urlPath string, debug bool) (interface{}, error)Parameters:
authToken: Authentication token from Scram()urlPath: API endpoint pathdebug: Whether to return raw response instead of parsed JSON
client := gospark.NewSkysparkClient(
"https://your-server.com/api",
"username",
"password",
)
authToken, err := client.Scram()
if err != nil {
log.Fatal(err)
}result, err := client.HuckleberryAPI("myFunction", []map[string]interface{}{
{
"param1": "value1",
"param2": 123,
"s": "special_value", // URL encoded automatically
},
}, false)result, err := client.HuckleberryAPI("simpleFunction", nil, false)authToken, err := client.Scram()
if err != nil {
log.Fatal(err)
}
response, err := client.Curl(authToken, "/endpoint", false)The library provides detailed error messages for various failure scenarios:
- Network connectivity issues
- Authentication failures
- Invalid server responses
- JSON parsing errors
- Cryptographic operation failures
- Cryptographically Secure Random Numbers: Uses
crypto/randfor nonce generation - HMAC-SHA256: For message authentication
- PBKDF2: For secure key derivation
- Base64 URL-Safe Encoding: For transport encoding
- Timeout Protection: HTTP client with configurable timeouts
golang.org/x/crypto: For cryptographic operations- Standard library packages:
crypto/hmac,crypto/sha256,crypto/rand, etc.
This project is licensed under the same terms as the original project.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
See the example/ directory for a complete working example.
Go library to call Skyspark Axon functions via API