Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotServiceActor = apperror.Authorization("This operation requires a service actor.") ErrNotAdminActor = apperror.Authorization("This operation requires an admin actor.") )
var Module = fx.Options( fx.Provide(fx.Annotate(NewTokenAuthorizer, fx.As(new(Authorizer)))), )
Module provides the TokenAuthorizer as the Authorizer contract.
Functions ¶
func ContextWithActor ¶
ContextWithActor returns a new context with the given Actor attached.
func ContextWithUser ¶
ContextWithUser returns a new context carrying the service's user entity. The auth middleware sets it after authentication; handlers read it with UserFromContext.
func UserFromContext ¶
UserFromContext returns the service's user entity from the context, or nil if none is present (e.g. service-account requests, or unauthenticated ones).
Types ¶
type Actor ¶
type Actor struct {
ID uuid.UUID
Type ActorType
ClientID string
Scopes []string
Permissions []string
IsAdmin bool
Locale string
}
Actor is the authenticated caller's security context passed into use cases. Populated by the interface layer (HTTP, Console, gRPC, etc.) after authentication.
Type distinguishes human users from automated service callers.
Scopes define what the credential is permitted to do. A standard interactive login carries broad default scopes (full access to own resources). A restricted credential carries only explicitly granted scopes.
Permissions define what the actor itself is permitted to do, regardless of the credential. Populated for user actors from the identity provider. Always empty for service actors.
IsAdmin is true when the actor holds the service-wide admin realm role. Locale is the user's preferred locale from the JWT locale claim (e.g. "en-US"). Empty for service actors.
func ActorFromContext ¶
ActorFromContext retrieves the authenticated Actor from the context, or returns nil if not present.
type Authorizer ¶
Authorizer handles application layer authorization: it checks whether the given actor holds all the required permissions.
type TokenAuthorizer ¶
type TokenAuthorizer struct{}
TokenAuthorizer authorizes tokens based on their scopes and permissions.
Permissions are fully-qualified, prefixed with the owning service: "assets:assets.write", "notifications:preferences.read". A scope or permission entry matches when it equals the permission itself, its admin-prefixed form ("admin:<permission>"), or a service-level wildcard ("<service>:*" / "admin:<service>:*").
func NewTokenAuthorizer ¶
func NewTokenAuthorizer() *TokenAuthorizer