fix naming

This commit is contained in:
Milo Schwartz 2024-10-25 21:57:58 -04:00
parent 387ce901b9
commit 08a6336898
No known key found for this signature in database
3 changed files with 3 additions and 8 deletions

View file

@ -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

View file

@ -1,3 +1,3 @@
# badger
Custom Traefik plugin middleware for auth
Middleware auth bouncer for Pangolin

View file

@ -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