oauth_start.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package gitinstallation
  2. import (
  3. "net/http"
  4. "github.com/porter-dev/porter/api/server/handlers"
  5. "github.com/porter-dev/porter/api/server/shared/config"
  6. "github.com/porter-dev/porter/api/types"
  7. "github.com/porter-dev/porter/internal/analytics"
  8. "github.com/porter-dev/porter/internal/models"
  9. "golang.org/x/oauth2"
  10. )
  11. type GithubAppOAuthStartHandler struct {
  12. handlers.PorterHandler
  13. }
  14. func NewGithubAppOAuthStartHandler(
  15. config *config.Config,
  16. ) *GithubAppOAuthStartHandler {
  17. return &GithubAppOAuthStartHandler{
  18. PorterHandler: handlers.NewDefaultPorterHandler(config, nil, nil),
  19. }
  20. }
  21. func (c *GithubAppOAuthStartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  22. user, _ := r.Context().Value(types.UserScope).(*models.User)
  23. c.Config().AnalyticsClient.Track(analytics.GithubConnectionStartTrack(
  24. &analytics.GithubConnectionStartTrackOpts{
  25. UserScopedTrackOpts: analytics.GetUserScopedTrackOpts(user.ID),
  26. },
  27. ))
  28. http.Redirect(w, r, c.Config().GithubAppConf.AuthCodeURL("", oauth2.AccessTypeOffline), 302)
  29. }