You are here

public function JwtPathAuth::applies in JSON Web Token Authentication (JWT) 8

Checks whether suitable authentication credentials are on the request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

bool TRUE if authentication credentials suitable for this provider are on the request, FALSE otherwise.

Overrides AuthenticationProviderInterface::applies

File

modules/jwt_path_auth/src/Authentication/Provider/JwtPathAuth.php, line 73

Class

JwtPathAuth
JWT Authentication Provider.

Namespace

Drupal\jwt_path_auth\Authentication\Provider

Code

public function applies(Request $request) {
  $raw_jwt = $request->query
    ->get('jwt');
  if (empty($raw_jwt)) {
    return FALSE;
  }
  $config = $this->configFactory
    ->get('jwt_path_auth.config');
  $allowed_path_prefixes = (array) $config
    ->get('allowed_path_prefixes');
  $path_matched = FALSE;
  $request_path = $request
    ->getPathInfo();
  foreach ($allowed_path_prefixes as $prefix) {
    if (strpos($request_path, $prefix) === 0) {
      $path_matched = TRUE;
      break;
    }
  }
  return $path_matched;
}