public function determineAccessToken($headersOnly = false)
  {
    $header    = $this->getRequest()->header('Authorization');
    $accessToken = '';

    // Check for special case, because cURL sometimes does an
    // internal second request and doubles the authorization header,
    // which always resulted in an error.
    //
    // 1st request: Authorization: Bearer XXX
    // 2nd request: Authorization: Bearer XXX, Bearer XXX
    if (strpos($header, 'Bearer') !== false) {
      if (strpos($header, ',') !== false) {
        $headerPart = explode(',', $header);
        $accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $headerPart[0]));
      } else {
        $accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
      }

      $accessToken = ($accessToken === 'Bearer' or $accessToken === 'Basic') ? '' : $accessToken;
    }

    if ( ! empty($accessToken)) {
      return $accessToken;
    } elseif ($headersOnly === false) {
      $input = RequestFacade::all();
      if (array_key_exists($this->tokenKey, $input)) {
        $accessToken = $input[$this->tokenKey];
      }
      unset($input);
    }

    if (empty($accessToken)) {
      throw new InvalidAccessTokenException('Access token is missing');
    }

    return $accessToken;
  }