Fix stale cmd/ scripts, export LoginWithChromedp, clean up vet warnings
Update 5 cmd/ test utilities that referenced APIs that drifted after bridge refactors (NewBrowserAuthManager, bridge.NewConfig, changed function signatures). Rewrite test-kosmi and test-native to use NewGraphQLWSClient directly. Export LoginWithChromedp for use by cmd scripts. Fix redundant-newline vet warnings across 5 cmd/ files. Remove unreachable code and replace deprecated ioutil calls in bridge/helper/lottie_convert.go. Made-with: Cursor
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
bkosmi "github.com/42wim/matterbridge/bridge/kosmi"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -23,7 +26,6 @@ func main() {
|
||||
email := os.Args[1]
|
||||
password := os.Args[2]
|
||||
|
||||
// Set up logging
|
||||
log := logrus.New()
|
||||
log.SetLevel(logrus.DebugLevel)
|
||||
entry := logrus.NewEntry(log)
|
||||
@@ -31,11 +33,7 @@ func main() {
|
||||
fmt.Println("🚀 Testing browser-based authentication...")
|
||||
fmt.Println()
|
||||
|
||||
// Create browser auth manager
|
||||
browserAuth := bkosmi.NewBrowserAuthManager(email, password, entry)
|
||||
|
||||
// Get token
|
||||
token, err := browserAuth.GetToken()
|
||||
token, err := bkosmi.LoginWithChromedp(email, password, entry)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Authentication failed: %v\n", err)
|
||||
os.Exit(1)
|
||||
@@ -48,27 +46,32 @@ func main() {
|
||||
fmt.Printf("Token length: %d characters\n", len(token))
|
||||
fmt.Println()
|
||||
|
||||
// Check if authenticated
|
||||
if browserAuth.IsAuthenticated() {
|
||||
fmt.Println("✅ Token is valid")
|
||||
} else {
|
||||
fmt.Println("❌ Token is invalid or expired")
|
||||
}
|
||||
|
||||
// Get user ID
|
||||
userID := browserAuth.GetUserID()
|
||||
userID := extractUserIDFromJWT(token)
|
||||
if userID != "" {
|
||||
fmt.Printf("User ID: %s\n", userID)
|
||||
} else {
|
||||
fmt.Println("(Could not extract user ID from token)")
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("🎉 Test completed successfully!")
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
func extractUserIDFromJWT(token string) string {
|
||||
parts := strings.Split(token, ".")
|
||||
if len(parts) != 3 {
|
||||
return ""
|
||||
}
|
||||
return b
|
||||
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
var claims map[string]interface{}
|
||||
if err := json.Unmarshal(payload, &claims); err != nil {
|
||||
return ""
|
||||
}
|
||||
if sub, ok := claims["sub"].(string); ok {
|
||||
return sub
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user