1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-10-18 07:34:22 +00:00

Add default page in case neither redirect was specified

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-04-21 19:11:39 +02:00
parent 42db8e247d
commit 8d968ce29d
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

24
main.go
View file

@ -8,6 +8,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"strings"
"syscall" "syscall"
"github.com/flosch/pongo2" "github.com/flosch/pongo2"
@ -76,6 +77,7 @@ func init() {
mainCfg.Cookie.Expire = 3600 mainCfg.Cookie.Expire = 3600
mainCfg.Listen.Addr = "127.0.0.1" mainCfg.Listen.Addr = "127.0.0.1"
mainCfg.Listen.Port = 8082 mainCfg.Listen.Port = 8082
mainCfg.Login.DefaultRedirect = "debug"
mainCfg.AuditLog.TrustedIPHeaders = []string{"X-Forwarded-For", "RemoteAddr", "X-Real-IP"} mainCfg.AuditLog.TrustedIPHeaders = []string{"X-Forwarded-For", "RemoteAddr", "X-Real-IP"}
mainCfg.AuditLog.Headers = []string{"x-origin-uri"} mainCfg.AuditLog.Headers = []string{"x-origin-uri"}
} }
@ -117,6 +119,7 @@ func main() {
http.HandleFunc("/", handleRootRequest) http.HandleFunc("/", handleRootRequest)
http.HandleFunc("/auth", handleAuthRequest) http.HandleFunc("/auth", handleAuthRequest)
http.HandleFunc("/debug", handleLoginDebug)
http.HandleFunc("/login", handleLoginRequest) http.HandleFunc("/login", handleLoginRequest)
http.HandleFunc("/logout", handleLogoutRequest) http.HandleFunc("/logout", handleLogoutRequest)
@ -271,3 +274,24 @@ func handleLogoutRequest(res http.ResponseWriter, r *http.Request) {
http.Redirect(res, r, redirURL, http.StatusFound) http.Redirect(res, r, redirURL, http.StatusFound)
} }
func handleLoginDebug(w http.ResponseWriter, r *http.Request) {
user, groups, err := detectUser(w, r)
switch err {
case nil:
// All fine
case plugins.ErrNoValidUserFound:
http.Redirect(w, r, "login", http.StatusFound)
return
default:
log.WithError(err).Error("Failed to get user for login debug")
http.Error(w, "Something went wrong", http.StatusInternalServerError)
}
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "Successfully logged in:")
fmt.Fprintf(w, "- Username: %s\n", user)
fmt.Fprintf(w, "- Groups: %s\n", strings.Join(groups, ","))
}