Преглед изворни кода

remove debug statements and add state check back

Ivan Galakhov пре 4 година
родитељ
комит
2b665f8ca9
1 измењених фајлова са 7 додато и 8 уклоњено
  1. 7 8
      server/api/oauth_github_handler.go

+ 7 - 8
server/api/oauth_github_handler.go

@@ -319,22 +319,19 @@ func (app *App) HandleGithubAppOAuthCallback(w http.ResponseWriter, r *http.Requ
 		return
 	}
 
-	//if r.URL.Query().Get("state") != session.Values["state"] {
-	//	http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
-	//	return
-	//}
+	if r.URL.Query().Get("state") != session.Values["state"] {
+		http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+		return
+	}
 
 	token, err := app.GithubAppConf.Exchange(oauth2.NoContext, r.URL.Query().Get("code"))
 
 	if err != nil {
-		fmt.Println("error")
 		fmt.Println(err)
 		http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
 		return
 	}
 
-	fmt.Println("here")
-
 	if !token.Valid() {
 		http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
 		return
@@ -356,11 +353,13 @@ func (app *App) HandleGithubAppOAuthCallback(w http.ResponseWriter, r *http.Requ
 
 	oauthInt := &integrations.OAuthIntegration{
 		Client:       integrations.OAuthGithub,
-		UserID:       userID,
+		UserID:       user.ID,
 		AccessToken:  []byte(token.AccessToken),
 		RefreshToken: []byte(token.RefreshToken),
 	}
 
+	// error happens here because OAuthIntegration needs to have a project ID
+	// and we don't actually have a project ID here
 	oauthInt, err = app.Repo.OAuthIntegration.CreateOAuthIntegration(oauthInt)
 
 	if err != nil {