X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fapi%2FApiMiddleware.php;h=4120f7a9530d09ab252df836eeddb7aceea76b8b;hb=f9ff7f1b69f19b42569ffa67280807ba56f5d48a;hp=162e88e0bc06ea50a43e6cc1cc289212962b1edf;hpb=80677a23e2e10d78bc527e9754286787b453ce61;p=github%2Fshaarli%2FShaarli.git diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index 162e88e0..4120f7a9 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -1,9 +1,9 @@ getHeaderLine('jwt'); - if (empty($jwt)) { + if (! $request->hasHeader('Authorization')) { throw new ApiAuthorizationException('JWT token not provided'); } @@ -107,7 +106,13 @@ class ApiMiddleware throw new ApiAuthorizationException('Token secret must be set in Shaarli\'s administration'); } - ApiUtils::validateJwtToken($jwt, $this->conf->get('api.secret')); + $authorization = $request->getHeaderLine('Authorization'); + + if (! preg_match('/^Bearer (.*)/i', $authorization, $matches)) { + throw new ApiAuthorizationException('Invalid JWT header'); + } + + ApiUtils::validateJwtToken($matches[1], $this->conf->get('api.secret')); } /**