3
0
corteza/auth/http.go
Denis Arh d886a98740 Implements JWT authorization along with some refactoring
- introduces auth package, for common (sam, crm) auth handlers
 - routes are now generated inside server package, each handler got its own MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler)
 - there MountRoute methods are now called from non-generated code so we can inject services to (rest) controllers
2018-07-26 20:12:14 +02:00

21 lines
395 B
Go

package auth
import (
"errors"
"github.com/titpetric/factory/resputil"
"net/http"
)
func AuthenticationMiddlewareValidOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var ctx = r.Context()
if !GetIdentityFromContext(ctx).Valid() {
resputil.JSON(w, errors.New("Unauthorized"))
return
}
next.ServeHTTP(w, r)
})
}