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
This commit is contained in:
Karl Persson
2022-12-02 15:10:03 +01:00
committed by GitHub
parent c52d4e2a64
commit 22be025284
12 changed files with 313 additions and 8 deletions
+41
View File
@@ -1,4 +1,45 @@
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,
}
}