Skip to content

Authorization Service

authorization_service

Inbound port for authorization and permission checking.

AuthorizationService

Bases: ABC

Abstract service that authorizes user actions.

Source code in src/forging_blocks/application/ports/inbound/authorization_service.py
class AuthorizationService(ABC):
    """Abstract service that authorizes user actions."""

    @abstractmethod
    async def check_permission(
        self,
        context: AuthorizationContext,
        permission: Permission,
    ) -> bool:
        """Evaluate whether *permission* is granted in *context*."""
        ...

    @abstractmethod
    async def check_resource_permission(
        self,
        context: AuthorizationContext,
        resource: str,
        action: str,
    ) -> bool:
        """Evaluate whether *action* on *resource* is permitted in *context*."""
        ...

    @abstractmethod
    async def get_user_permissions(self, user_id: str) -> list[Permission]:
        """Return the effective permissions for *user_id*."""
        ...

    @abstractmethod
    async def get_user_roles(self, user_id: str) -> list[str]:
        """Return the roles assigned to *user_id*."""
        ...

check_permission(context: AuthorizationContext, permission: Permission) -> bool abstractmethod async

Evaluate whether permission is granted in context.

Source code in src/forging_blocks/application/ports/inbound/authorization_service.py
@abstractmethod
async def check_permission(
    self,
    context: AuthorizationContext,
    permission: Permission,
) -> bool:
    """Evaluate whether *permission* is granted in *context*."""
    ...

check_resource_permission(context: AuthorizationContext, resource: str, action: str) -> bool abstractmethod async

Evaluate whether action on resource is permitted in context.

Source code in src/forging_blocks/application/ports/inbound/authorization_service.py
@abstractmethod
async def check_resource_permission(
    self,
    context: AuthorizationContext,
    resource: str,
    action: str,
) -> bool:
    """Evaluate whether *action* on *resource* is permitted in *context*."""
    ...

get_user_permissions(user_id: str) -> list[Permission] abstractmethod async

Return the effective permissions for user_id.

Source code in src/forging_blocks/application/ports/inbound/authorization_service.py
@abstractmethod
async def get_user_permissions(self, user_id: str) -> list[Permission]:
    """Return the effective permissions for *user_id*."""
    ...

get_user_roles(user_id: str) -> list[str] abstractmethod async

Return the roles assigned to user_id.

Source code in src/forging_blocks/application/ports/inbound/authorization_service.py
@abstractmethod
async def get_user_roles(self, user_id: str) -> list[str]:
    """Return the roles assigned to *user_id*."""
    ...