diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-07-14 01:24:40 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-07-14 01:24:40 +0100 |
| commit | 08a3fb8a2b0281c3c329b33215ec7f8866add606 (patch) | |
| tree | ff8a5413449ea198bc063bf0099fc025ea49c82b /web/command/middleware/authenticate.go | |
| parent | 684787bcb72aece2aa914597a3bc8788432e66f7 (diff) | |
Add authentication and ability to change host
Diffstat (limited to 'web/command/middleware/authenticate.go')
| -rw-r--r-- | web/command/middleware/authenticate.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/web/command/middleware/authenticate.go b/web/command/middleware/authenticate.go new file mode 100644 index 0000000..08e3552 --- /dev/null +++ b/web/command/middleware/authenticate.go @@ -0,0 +1,25 @@ +package middleware + +import ( + "net/http" + + "github.com/LMBishop/scrapbook/pkg/auth" +) + +func MustAuthenticate(authenticator *auth.Authenticator, next http.HandlerFunc) http.HandlerFunc { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + jwt, err := r.Cookie("session") + if err != nil { + http.Redirect(w, r, "/authenticate", 302) + return + } + + err = authenticator.VerifyJwt(jwt.Value) + if err != nil { + http.Redirect(w, r, "/authenticate", 302) + return + } + + next.ServeHTTP(w, r) + }) +} |
