API Services AuthenticationService - evansims/openfga-php GitHub Wiki

Service implementation for managing authentication in OpenFGA operations. This service encapsulates all authentication-related logic, providing a clean abstraction over the underlying authentication strategies. It handles token management, authentication request flows, and integrates with telemetry for monitoring authentication performance and failures. The service supports multiple authentication strategies through the AuthenticationInterface, automatically handling token refresh and error recovery patterns. It provides consistent error handling and telemetry integration across all authentication operations.

Table of Contents


Namespace

OpenFGA\Services


Source

View source code


Implements


Related Classes


Methods

getAuthorizationHeader

public function getAuthorizationHeader(
    Psr\Http\Message\StreamFactoryInterface $streamFactory,
    ?callable $requestSender = NULL,
): ?string

Get the authorization header for API requests. Retrieves the current authorization header, automatically handling token refresh if the current token is expired or missing. This method encapsulates the complexity of different authentication flows and provides a simple interface for obtaining valid authorization credentials.

View source


Parameters

Name Type Description
$streamFactory StreamFactoryInterface Stream factory for building authentication requests
$requestSender callable | null

Returns

string | null — The authorization header value, or null if no authentication configured


sendAuthenticationRequest

public function sendAuthenticationRequest(
    OpenFGA\Network\RequestContext $context,
    callable $requestSender,
): Psr\Http\Message\ResponseInterface

Send an authentication request using a pre-built RequestContext. Handles the complete lifecycle of authentication requests, including request building, sending, response handling, and telemetry tracking. This method provides a centralized point for all authentication-related HTTP operations.

View source


Parameters

Name Type Description
$context RequestContext The authentication request context
$requestSender callable

Returns

Psr\Http\Message\ResponseInterface — The authentication response

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