Skip to content
Snippets Groups Projects
Commit c628755c authored by Christian Pointner's avatar Christian Pointner
Browse files

added auth backends listing

parent 4c07de52
No related branches found
No related tags found
No related merge requests found
......@@ -64,14 +64,17 @@ func login(w http.ResponseWriter, r *http.Request) {
switch strings.ToLower(backend) {
case "oidc":
if auth.oidc == nil {
sendHTTPResponse(w, http.StatusBadRequest, HTTPResponse{Error: "OIDC authentication is not configured"})
resp := HTTPResponse{Error: "OIDC authentication is not configured"}
sendHTTPResponse(w, http.StatusBadRequest, resp)
return
}
auth.oidc.HandleLogin(w, r)
case "":
sendHTTPResponse(w, http.StatusNotImplemented, HTTPResponse{Error: "default/fallback authentication backend has not been implemented yet"})
resp := HTTPResponse{Error: "default/fallback authentication backend has not been implemented yet"}
sendHTTPResponse(w, http.StatusNotImplemented, resp)
default:
sendHTTPResponse(w, http.StatusBadRequest, HTTPResponse{Error: "invalid authentication backend: " + backend})
resp := HTTPResponse{Error: "invalid authentication backend: " + backend}
sendHTTPResponse(w, http.StatusBadRequest, resp)
}
}
......@@ -98,6 +101,25 @@ func whoami(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(s)
}
type AuthBackendInfo struct {
Name string
Description string
}
func listBackends(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
backends := []AuthBackendInfo{}
if auth.oidc != nil {
backend := AuthBackendInfo{Name: "oidc"}
backend.Description = "OpenID Connect using Identity Provider: " + auth.config.OIDC.IssuerURL
backends = append(backends, backend)
}
json.NewEncoder(w).Encode(backends)
}
func disabled(w http.ResponseWriter, r *http.Request) {
sendHTTPResponse(w, http.StatusBadRequest, HTTPResponse{Error: "authentication is disabled"})
}
......@@ -111,6 +133,7 @@ func InstallHTTPHandler(r *mux.Router) {
r.HandleFunc("/login", login)
r.HandleFunc("/logout", logout)
r.HandleFunc("/whoami", whoami)
r.HandleFunc("/backends", listBackends)
if auth.oidc != nil {
r.Handle("/oidc/callback", auth.oidc.CallbackHandler())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment