go-zprox/internal/middleware/middleware.go
Zeev Diukman fbaf9393ea first
2025-03-02 16:14:03 +00:00

53 lines
1.5 KiB
Go

package middleware
// import (
// "net/http"
// "github.com/alexedwards/scs/v2"
// conf "zeevdiukman.com/zprox/internal/config"
// )
// // import (
// // "net/http"
// // )
// func Auth(c *conf.Config, sessionManager *scs.SessionManager) func(http.Handler) http.Handler {
// return func(next http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// accessToken := sessionManager.GetString(r.Context(), "access_token")
// // auth.SetAuthHeader(w, accessToken)
// loginPath := c.Auth.Prefix + c.Auth.LoginPath
// logoutPath := c.Auth.Prefix + c.Auth.LogoutPath
// if loginPath == r.URL.Path || logoutPath == r.URL.Path {
// next.ServeHTTP(w, r)
// return
// }
// tokenOk := Domain.IsAuthorizedJWT(accessToken)
// if tokenOk {
// next.ServeHTTP(w, r)
// } else {
// p := c.Auth
// http.Redirect(w, r, p.Prefix+p.LoginPath, http.StatusFound) // Redirect to login
// }
// })
// }
// }
// func Domain(next http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// // requestedPath := r.URL.Path
// // a := c.Auth
// // excludedPaths := []string{
// // a.Prefix + a.LoginPath,
// // a.Prefix + a.CallbackPath,
// // a.Prefix + a.LogoutPath,
// // }
// // contains := helper.IsSliceContains(excludedPaths, requestedPath)
// // if !contains {
// // sessionManager.Put(r.Context(), "original_path", requestedPath)
// // }
// next.ServeHTTP(w, r)
// })
// }