keyStorage = $keyStorage; return $this; } /** * @param array $allowedAlgorithms * @return $this */ public function setAllowedAlgorithms(array $allowedAlgorithms) { $this->allowedAlgorithms = $allowedAlgorithms; return $this; } public function showAction(Request $request, $token) { try { $token = \JWT::decode($token, $this->keyStorage, $this->allowedAlgorithms); } catch (\UnexpectedValueException $exception) { throw new NotFoundHttpException('Resource not found', $exception); } catch (\Exception $exception) { throw new BadRequestHttpException('Invalid token', $exception); } if (! isset($token->sdef) || !is_array($token->sdef) || count($token->sdef) !== 3) { throw new BadRequestHttpException('sdef should be a sub-definition identifier.'); } list ($sbas_id, $record_id, $subdef) = $token->sdef; try { $databox = $this->findDataboxById($sbas_id); $record = $databox->get_record($record_id); $subDefinition = $record->get_subdef($subdef); $permalink = $subDefinition->get_permalink(); } catch (\Exception $exception) { throw new NotFoundHttpException('Media was not found', $exception); } $subRequest = Request::create( (string) $permalink->get_url(), 'GET', [], $request->cookies->all(), [], $request->server->all() ); if ($request->query->has('download')) { $subRequest->query->set('download', $request->query->get('download')); } $response = $this->app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false); // Remove Caption link header as it contains permalink token. $response->headers->remove('link'); return $response; } }