API Services AuthorizationService - evansims/openfga-php GitHub Wiki

Service implementation for authorization operations. This service handles all authorization-related queries including permission checks, relationship expansions, and object/user listing. It delegates HTTP communication to the HttpServiceInterface and uses the Result pattern for consistent error handling. The service supports various consistency levels and contextual tuple evaluation for dynamic authorization scenarios. All operations are performed against a specific store and authorization model.

Table of Contents


Namespace

OpenFGA\Services


Source

View source code


Implements


Related Classes


Methods

batchCheck

public function batchCheck(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\AuthorizationModelInterface|string $model,
    OpenFGA\Models\Collections\BatchCheckItemsInterface $checks,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Performs multiple authorization checks in a single batch request. This method allows checking multiple user-object relationships simultaneously for better performance when multiple authorization decisions are needed. Each check in the batch has a correlation ID to map results back to the original requests.

View source


Parameters

Name Type Description
$store StoreInterface | string The store to check against
$model AuthorizationModelInterface | string The authorization model to use
$checks BatchCheckItemsInterface The batch check items with correlation IDs

Returns

FailureInterface | SuccessInterface — Success with BatchCheckResponse, or Failure with error details


check

public function check(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\AuthorizationModelInterface|string $model,
    OpenFGA\Models\TupleKeyInterface $tupleKey,
    ?bool $trace = NULL,
    ?object $context = NULL,
    ?OpenFGA\Models\Collections\TupleKeysInterface $contextualTuples = NULL,
    ?OpenFGA\Models\Enums\Consistency $consistency = NULL,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Checks if a user has a specific relationship with an object. This method verifies whether the specified user has the given relationship (like 'reader', 'writer', or 'owner') with the target object. It's the core operation for making authorization decisions in your application.

View source


Parameters

Name Type Description
$store StoreInterface | string The store to check against
$model AuthorizationModelInterface | string The authorization model to use
$tupleKey TupleKeyInterface The relationship to check
$trace bool | null Whether to include a trace in the response
$context object | null Additional context for the check
$contextualTuples TupleKeysInterface | null Additional tuples for contextual evaluation
$consistency Consistency | null Override the default consistency level

Returns

FailureInterface | SuccessInterface — Success with CheckResponse, or Failure with error details


expand

public function expand(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\TupleKeyInterface $tupleKey,
    ?OpenFGA\Models\AuthorizationModelInterface|string|null $model = NULL,
    ?OpenFGA\Models\Collections\TupleKeysInterface $contextualTuples = NULL,
    ?OpenFGA\Models\Enums\Consistency $consistency = NULL,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Expands a relationship tuple to show all users that have the relationship. This method recursively expands a relationship to reveal all users who have access through direct assignment, group membership, or computed relationships. It's useful for understanding why a user has a particular permission.

View source


Parameters

Name Type Description
$store StoreInterface | string The store containing the tuple
$tupleKey TupleKeyInterface The tuple to expand
$model AuthorizationModelInterface | null | string | null The authorization model to use
$contextualTuples TupleKeysInterface | null Additional tuples for contextual evaluation
$consistency Consistency | null Override the default consistency level

Returns

FailureInterface | SuccessInterface — Success with ExpandResponse, or Failure with error details


listObjects

public function listObjects(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\AuthorizationModelInterface|string $model,
    string $type,
    string $relation,
    string $user,
    ?object $context = NULL,
    ?OpenFGA\Models\Collections\TupleKeysInterface $contextualTuples = NULL,
    ?OpenFGA\Models\Enums\Consistency $consistency = NULL,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Lists objects that have a specific relationship with a user. This method finds all objects of a given type that the specified user has a particular relationship with. It's useful for building filtered lists based on user permissions (for example "show all documents the user can read").

View source


Parameters

Name Type Description
$store StoreInterface | string The store to query
$model AuthorizationModelInterface | string The authorization model to use
$type string The type of objects to list
$relation string The relationship to check
$user string The user to check relationships for
$context object | null Additional context for evaluation
$contextualTuples TupleKeysInterface | null Additional tuples for contextual evaluation
$consistency Consistency | null Override the default consistency level

Returns

FailureInterface | SuccessInterface — Success with ListObjectsResponse, or Failure with error details


listUsers

public function listUsers(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\AuthorizationModelInterface|string $model,
    string $object,
    string $relation,
    OpenFGA\Models\Collections\UserTypeFiltersInterface $userFilters,
    ?object $context = NULL,
    ?OpenFGA\Models\Collections\TupleKeysInterface $contextualTuples = NULL,
    ?OpenFGA\Models\Enums\Consistency $consistency = NULL,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Lists users that have a specific relationship with an object. This method finds all users (and optionally groups) that have a particular relationship with a specific object. It's useful for auditing access or building user interfaces that show who has permissions.

View source


Parameters

Name Type Description
$store StoreInterface | string The store to query
$model AuthorizationModelInterface | string The authorization model to use
$object string The object to check relationships for
$relation string The relationship to check
$userFilters UserTypeFiltersInterface Filters for user types to include
$context object | null Additional context for evaluation
$contextualTuples TupleKeysInterface | null Additional tuples for contextual evaluation
$consistency Consistency | null Override the default consistency level

Returns

FailureInterface | SuccessInterface — Success with ListUsersResponse, or Failure with error details


streamedListObjects

public function streamedListObjects(
    OpenFGA\Models\StoreInterface|string $store,
    OpenFGA\Models\AuthorizationModelInterface|string $model,
    string $type,
    string $relation,
    string $user,
    ?object $context = NULL,
    ?OpenFGA\Models\Collections\TupleKeysInterface $contextualTuples = NULL,
    ?OpenFGA\Models\Enums\Consistency $consistency = NULL,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface

Lists objects that a user has a specific relationship with using streaming. This method finds all objects of a given type where the specified user has the requested relationship, returning results as a stream for efficient processing of large datasets. The streaming approach is memory-efficient for large result sets.

View source


Parameters

Name Type Description
$store StoreInterface | string The store to query
$model AuthorizationModelInterface | string The authorization model to use
$type string The object type to filter by
$relation string The relationship to check
$user string The user to check relationships for
$context object | null Additional context for evaluation
$contextualTuples TupleKeysInterface | null Additional tuples for contextual evaluation
$consistency Consistency | null Override the default consistency level

Returns

FailureInterface | SuccessInterface — Success with Generator<StreamedListObjectsResponse>, or Failure with error details

⚠️ **GitHub.com Fallback** ⚠️