From 08a6336898d936b350e493819fe48519362cafbe Mon Sep 17 00:00:00 2001 From: Milo Schwartz Date: Fri, 25 Oct 2024 21:57:58 -0400 Subject: [PATCH] fix naming --- .traefik.yml | 4 ++-- README.md | 2 +- main.go | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.traefik.yml b/.traefik.yml index 70e0ae0..87b5f84 100644 --- a/.traefik.yml +++ b/.traefik.yml @@ -1,9 +1,9 @@ -displayName: badger +displayName: Fossorial Badger type: middleware import: github.com/fosrl/badger -summary: Middleware auth bouncer for Fossorial +summary: Middleware auth bouncer for Pangolin testData: apiBaseUrl: http://localhost:3001/api/v1 diff --git a/README.md b/README.md index d732979..d2678a7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # badger -Custom Traefik plugin middleware for auth +Middleware auth bouncer for Pangolin diff --git a/main.go b/main.go index c79c472..1c6e3bf 100644 --- a/main.go +++ b/main.go @@ -35,26 +35,21 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h } func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - // Check if the session cookie exists cookie, err := req.Cookie(SessionCookieName) if err != nil { - // No session cookie, redirect to login originalRequestURL := url.QueryEscape(req.URL.String()) http.Redirect(rw, req, fmt.Sprintf("%s/auth/login?redirect=%s", p.appBaseUrl, originalRequestURL), http.StatusFound) return } - // Verify the user with the session ID sessionID := cookie.Value verifyURL := fmt.Sprintf("%s/badger/verify-user?sessionId=%s", p.apiBaseUrl, sessionID) resp, err := http.Get(verifyURL) if err != nil || resp.StatusCode != http.StatusOK { - // If unauthorized (401), redirect to the homepage if resp != nil && resp.StatusCode == http.StatusUnauthorized { http.Redirect(rw, req, p.appBaseUrl, http.StatusFound) } else { - // Handle other errors, possibly log them (you can adjust the error handling here) http.Error(rw, "Internal Server Error", http.StatusInternalServerError) } return