actor

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, a Actor) context.Context

Types

type Actor

type Actor interface {
	ID() string
	Type() Type
	DisplayName() string

	Email() string
	Subject() string
	ClientID() string
	Realm() string
	Roles() []string
	Scopes() []string
	Attrs() map[string]string
}

Actor represents the identity of a request initiator.

func FromContext

func FromContext(ctx context.Context) (Actor, bool)

func MustFromContext

func MustFromContext(ctx context.Context) Actor

MustFromContext panics if no actor in context — use only in trusted code paths.

type AnonymousActor

type AnonymousActor struct{}

func NewAnonymousActor

func NewAnonymousActor() *AnonymousActor

func (*AnonymousActor) Attrs

func (a *AnonymousActor) Attrs() map[string]string

func (*AnonymousActor) ClientID

func (a *AnonymousActor) ClientID() string

func (*AnonymousActor) DisplayName

func (a *AnonymousActor) DisplayName() string

func (*AnonymousActor) Email

func (a *AnonymousActor) Email() string

func (*AnonymousActor) ID

func (a *AnonymousActor) ID() string

func (*AnonymousActor) Realm

func (a *AnonymousActor) Realm() string

func (*AnonymousActor) Roles

func (a *AnonymousActor) Roles() []string

func (*AnonymousActor) Scopes

func (a *AnonymousActor) Scopes() []string

func (*AnonymousActor) Subject

func (a *AnonymousActor) Subject() string

func (*AnonymousActor) Type

func (a *AnonymousActor) Type() Type

type ServiceActor

type ServiceActor struct {
	// contains filtered or unexported fields
}

ServiceActor represents a service-to-service caller identity (machine principal). It is used when X-Principal-Type: service is injected by the gateway.

func NewServiceActor

func NewServiceActor(id, clientID, displayName string) *ServiceActor

NewServiceActor creates a ServiceActor.

func (*ServiceActor) Attrs

func (s *ServiceActor) Attrs() map[string]string

func (*ServiceActor) ClientID

func (s *ServiceActor) ClientID() string

func (*ServiceActor) DisplayName

func (s *ServiceActor) DisplayName() string

func (*ServiceActor) Email

func (s *ServiceActor) Email() string

func (*ServiceActor) ID

func (s *ServiceActor) ID() string

func (*ServiceActor) Realm

func (s *ServiceActor) Realm() string

func (*ServiceActor) Roles

func (s *ServiceActor) Roles() []string

func (*ServiceActor) Scopes

func (s *ServiceActor) Scopes() []string

func (*ServiceActor) SetRealm

func (s *ServiceActor) SetRealm(realm string)

func (*ServiceActor) SetScopes

func (s *ServiceActor) SetScopes(scopes []string)

func (*ServiceActor) Subject

func (s *ServiceActor) Subject() string

func (*ServiceActor) Type

func (s *ServiceActor) Type() Type

type SystemActor

type SystemActor struct {
	// contains filtered or unexported fields
}

func NewSystemActor

func NewSystemActor(id, serviceName string) *SystemActor

NewSystemActor creates a SystemActor. id is the fully-qualified OpenFGA principal (e.g. "system:my-service"). serviceName is the human-readable service name.

func (*SystemActor) Attrs

func (s *SystemActor) Attrs() map[string]string

func (*SystemActor) ClientID

func (s *SystemActor) ClientID() string

func (*SystemActor) DisplayName

func (s *SystemActor) DisplayName() string

func (*SystemActor) Email

func (s *SystemActor) Email() string

func (*SystemActor) ID

func (s *SystemActor) ID() string

func (*SystemActor) Realm

func (s *SystemActor) Realm() string

func (*SystemActor) Roles

func (s *SystemActor) Roles() []string

func (*SystemActor) Scopes

func (s *SystemActor) Scopes() []string

func (*SystemActor) ServiceName

func (s *SystemActor) ServiceName() string

func (*SystemActor) Subject

func (s *SystemActor) Subject() string

func (*SystemActor) Type

func (s *SystemActor) Type() Type

type Type

type Type string

Type identifies the kind of request initiator (generic identity, not domain model).

const (
	TypeUser      Type = "user"
	TypeSystem    Type = "system"
	TypeAnonymous Type = "anonymous"
	TypeService   Type = "service"
)

type UserActor

type UserActor struct {
	// contains filtered or unexported fields
}

UserActor is the concrete actor for an authenticated user.

func NewUserActor

func NewUserActor(p UserActorParams) *UserActor

NewUserActor creates a UserActor from params. All fields are optional except ID.

func (*UserActor) Attrs

func (u *UserActor) Attrs() map[string]string

func (*UserActor) ClientID

func (u *UserActor) ClientID() string

func (*UserActor) DisplayName

func (u *UserActor) DisplayName() string

func (*UserActor) Email

func (u *UserActor) Email() string

func (*UserActor) ID

func (u *UserActor) ID() string

func (*UserActor) Realm

func (u *UserActor) Realm() string

func (*UserActor) Roles

func (u *UserActor) Roles() []string

func (*UserActor) Scopes

func (u *UserActor) Scopes() []string

func (*UserActor) Subject

func (u *UserActor) Subject() string

func (*UserActor) Type

func (u *UserActor) Type() Type

type UserActorParams

type UserActorParams struct {
	ID          string
	DisplayName string
	Email       string
	Subject     string            // External IdP subject (Keycloak sub)
	ClientID    string            // OAuth2 client_id
	Realm       string            // IdP realm / tenant namespace
	Roles       []string          // Roles from token
	Scopes      []string          // OAuth2 scopes from token
	Attrs       map[string]string // Open extension bag
}

UserActorParams holds all fields for constructing a UserActor. New fields should be added here rather than extending the constructor signature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL