Skip to content

Commit

Permalink
Wait for target to become available
Browse files Browse the repository at this point in the history
Escape clientId in callback
Set cookie on escaped path
  • Loading branch information
bruwozniak committed Jun 24, 2021
1 parent 213aedf commit ab22139
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/gorilla/securecookie"
)
Expand Down Expand Up @@ -107,6 +108,8 @@ func handleCallback(w http.ResponseWriter, r *http.Request) {
HttpOnly: true,
}
http.SetCookie(w, cookie)
cookie.Path = strings.Replace(servicePrefix, "@", "%40", -1)
http.SetCookie(w, cookie)
http.Redirect(w, r, servicePrefix, http.StatusFound)
} else {
log.Println(err)
Expand All @@ -125,7 +128,7 @@ func (ah JHOAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else {
cookie := http.Cookie{Name: "jh-proxy-auth-state", Value: r.URL.String(), MaxAge: 600, Path: servicePrefix}
http.SetCookie(w, &cookie)
params := fmt.Sprintf("?client_id=%s&redirect_uri=%s&response_type=code&state=", clientId, url.QueryEscape(callbackUrl))
params := fmt.Sprintf("?client_id=%s&redirect_uri=%s&response_type=code&state=", url.QueryEscape(clientId), url.QueryEscape(callbackUrl))
http.Redirect(w, r, "/hub/api/oauth2/authorize"+params, http.StatusFound)
}
}
Expand Down Expand Up @@ -153,6 +156,16 @@ func main() {
handler := JHOAuthHandler{
wrappedHandler: newPathTrimmingReverseProxy(backend),
}

// wait until target is reachable
for {
res, err := http.Get(backend.String())
if err == nil && res.StatusCode == 200 {
break
}
time.Sleep(1 * time.Second)
}

err = http.ListenAndServe(":"+*port, handler)
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit ab22139

Please sign in to comment.