class ApiKeyAuthenticationMiddleware (View source)

Authenticates API requests by the X-API-Key header and loads the key's user.

This middleware checks for API key in request headers and authenticates the user if the key is valid

Methods

__construct(ApiKeyService $apiKeyService, ConfigurationInterface $config)

No description

bool
process(Request $request)

Process the request

int
getAuthenticatedUserId(Request $request)

Get authenticated user ID from API key (stateless)

int|null
getAuthenticatedApiKeyId(Request $request)

Get the api_keys row id for the request's key (stateless), for audit logging.

getApiKeyScope(Request $request)

Get the permission scope of the request's API key (stateless)

Details

__construct(ApiKeyService $apiKeyService, ConfigurationInterface $config)

No description

Parameters

ApiKeyService $apiKeyService
ConfigurationInterface $config

bool process(Request $request)

Process the request

Parameters

Request $request

The HTTP request

Return Value

bool

True if authentication succeeded, false otherwise

int getAuthenticatedUserId(Request $request)

Get authenticated user ID from API key (stateless)

Parameters

Request $request

The HTTP request

Return Value

int

User ID or 0 if not authenticated

int|null getAuthenticatedApiKeyId(Request $request)

Get the api_keys row id for the request's key (stateless), for audit logging.

Parameters

Request $request

The HTTP request

Return Value

int|null

The key id, or null when no key is present/resolvable

ApiKeyScope|null getApiKeyScope(Request $request)

Get the permission scope of the request's API key (stateless)

Parameters

Request $request

The HTTP request

Return Value

ApiKeyScope|null

The scope, or null when no key is present/resolvable