diff --git a/handlers/api.go b/handlers/api.go index 9be32af0..a2d6e5fb 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -131,6 +131,7 @@ func sendUnauthorizedJson(w http.ResponseWriter, r *http.Request) { Status: "error", Error: errors.New("not authorized").Error(), } + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusUnauthorized) returnJson(output, w, r) } diff --git a/handlers/handlers.go b/handlers/handlers.go index 848c2cb3..4887889f 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -110,14 +110,14 @@ func IsReadAuthenticated(r *http.Request) bool { var token string query := r.URL.Query() key := query.Get("api") - if subtle.ConstantTimeCompare([]byte(key), []byte(core.CoreApp.ApiKey)) == 1 { + if subtle.ConstantTimeCompare([]byte(key), []byte(core.CoreApp.ApiSecret)) == 1 { return true } tokens, ok := r.Header["Authorization"] if ok && len(tokens) >= 1 { token = tokens[0] token = strings.TrimPrefix(token, "Bearer ") - if subtle.ConstantTimeCompare([]byte(token), []byte(core.CoreApp.ApiKey)) == 1 { + if subtle.ConstantTimeCompare([]byte(token), []byte(core.CoreApp.ApiSecret)) == 1 { return true } } @@ -144,7 +144,7 @@ func IsFullAuthenticated(r *http.Request) bool { if ok && len(tokens) >= 1 { token = tokens[0] token = strings.TrimPrefix(token, "Bearer ") - if subtle.ConstantTimeCompare([]byte(token), []byte(core.CoreApp.ApiKey)) == 1 { + if subtle.ConstantTimeCompare([]byte(token), []byte(core.CoreApp.ApiSecret)) == 1 { return true } } diff --git a/handlers/routes.go b/handlers/routes.go index c49ce59b..7770b0d6 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -103,14 +103,6 @@ func Router() *mux.Router { r.Handle("/group/{id}", sendLog(groupViewHandler)).Methods("GET") - // API GROUPS Routes - r.Handle("/api/groups", readOnly(apiAllGroupHandler, false)).Methods("GET") - r.Handle("/api/groups", authenticated(apiCreateGroupHandler, false)).Methods("POST") - r.Handle("/api/groups/{id}", readOnly(apiGroupHandler, false)).Methods("GET") - r.Handle("/api/groups/{id}", authenticated(apiGroupUpdateHandler, false)).Methods("POST") - r.Handle("/api/groups/{id}", authenticated(apiGroupDeleteHandler, false)).Methods("DELETE") - r.Handle("/api/reorder/groups", authenticated(apiGroupReorderHandler, false)).Methods("POST") - // API Routes r.Handle("/api", authenticated(apiIndexHandler, false)) r.Handle("/api/renew", authenticated(apiRenewHandler, false)) @@ -120,6 +112,14 @@ func Router() *mux.Router { r.Handle("/api/integrations/{name}", authenticated(apiIntegrationHandler, false)).Methods("GET") r.Handle("/api/integrations/{name}", authenticated(apiIntegrationHandler, false)).Methods("POST") + // API GROUPS Routes + r.Handle("/api/groups", readOnly(apiAllGroupHandler, false)).Methods("GET") + r.Handle("/api/groups", authenticated(apiCreateGroupHandler, false)).Methods("POST") + r.Handle("/api/groups/{id}", readOnly(apiGroupHandler, false)).Methods("GET") + r.Handle("/api/groups/{id}", authenticated(apiGroupUpdateHandler, false)).Methods("POST") + r.Handle("/api/groups/{id}", authenticated(apiGroupDeleteHandler, false)).Methods("DELETE") + r.Handle("/api/reorder/groups", authenticated(apiGroupReorderHandler, false)).Methods("POST") + // API SERVICE Routes r.Handle("/api/services", readOnly(apiAllServicesHandler, false)).Methods("GET") r.Handle("/api/services", authenticated(apiCreateServiceHandler, false)).Methods("POST") diff --git a/source/tmpl/settings.gohtml b/source/tmpl/settings.gohtml index 3d71df0c..0aaa2b6f 100644 --- a/source/tmpl/settings.gohtml +++ b/source/tmpl/settings.gohtml @@ -22,7 +22,7 @@ {{.Name}} {{end}} -