1
0

Removed unnecessary middleware for token-based auth from HTTP server.

This commit is contained in:
Alexander Andreev 2022-03-06 22:15:31 +04:00
parent 3eddc5f93e
commit 16df452105
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -2,8 +2,6 @@ package server
import ( import (
"context" "context"
"crypto/subtle"
"encoding/json"
"log" "log"
"net" "net"
"net/http" "net/http"
@ -87,19 +85,3 @@ func (s *HttpServer) Stop() error {
return nil return nil
} }
// AuthWithToken middleware that authenticates user by token (that is effectively just a password)
// supplied in an 'Authentication-Token' HTTP header.
func AuthWithToken(handler http.HandlerFunc, token string) http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) {
if subtle.ConstantTimeCompare([]byte(r.Header.Get("Authentication-Token")), []byte(token)) == 1 {
handler(rw, r)
} else {
rw.WriteHeader(http.StatusUnauthorized)
rw.Header().Add("Content-Type", "application/json")
response := make(map[string]string)
response["message"] = "Unauthorized"
json.NewEncoder(rw).Encode(response)
}
}
}