Files
grafana/pkg/services/authn/authn.go
T
Karl Persson 22be025284 Auth: Add anonymous authn client (#59637)
* Authn: Add Client interface and Reqeust and Identity structures

* Authn: Implement Authenticate method in service

* Authn: Add tracing

* Authn: Add logger

* AuthN: Implement Anonymous client
2022-12-02 15:10:03 +01:00

46 lines
831 B
Go

package authn
import (
"context"
"net/http"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/user"
)
const (
ClientAnonymous = "auth.anonymous"
)
type Service interface {
Authenticate(ctx context.Context, client string, r *Request) (*Identity, error)
}
type Client interface {
Authenticate(ctx context.Context, r *Request) (*Identity, error)
}
type Request struct {
HTTPRequest *http.Request
}
type Identity struct {
OrgID int64
OrgName string
IsAnonymous bool
OrgRoles map[int64]org.RoleType
}
func (i *Identity) Role() org.RoleType {
return i.OrgRoles[i.OrgID]
}
func (i *Identity) SignedInUser() *user.SignedInUser {
return &user.SignedInUser{
OrgID: i.OrgID,
OrgName: i.OrgName,
OrgRole: i.Role(),
IsAnonymous: i.IsAnonymous,
}
}