|
|
@@ -3,6 +3,7 @@ package gitinstallation
|
|
|
import (
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
+ "net/url"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
"github.com/porter-dev/porter/api/server/shared"
|
|
|
@@ -42,8 +43,15 @@ func (c *GithubAppOAuthCallbackHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
token, err := c.Config().GithubAppConf.Exchange(oauth2.NoContext, r.URL.Query().Get("code"))
|
|
|
|
|
|
if err != nil || !token.Valid() {
|
|
|
- if session.Values["query_params"] != "" {
|
|
|
- http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
|
|
|
+ if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
|
|
|
+ // attempt to parse the redirect uri, if it fails just redirect to dashboard
|
|
|
+ redirectURI, err := url.Parse(redirectStr)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ http.Redirect(w, r, "/dashboard", 302)
|
|
|
+ }
|
|
|
+
|
|
|
+ http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
|
|
|
} else {
|
|
|
http.Redirect(w, r, "/dashboard", 302)
|
|
|
}
|
|
|
@@ -82,8 +90,15 @@ func (c *GithubAppOAuthCallbackHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
},
|
|
|
))
|
|
|
|
|
|
- if session.Values["query_params"] != "" {
|
|
|
- http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
|
|
|
+ if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
|
|
|
+ // attempt to parse the redirect uri, if it fails just redirect to dashboard
|
|
|
+ redirectURI, err := url.Parse(redirectStr)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ http.Redirect(w, r, "/dashboard", 302)
|
|
|
+ }
|
|
|
+
|
|
|
+ http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
|
|
|
} else {
|
|
|
http.Redirect(w, r, "/dashboard", 302)
|
|
|
}
|