Split header by space
parent
f46fa6bacd
commit
21b45b4255
|
@ -99,18 +99,15 @@ func tokenAuthMiddleware(next http.Handler) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authHeaderParts := strings.Split(r.Header.Get("Authorization"), "")
|
logger.Debug("Checking bearer token")
|
||||||
switch {
|
authHeaderParts := strings.Split(r.Header.Get("Authorization"), " ")
|
||||||
case len(authHeaderParts) != 2:
|
if len(authHeaderParts) != 2 || authHeaderParts[0] != "Bearer" || authHeaderParts[1] != cfg.HatsToken {
|
||||||
case authHeaderParts[0] != "Bearer":
|
|
||||||
case authHeaderParts[1] != cfg.HatsToken:
|
|
||||||
logger.Warn("Unauthorized request", "method", r.Method, "path", r.URL.Path, "address", r.RemoteAddr)
|
logger.Warn("Unauthorized request", "method", r.Method, "path", r.URL.Path, "address", r.RemoteAddr)
|
||||||
http.Error(w, "Bearer authorization header doesn't match configured token", http.StatusUnauthorized)
|
http.Error(w, "Bearer authorization header doesn't match configured token", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
logger.Debug("Token valid")
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
}
|
}
|
||||||
|
logger.Debug("Token valid")
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue