checkAuthorization($request); $resolve($next($request)); } ); } /** * * * @param ServerRequestInterface $request * @return ServerRequestInterface */ private function checkAuthorization(ServerRequestInterface $request): ServerRequestInterface { $authorization = $request->getHeaderLine('authorization'); if (str_starts_with(strtolower($authorization), "bearer ")) { $jwt = substr($authorization, strpos($authorization, " ")+1); $key = new JWTPlaintextKey($this->config->getJwtSecret()); $tok = new JWTToken($key, $jwt); if (!$tok->isValid()) { throw new SecurityException(message:"Invalid token", code:SecurityException::ERR_ACCESS_DENIED); } $mercureClaims = $tok->claims->get('mercure'); return $request ->withAttribute('authorization', $tok); } else { return $request ->withAttribute('authorization', null); } } }