3
0
Files
corteza/auth/middleware.go
2018-09-04 15:37:43 +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)
})
}