diff --git a/pkg/services/authn/clients/basic.go b/pkg/services/authn/clients/basic.go index 5e37640179e..d23b55f5285 100644 --- a/pkg/services/authn/clients/basic.go +++ b/pkg/services/authn/clients/basic.go @@ -2,10 +2,8 @@ package clients import ( "context" - "strings" "github.com/grafana/grafana/pkg/services/authn" - "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util/errutil" ) @@ -28,9 +26,9 @@ func (c *Basic) Name() string { } func (c *Basic) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) { - username, password, err := util.DecodeBasicAuthHeader(getBasicAuthHeaderFromRequest(r)) - if err != nil { - return nil, errDecodingBasicAuthHeader.Errorf("failed to decode basic auth header: %w", err) + username, password, ok := getBasicAuthFromRequest(r) + if !ok { + return nil, errDecodingBasicAuthHeader.Errorf("failed to decode basic auth header") } return c.client.AuthenticatePassword(ctx, r, username, password) @@ -45,22 +43,14 @@ func (c *Basic) Priority() uint { } func looksLikeBasicAuthRequest(r *authn.Request) bool { - return getBasicAuthHeaderFromRequest(r) != "" + _, _, ok := getBasicAuthFromRequest(r) + return ok } -func getBasicAuthHeaderFromRequest(r *authn.Request) string { +func getBasicAuthFromRequest(r *authn.Request) (string, string, bool) { if r.HTTPRequest == nil { - return "" + return "", "", false } - header := r.HTTPRequest.Header.Get(authorizationHeaderName) - if header == "" { - return "" - } - - if !strings.HasPrefix(header, basicPrefix) { - return "" - } - - return header + return r.HTTPRequest.BasicAuth() }