From 12080f04fb2121c1076a23cedc7e17e360da648d Mon Sep 17 00:00:00 2001 From: venomade Date: Mon, 16 Dec 2024 22:04:47 +0000 Subject: Improvements to README, DataDir, DEBUG and comments Expand README Remove Hardcoding of Data Directory Add DEBUG const Remove unnecesary comments --- oauth.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'oauth.go') diff --git a/oauth.go b/oauth.go index f41dde3..e3f4174 100644 --- a/oauth.go +++ b/oauth.go @@ -12,46 +12,42 @@ func openBrowser(url string) error { } func startServer(codeChannel chan string) { - // Step 5: Start a web server that listens on localhost:3000 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - // Extract the code parameter from the query string code := r.URL.Query().Get("code") if code != "" { - // Send the authorization code to the channel codeChannel <- code - // Respond to the browser fmt.Fprintf(w, "Authorization successful! You can now close this window.") } else { - // If there's no code, display an error http.Error(w, "Authorization failed", http.StatusBadRequest) } }) - // Start the server err := http.ListenAndServe(":3000", nil) if err != nil { fmt.Printf("Error starting server: %v\n", err) } } -func GetOAuth(clientID string) (string, error) { - // Step 1: Construct the URL with the provided client_id - url := fmt.Sprintf("https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=%s&redirect_uri=http://localhost:3000&scope=user%%3Aread%%3Afollows&state=xsscheckbasic101", clientID) +func GetOAuth() (string, error) { + url := fmt.Sprintf("%s?%s&%s&%s&%s&%s", + "https://id.twitch.tv/oauth2/authorize", + "response_type=code", + fmt.Sprintf("client_id=%s", clientSecrets.ClientID), + "redirect_uri=http://localhost:3000", + "scope=user%3Aread%3Afollows", + "state=xsscheckbasic101", + ) - // Step 2: Open the URL in the default web browser using xdg-open err := openBrowser(url) if err != nil { return "", fmt.Errorf("failed to open browser: %v", err) } - // Step 3: Start the HTTP server to capture the response codeChannel := make(chan string) go startServer(codeChannel) - // Step 4: Wait for the authorization code to be received code := <-codeChannel - // Return the authorization code return code, nil } -- cgit 1.4.1-2-gfad0