Skip to content

Commit

Permalink
fix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Apr 28, 2021
1 parent dfcb2be commit 3078093
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/jwtauth/auth_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3078093

Please sign in to comment.