mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* API: Add reqSignedIn to router groups * AuthN: Add fall through in context handler * AuthN: Add IsAnonymous field * AuthN: add priority to context aware clients * ContextHandler: Add comment * AuthN: Add a simple priority queue * AuthN: Add Name to client interface * AuthN: register clients with function * AuthN: update mock and fake to implement interface * AuthN: rewrite test without reflection * AuthN: add comment * AuthN: fix queue insert * AuthN: rewrite tests * AuthN: make the queue generic so we can reuse it for hooks * ContextHandler: Add fixme for auth headers * AuthN: remove unused variable * AuthN: use multierror * AuthN: write proper tests for queue * AuthN: Add queue item that can store the value and priority Co-authored-by: Jo <joao.guerreiro@grafana.com>
41 lines
978 B
Go
41 lines
978 B
Go
package clients
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/authn"
|
|
"github.com/grafana/grafana/pkg/util/errutil"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
var (
|
|
errBadForm = errutil.NewBase(errutil.StatusBadRequest, "form-auth.invalid", errutil.WithPublicMessage("bad login data"))
|
|
)
|
|
|
|
var _ authn.Client = new(Form)
|
|
|
|
func ProvideForm(client authn.PasswordClient) *Form {
|
|
return &Form{client}
|
|
}
|
|
|
|
type Form struct {
|
|
client authn.PasswordClient
|
|
}
|
|
|
|
type loginForm struct {
|
|
Username string `json:"user" binding:"Required"`
|
|
Password string `json:"password" binding:"Required"`
|
|
}
|
|
|
|
func (c *Form) Name() string {
|
|
return authn.ClientForm
|
|
}
|
|
|
|
func (c *Form) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
|
form := loginForm{}
|
|
if err := web.Bind(r.HTTPRequest, &form); err != nil {
|
|
return nil, errBadForm.Errorf("failed to parse request: %w", err)
|
|
}
|
|
return c.client.AuthenticatePassword(ctx, r, form.Username, form.Password)
|
|
}
|