lib/api: http.Request.BasicAuth instead of custom code (#8039)
This commit is contained in:
+2
-20
@@ -7,9 +7,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -66,28 +64,12 @@ func basicAuthAndSessionMiddleware(cookieName string, guiCfg config.GUIConfigura
|
|||||||
http.Error(w, "Not Authorized", http.StatusUnauthorized)
|
http.Error(w, "Not Authorized", http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr := r.Header.Get("Authorization")
|
username, password, ok := r.BasicAuth()
|
||||||
if !strings.HasPrefix(hdr, "Basic ") {
|
if !ok {
|
||||||
error()
|
error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr = hdr[6:]
|
|
||||||
bs, err := base64.StdEncoding.DecodeString(hdr)
|
|
||||||
if err != nil {
|
|
||||||
error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fields := bytes.SplitN(bs, []byte(":"), 2)
|
|
||||||
if len(fields) != 2 {
|
|
||||||
error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
username := string(fields[0])
|
|
||||||
password := string(fields[1])
|
|
||||||
|
|
||||||
authOk := auth(username, password, guiCfg, ldapCfg)
|
authOk := auth(username, password, guiCfg, ldapCfg)
|
||||||
if !authOk {
|
if !authOk {
|
||||||
usernameIso := string(iso88591ToUTF8([]byte(username)))
|
usernameIso := string(iso88591ToUTF8([]byte(username)))
|
||||||
|
|||||||
Reference in New Issue
Block a user