Skip to content

Commit 5777f65

Browse files
utkarshcmutorkelo
authored andcommitted
Basic Auth now supports LDAP username and password (grafana#6940)
1 parent 0841e84 commit 5777f65

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/sources/http_api/auth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Currently you can authenticate via an `API Token` or via a `Session cookie` (acq
1818
## Basic Auth
1919

2020
If basic auth is enabled (it is enabled by default) you can authenticate your HTTP request via
21-
standard basic auth.
21+
standard basic auth. Basic auth will also authenticate LDAP users.
2222

2323
curl example:
2424
```

pkg/middleware/middleware.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/grafana/grafana/pkg/bus"
1010
"github.com/grafana/grafana/pkg/components/apikeygen"
1111
"github.com/grafana/grafana/pkg/log"
12+
l "github.com/grafana/grafana/pkg/login"
1213
"github.com/grafana/grafana/pkg/metrics"
1314
m "github.com/grafana/grafana/pkg/models"
1415
"github.com/grafana/grafana/pkg/setting"
@@ -137,6 +138,7 @@ func initContextWithApiKey(ctx *Context) bool {
137138
}
138139

139140
func initContextWithBasicAuth(ctx *Context) bool {
141+
140142
if !setting.BasicAuthEnabled {
141143
return false
142144
}
@@ -160,9 +162,9 @@ func initContextWithBasicAuth(ctx *Context) bool {
160162

161163
user := loginQuery.Result
162164

163-
// validate password
164-
if util.EncodePassword(password, user.Salt) != user.Password {
165-
ctx.JsonApiErr(401, "Invalid username or password", nil)
165+
loginUserQuery := l.LoginUserQuery{Username: username, Password: password, User: user}
166+
if err := bus.Dispatch(&loginUserQuery); err != nil {
167+
ctx.JsonApiErr(401, "Invalid username or password", err)
166168
return true
167169
}
168170

0 commit comments

Comments
 (0)