Skip to content

Authorization Context

authorization_context

Authorization context bundled for a single authorization decision.

AuthorizationContext dataclass

Bundles the information needed for a single authorization decision.

Parameters:

Name Type Description Default
user_id str

The unique identifier of the user requesting access.

required
roles list[str] | None

Roles assigned to the user (e.g. ["admin", "editor"]).

None
resource_id str | None

Optional identifier of the resource being accessed.

None
resource_type str | None

Optional discriminator for the resource kind
(e.g. "document", "project").

None
action str | None

Optional name of the action being performed
(e.g. "publish", "archive").

None
metadata dict[str, Any] | None

Arbitrary key-value pairs that checkers may inspect.

None
Source code in src/forging_blocks/foundation/context/authorization_context.py
@auto_freeze
@dataclass(frozen=True)
class AuthorizationContext:
    """Bundles the information needed for a single authorization decision.

    Args:
        user_id: The unique identifier of the user requesting access.
        roles: Roles assigned to the user (e.g. ``["admin", "editor"]``).
        resource_id: Optional identifier of the resource being accessed.
        resource_type: Optional discriminator for the resource kind
            (e.g. ``"document"``, ``"project"``).
        action: Optional name of the action being performed
            (e.g. ``"publish"``, ``"archive"``).
        metadata: Arbitrary key-value pairs that checkers may inspect.
    """

    user_id: str
    roles: list[str] | None = None
    resource_id: str | None = None
    resource_type: str | None = None
    action: str | None = None
    metadata: dict[str, Any] | None = None