Move /waygate/authorized into waygate library

This commit is contained in:
Anders Pitman
2022-03-08 11:23:19 -07:00
parent 42cbf1abe2
commit 951fa52c81
2 changed files with 0 additions and 67 deletions

View File

@@ -211,13 +211,6 @@ func Listen() {
tlsListener := tls.NewListener(httpListener, tlsConfig)
http.Handle("/waygate/", http.StripPrefix("/waygate", waygateServer))
// TODO: This feels like a bit of a hack.
//http.HandleFunc("/waygate/authorize", func(w http.ResponseWriter, r *http.Request) {
// webUiHandler.handleWebUiRequest(w, r)
//})
http.HandleFunc("/waygate/authorized", func(w http.ResponseWriter, r *http.Request) {
webUiHandler.handleWebUiRequest(w, r)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
timestamp := time.Now().Format(time.RFC3339)

View File

@@ -14,8 +14,6 @@ import (
"strings"
"sync"
"time"
"github.com/takingnames/waygate-go"
)
//go:embed logo.png templates
@@ -107,64 +105,6 @@ func (h *WebUiHandler) handleWebUiRequest(w http.ResponseWriter, r *http.Request
}
switch r.URL.Path {
case "/waygate/authorized":
if r.Method != "POST" {
w.WriteHeader(405)
io.WriteString(w, "Invalid method")
return
}
r.ParseForm()
authReq, err := waygate.ExtractAuthRequest(r)
if err != nil {
w.WriteHeader(400)
io.WriteString(w, err.Error())
return
}
domain := r.Form.Get("domain")
host := r.Form.Get("host")
fqdn := fmt.Sprintf("%s.%s", host, domain)
fmt.Println(fqdn)
waygateId, err := h.db.AddWaygate([]string{fqdn})
if err != nil {
w.WriteHeader(500)
h.alertDialog(w, r, err.Error(), "/")
return
}
waygateToken, err := h.db.AddWaygateToken(waygateId)
if err != nil {
w.WriteHeader(500)
h.alertDialog(w, r, err.Error(), "/")
return
}
if authReq.RedirectUri == "urn:ietf:wg:oauth:2.0:oob" {
fmt.Fprintf(w, waygateToken)
} else {
code, err := genRandomCode(32)
if err != nil {
w.WriteHeader(500)
h.alertDialog(w, r, err.Error(), "/")
return
}
err = h.db.SetTokenCode(waygateToken, code)
if err != nil {
w.WriteHeader(500)
h.alertDialog(w, r, err.Error(), "/")
return
}
url := fmt.Sprintf("http://%s?code=%s&state=%s", authReq.RedirectUri, code, authReq.State)
http.Redirect(w, r, url, 303)
}
return
case "/login":
h.handleLogin(w, r)
case "/users":