mocksaml/pages/api/apps/index.ts

31 lines
817 B
TypeScript
Raw Normal View History

2022-01-13 18:13:25 +00:00
import { promises as fs } from 'fs';
2022-01-13 17:07:44 +00:00
import type { NextApiRequest, NextApiResponse } from 'next';
2022-01-13 18:13:25 +00:00
import path from 'path';
2022-01-13 17:50:16 +00:00
import { metadata } from '../../../services';
2022-01-13 17:07:44 +00:00
import type { App, IdPMetadata } from '../../../types';
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<App | App[] | IdPMetadata | null>
) {
if (req.method === 'POST') {
return await create(req);
}
async function create(req: NextApiRequest) {
const {
2022-01-13 17:50:16 +00:00
acs_url,
entity_id,
2022-01-13 17:07:44 +00:00
name = 'My App',
description = null,
} = req.body;
2022-01-13 18:13:25 +00:00
const certificateFilePath = path.join('data', 'x509cert.txt');
const certificate = await fs.readFile(certificateFilePath, 'utf8');
2022-01-13 17:07:44 +00:00
2022-01-13 17:50:16 +00:00
return res
.status(200)
.json(metadata.create(acs_url, entity_id, certificate));
2022-01-13 17:07:44 +00:00
}
}