diff options
Diffstat (limited to 'token.go')
-rw-r--r-- | token.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/token.go b/token.go index 8ccbdb2..73089cd 100644 --- a/token.go +++ b/token.go @@ -24,27 +24,23 @@ type UserTokenResponse struct { func GetUserToken(authCode string) UserTokenResponse{ - // Define the URL and form data - apiURL := "https://id.twitch.tv/oauth2/token" // Replace with the actual URL to send the POST request to + apiURL := "https://id.twitch.tv/oauth2/token" data := url.Values{} - data.Set("client_id", clientID) - data.Set("client_secret", clientSecret) + data.Set("client_id", clientSecrets.ClientID) + data.Set("client_secret", clientSecrets.ClientSecret) data.Set("code", authCode) data.Set("grant_type", "authorization_code") data.Set("redirect_uri", "http://localhost:3000") - // Create the POST request req, err := http.NewRequest("POST", apiURL, bytes.NewBufferString(data.Encode())) if err != nil { fmt.Println("Error creating request:", err) panic(err) } - // Set the appropriate header for x-www-form-urlencoded req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - // Send the request client := &http.Client{} resp, err := client.Do(req) if err != nil { @@ -53,10 +49,10 @@ func GetUserToken(authCode string) UserTokenResponse{ } defer resp.Body.Close() - // Print the response status - // fmt.Println("Response Status:", resp.Status) + if DEBUG { + fmt.Println("Response Status:", resp.Status) + } - // You can read and print the body here if needed body, err := io.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) @@ -76,8 +72,8 @@ func GetUserToken(authCode string) UserTokenResponse{ func GetAppToken() string{ oauth2Config = &clientcredentials.Config{ - ClientID: clientID, - ClientSecret: clientSecret, + ClientID: clientSecrets.ClientID, + ClientSecret: clientSecrets.ClientSecret, TokenURL: twitch.Endpoint.TokenURL, } |