mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AuthN: Use BasicAuth from http request (#62792)
AuthN: use BasicAuth from http request
This commit is contained in:
parent
48e0ab2142
commit
ad068ed533
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user