You are here

public function ApiKeyAuth::getKey in Services API Key Authentication 2.0.x

Same name and namespace in other branches
  1. 8.2 src/Authentication/Provider/ApiKeyAuth.php \Drupal\services_api_key_auth\Authentication\Provider\ApiKeyAuth::getKey()
  2. 8 src/Authentication/Provider/ApiKeyAuth.php \Drupal\services_api_key_auth\Authentication\Provider\ApiKeyAuth::getKey()
  3. 3.0.x src/Authentication/Provider/ApiKeyAuth.php \Drupal\services_api_key_auth\Authentication\Provider\ApiKeyAuth::getKey()

Retrieve key from request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object that the service will respond to.

Return value

bool True if api key is present

2 calls to ApiKeyAuth::getKey()
ApiKeyAuth::applies in src/Authentication/Provider/ApiKeyAuth.php
Checks whether suitable authentication credentials are on the request.
ApiKeyAuth::authenticate in src/Authentication/Provider/ApiKeyAuth.php
Authenticates the user.

File

src/Authentication/Provider/ApiKeyAuth.php, line 110

Class

ApiKeyAuth
HTTP Basic authentication provider.

Namespace

Drupal\services_api_key_auth\Authentication\Provider

Code

public function getKey(Request $request) {

  // Exempt edit/delete form route.
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  if (strstr($route_name, 'entity.api_key')) {
    return FALSE;
  }
  $form_api_key = $request
    ->get('api_key');
  if (!empty($form_api_key)) {
    return $form_api_key;
  }
  $query_api_key = $request->query
    ->get('api_key');
  if (!empty($query_api_key)) {
    return $query_api_key;
  }
  $header_api_key = $request->headers
    ->get('apikey');
  if (!empty($header_api_key)) {
    return $header_api_key;
  }
  return FALSE;
}