You are here

protected function TokenAuthentication::extractToken in RESTful 7.2

Extract the token from the request.

Parameters

RequestInterface $request: The request.

Return value

string The extracted token.

2 calls to TokenAuthentication::extractToken()
TokenAuthentication::applies in modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
Determines if the request can be checked for authentication. For example, when authenticating with HTTP header, return FALSE if the header values do not exist.
TokenAuthentication::authenticate in modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
Authenticate the request by trying to match a user.

File

modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php, line 85
Contains \Drupal\restful_token_auth\Plugin\authentication\TokenAuthentication

Class

TokenAuthentication
Class TokenAuthentication @package Drupal\restful\Plugin\authentication

Namespace

Drupal\restful_token_auth\Plugin\authentication

Code

protected function extractToken(RequestInterface $request) {
  $plugin_definition = $this
    ->getPluginDefinition();
  $options = $plugin_definition['options'];
  $key_name = !empty($options['paramName']) ? $options['paramName'] : 'access_token';

  // Access token may be on the request, or in the headers.
  $input = $request
    ->getParsedInput();

  // If we don't have a $key_name on either the URL or the in the headers,
  // then check again using a hyphen instead of an underscore. This is due to
  // new versions of Apache not accepting headers with underscores.
  if (empty($input[$key_name]) && !$request
    ->getHeaders()
    ->get($key_name)
    ->getValueString()) {
    $key_name = str_replace('_', '-', $key_name);
  }
  return empty($input[$key_name]) ? $request
    ->getHeaders()
    ->get($key_name)
    ->getValueString() : $input[$key_name];
}