You are here

protected function JwtAuth::getJwtFromRequest in JSON Web Token Authentication (JWT) 8.0

Same name and namespace in other branches
  1. 8 src/Authentication/Provider/JwtAuth.php \Drupal\jwt\Authentication\Provider\JwtAuth::getJwtFromRequest()

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.

1 call to JwtAuth::getJwtFromRequest()
JwtAuth::authenticate in src/Authentication/Provider/JwtAuth.php
Authenticates the user.

File

src/Authentication/Provider/JwtAuth.php, line 114

Class

JwtAuth
JWT Authentication Provider.

Namespace

Drupal\jwt\Authentication\Provider

Code

protected function getJwtFromRequest(Request $request) {
  $auth_header = $request->headers
    ->get('Authorization');
  $matches = [];
  if (!($hasJWT = preg_match('/^Bearer (.*)/', $auth_header, $matches))) {
    return FALSE;
  }
  return $matches[1];
}