You are here

public static function UsersJwtAuth::getJwtFromRequest in JSON Web Token Authentication (JWT) 8

Gets a raw JsonWebToken from the current request.

Parameters

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

Return value

string|bool Raw JWT String if on request, false if not.

3 calls to UsersJwtAuth::getJwtFromRequest()
UsersJwtAuth::applies in modules/users_jwt/src/Authentication/Provider/UsersJwtAuth.php
Checks whether suitable authentication credentials are on the request.
UsersJwtAuth::authenticate in modules/users_jwt/src/Authentication/Provider/UsersJwtAuth.php
Authenticates the user.
UsersJwtRequestPolicy::check in modules/users_jwt/src/PageCache/UsersJwtRequestPolicy.php
Determines whether delivery of a cached page should be attempted.

File

modules/users_jwt/src/Authentication/Provider/UsersJwtAuth.php, line 159

Class

UsersJwtAuth
Class UsersJwtAuth.

Namespace

Drupal\users_jwt\Authentication\Provider

Code

public static function getJwtFromRequest(Request $request) {
  $auth_headers = [];
  $auth = $request->headers
    ->get('Authorization');
  if ($auth) {
    $auth_headers[] = $auth;
  }

  // Check a second header used in combination with basic auth.
  $fallback = $request->headers
    ->get('JWT-Authorization');
  if ($fallback) {
    $auth_headers[] = $fallback;
  }
  foreach ($auth_headers as $value) {
    if (preg_match('/^UsersJwt (.+)/', $value, $matches)) {
      return $matches[1];
    }
  }
  return FALSE;
}