From b3b33733b017627b28aef27a99077bdb32f84b6e Mon Sep 17 00:00:00 2001 From: abs3nt Date: Tue, 10 Jan 2023 18:01:40 -0800 Subject: [PATCH] port and xdg open --- README.md | 13 +++++++++++-- internal/auth/auth.go | 14 ++++++++------ internal/config/config.go | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fc96813..08abb74 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,18 @@ then to use add your information to ~/.config/gospt/client.yml like this ``` -client_id: ID -client_secret: SECRET +client_id: "idgoeshere" +client_secret: "secretgoeshere" +port: "8888" ``` +if you dont want to store your secret in the file in plaintext you can use a command to retreive it: + +``` +client_secret_cmd: "secret spotify_secret" +``` + +you should have either client_secret or client_secret_cmd + then run diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 3d23785..6f1c437 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "os/exec" "path/filepath" "gospt/internal/config" @@ -25,17 +26,17 @@ var ( ) func GetClient(ctx *gctx.Context) (*spotify.Client, error) { - if config.Values.ClientId == "" || config.Values.ClientSecret == "" { + if config.Values.ClientId == "" || config.Values.ClientSecret == "" || config.Values.Port == "" { configDir, _ := os.UserConfigDir() fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/client.yml")) fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications") - fmt.Println("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"") + fmt.Print("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"\nport:\"8888\"\n\n") return nil, fmt.Errorf("\nINVALID CONFIG") } auth = spotifyauth.New( spotifyauth.WithClientID(config.Values.ClientId), spotifyauth.WithClientSecret(config.Values.ClientSecret), - spotifyauth.WithRedirectURL("http://localhost:1024/callback"), + spotifyauth.WithRedirectURL(fmt.Sprintf("http://localhost:%s/callback", config.Values.Port)), spotifyauth.WithScopes( spotifyauth.ScopeImageUpload, spotifyauth.ScopePlaylistReadPrivate, @@ -102,14 +103,15 @@ func GetClient(ctx *gctx.Context) (*spotify.Client, error) { log.Println("Got request for:", r.URL.String()) }) go func() { - err := http.ListenAndServe(":1024", nil) + err := http.ListenAndServe(fmt.Sprintf(":%s", config.Values.Port), nil) if err != nil { log.Fatal(err) } }() url := auth.AuthURL(state) - fmt.Println("GO HERE", url) - + fmt.Println(url) + cmd := exec.Command("xdg-open", url) + cmd.Start() // wait for auth to complete client := <-ch diff --git a/internal/config/config.go b/internal/config/config.go index 8a47056..aa990a3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,4 +4,5 @@ var Values struct { ClientId string `yaml:"client_id"` ClientSecret string `yaml:"client_secret"` ClientSecretCmd string `yaml:"client_secret_cmd"` + Port string `yaml:"port"` }