Removed unnecessary middleware for token-based auth from HTTP server.
This commit is contained in:
parent
3eddc5f93e
commit
16df452105
@ -2,8 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -87,19 +85,3 @@ func (s *HttpServer) Stop() error {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user