Chore: Merge branch 'ogn-dev' into with-tun

This commit is contained in:
yaling888
2022-03-16 20:16:30 +08:00
74 changed files with 675 additions and 281 deletions

View File

@ -115,10 +115,10 @@ func authentication(next http.Handler) http.Handler {
}
header := r.Header.Get("Authorization")
text := strings.SplitN(header, " ", 2)
bearer, token, found := strings.Cut(header, " ")
hasInvalidHeader := text[0] != "Bearer"
hasInvalidSecret := len(text) != 2 || text[1] != serverSecret
hasInvalidHeader := bearer != "Bearer"
hasInvalidSecret := !found || token != serverSecret
if hasInvalidHeader || hasInvalidSecret {
render.Status(r, http.StatusUnauthorized)
render.JSON(w, r, ErrUnauthorized)