diff --git a/src/auth/api/http/auth.go b/src/auth/api/http/auth.go index a30487a6e..ec8265f77 100644 --- a/src/auth/api/http/auth.go +++ b/src/auth/api/http/auth.go @@ -1,7 +1,6 @@ package http import ( - "encoding/base64" "net/http" "strings" @@ -51,19 +50,19 @@ func (m *Auth) Middleware(next http.Handler) http.Handler { next.ServeHTTP(rw, r.WithContext(WithUserInfo(ctx, userInfo))) return case BasicSchema: - apiKey, err := base64.StdEncoding.DecodeString(authValue) - if err != nil { - httpinfra.WriteHTTPErrorResponse(rw, errors.InvalidFormatError(err.Error())) - return - } + _, apiKey, ok := r.BasicAuth() + if ok { + userInfo, err := m.authenticator.AuthenticateAPIKey(r.Context(), []byte(apiKey)) + if err != nil { + httpinfra.WriteHTTPErrorResponse(rw, err) + return + } - userInfo, err := m.authenticator.AuthenticateAPIKey(r.Context(), apiKey) - if err != nil { - httpinfra.WriteHTTPErrorResponse(rw, err) + next.ServeHTTP(rw, r.WithContext(WithUserInfo(ctx, userInfo))) return } - next.ServeHTTP(rw, r.WithContext(WithUserInfo(ctx, userInfo))) + httpinfra.WriteHTTPErrorResponse(rw, errors.InvalidFormatError("error parsing basic auth")) return default: httpinfra.WriteHTTPErrorResponse(rw, errors.InvalidFormatError("unsupported authorization schema %s", authSchema))