From bafa13ea36576b49c8041fade3666ca5a710ae25 Mon Sep 17 00:00:00 2001 From: hunjixin <1084400399@qq.com> Date: Wed, 28 Apr 2021 17:30:30 +0800 Subject: [PATCH] fix auth --- pkg/jwtauth/auth_mux.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/jwtauth/auth_mux.go b/pkg/jwtauth/auth_mux.go index abf26eca2c..e692bcfb73 100644 --- a/pkg/jwtauth/auth_mux.go +++ b/pkg/jwtauth/auth_mux.go @@ -44,22 +44,22 @@ func (authMux *AuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { token = "Bearer " + token } } - if token != "" { - if !strings.HasPrefix(token, "Bearer ") { - log.Warn("missing Bearer prefix in venusauth header") - w.WriteHeader(401) - return - } - token = strings.TrimPrefix(token, "Bearer ") - res, err := authMux.jwtCli.Verify(r.Context(), util.MacAddr(), "venus", r.RemoteAddr, r.Host, token) - if err != nil { - log.Warnf("JWT Verification failed (originating from %s): %s", r.RemoteAddr, err) - w.WriteHeader(401) - return - } - ctx = auth.WithPerm(ctx, res) + if !strings.HasPrefix(token, "Bearer ") { + log.Warn("missing Bearer prefix in venusauth header") + w.WriteHeader(401) + return } + + token = strings.TrimPrefix(token, "Bearer ") + res, err := authMux.jwtCli.Verify(r.Context(), util.MacAddr(), "venus", r.RemoteAddr, r.Host, token) + if err != nil { + log.Warnf("JWT Verification failed (originating from %s): %s", r.RemoteAddr, err) + w.WriteHeader(401) + return + } + ctx = auth.WithPerm(ctx, res) + } *r = *(r.WithContext(ctx)) authMux.mux.ServeHTTP(w, r)