foreach (['name', 'email', 'given_name', 'family_name', 'email_verified', 'gender'] as $field) { $builder->set($field, $user[$field]); } $builder->sign(new JWT\Signer\Rsa\Sha256(), $privateKey); $token = $builder->getToken(); return new Response($token, 200, ['Access-Control-Allow-Origin' => '*', 'Content-Type' => 'application/jwt']); }); $app->get('/images', function(Request $request) use($app, $images) { $image = $images->find()->sort(['date' => -1]); $images = []; while ($next = $image->getNext()) { $images[] = ImageData::fromDb($request, $next); } return new JsonResponse($images, 200, ['Access-Control-Allow-Origin' => '*']); }); $app->get('/files/{id}', function($id) use($app, $images, $gridfs) { $file = $gridfs->findOne(['_id' => new MongoId($id)]); if ($file === null) { throw new NotFoundHttpException('File not found'); } return new Response($file->getBytes(), 200, ['Content-type' => $file->file['contentType']]); });