MCPcopy Index your code
hub / github.com/1Panel-dev/KubePi / wrapBasicAuth

Method wrapBasicAuth

thirdparty/gotty/server/middleware.go:26–51  ·  view source on GitHub ↗
(handler http.Handler, credential string)

Source from the content-addressed store, hash-verified

24}
25
26func (server *Server) wrapBasicAuth(handler http.Handler, credential string) http.Handler {
27 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
28 token := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
29
30 if len(token) != 2 || strings.ToLower(token[0]) != "basic" {
31 w.Header().Set("WWW-Authenticate", `Basic realm="GoTTY"`)
32 http.Error(w, "Bad Request", http.StatusUnauthorized)
33 return
34 }
35
36 payload, err := base64.StdEncoding.DecodeString(token[1])
37 if err != nil {
38 http.Error(w, "Internal Server Error", http.StatusInternalServerError)
39 return
40 }
41
42 if credential != string(payload) {
43 w.Header().Set("WWW-Authenticate", `Basic realm="GoTTY"`)
44 http.Error(w, "authorization failed", http.StatusUnauthorized)
45 return
46 }
47
48 log.Printf("Basic Authentication Succeeded: %s", r.RemoteAddr)
49 handler.ServeHTTP(w, r)
50 })
51}

Callers 1

setupHandlersMethod · 0.95

Calls 3

ErrorMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected