@@ -10,6 +10,7 @@ import (
1010 "encoding/json"
1111 "flag"
1212 "fmt"
13+ "io"
1314 "log"
1415 "net/http"
1516 "net/url"
@@ -182,9 +183,11 @@ func securityHeaders(next http.Handler) http.Handler {
182183
183184// oauthTokenResponse represents the GitHub OAuth token response
184185type oauthTokenResponse struct {
185- AccessToken string `json:"access_token"`
186- TokenType string `json:"token_type"`
187- Scope string `json:"scope"`
186+ AccessToken string `json:"access_token"`
187+ TokenType string `json:"token_type"`
188+ Scope string `json:"scope"`
189+ Error string `json:"error"`
190+ ErrorDescription string `json:"error_description"`
188191}
189192
190193// githubUser represents a GitHub user
@@ -596,13 +599,23 @@ func exchangeCodeForToken(code, redirectURI string) (string, error) {
596599 return "" , fmt .Errorf ("token exchange returned status %d" , resp .StatusCode )
597600 }
598601
602+ // Read the entire response body for debugging
603+ body , err := io .ReadAll (resp .Body )
604+ if err != nil {
605+ return "" , fmt .Errorf ("failed to read response body: %w" , err )
606+ }
607+
599608 // Parse response
600609 var tokenResp oauthTokenResponse
601- if err := json .NewDecoder (resp .Body ).Decode (& tokenResp ); err != nil {
610+ if err := json .Unmarshal (body , & tokenResp ); err != nil {
611+ // Log the raw response for debugging
612+ log .Printf ("Token exchange response body: %s" , string (body ))
602613 return "" , fmt .Errorf ("failed to parse token response: %w" , err )
603614 }
604615
605616 if tokenResp .AccessToken == "" {
617+ // Log the parsed response for debugging
618+ log .Printf ("Token response error: %s, description: %s" , tokenResp .Error , tokenResp .ErrorDescription )
606619 return "" , fmt .Errorf ("no access token in response" )
607620 }
608621
0 commit comments