public static function JwtAuth::getJwtFromRequest in JSON Web Token Authentication (JWT) 8
Same name and namespace in other branches
- 8.0 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.
3 calls to JwtAuth::getJwtFromRequest()
- DisallowJwtAuthRequests::check in src/
PageCache/ DisallowJwtAuthRequests.php - Determines whether delivery of a cached page should be attempted.
- JwtAuth::applies in src/
Authentication/ Provider/ JwtAuth.php - Checks whether suitable authentication credentials are on the request.
- JwtAuth::authenticate in src/
Authentication/ Provider/ JwtAuth.php - Authenticates the user.
File
- src/
Authentication/ Provider/ JwtAuth.php, line 112
Class
- JwtAuth
- JWT Authentication Provider.
Namespace
Drupal\jwt\Authentication\ProviderCode
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('/^Bearer (.+)/', $value, $matches)) {
return $matches[1];
}
}
return FALSE;
}