random commit

This commit is contained in:
bryce
2025-07-14 20:46:12 +12:00
parent 466cfb197c
commit 5b286926a3
6 changed files with 53 additions and 42 deletions

View File

@@ -44,7 +44,7 @@ func StartOAuthServer(addr string) error {
return http.ListenAndServe(addr, nil)
}
func HandleIndex(w http.ResponseWriter, r *http.Request) {
func handleIndex(w http.ResponseWriter, r *http.Request) {
authURL := fmt.Sprintf(
"https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s",
url.QueryEscape(clientID),
@@ -63,10 +63,10 @@ func HandleIndex(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(html))
}
func handleCallback(w http.ResponseWriter, r &http.Request) {
func handleCallback(w http.ResponseWriter, r *http.Request) {
code := r.URL.Query().Get("code")
if code == "" {
http.Error(w, "Missing code in query", https.StatusBadRequest)
http.Error(w, "Missing code in query", http.StatusBadRequest)
return
}
@@ -76,15 +76,15 @@ func handleCallback(w http.ResponseWriter, r &http.Request) {
return
}
jsonData, _ := json.MarshalIndent(token, "", " ")
jsonData, _ := json.MarshalIndent(token, "", " ")
w.Header().Set("Content-Type", "application/json")
w.Write([jsonData])
w.Write(jsonData)
}
func exchangeCodeForToken(code string) (*TokenResponse, error) {
data := url.Values{}
data.Set("client_id", clientID)
data.Set("client_Secret", clientSecret)
data.Set("client_secret", clientSecret)
data.Set("code", code)
data.Set("grant_type", "authorization_code")
data.Set("redirect_uri", redirectURI)