2022-01-13 19:20:01 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
2022-01-14 19:55:28 +00:00
|
|
|
import { createCertificate, createIdPMetadataXML } from '../../../utils';
|
2022-01-13 19:20:01 +00:00
|
|
|
|
|
|
|
|
export default async function handler(
|
|
|
|
|
req: NextApiRequest,
|
|
|
|
|
res: NextApiResponse<any>
|
|
|
|
|
) {
|
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
|
return await download(req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function download(req: NextApiRequest) {
|
2022-01-14 19:55:28 +00:00
|
|
|
const { acs_url, sp_entity_id } = req.body;
|
2022-01-13 19:20:01 +00:00
|
|
|
|
2022-01-14 19:55:28 +00:00
|
|
|
const certificate = await createCertificate();
|
|
|
|
|
const idpEntityId = 'http://localhost:4000/sso';
|
|
|
|
|
const idpSsoUrl = 'http://localhost:4000/sso';
|
2022-01-13 19:20:01 +00:00
|
|
|
|
2022-01-14 19:55:28 +00:00
|
|
|
const xml = await createIdPMetadataXML({
|
|
|
|
|
idpEntityId,
|
|
|
|
|
idpSsoUrl,
|
|
|
|
|
certificate,
|
|
|
|
|
});
|
2022-01-13 19:20:01 +00:00
|
|
|
|
2022-01-13 19:42:17 +00:00
|
|
|
res.setHeader('Content-type', 'text/xml');
|
|
|
|
|
res.setHeader('Content-Disposition', 'attachment; filename="metadata.xml"');
|
2022-01-13 19:20:01 +00:00
|
|
|
|
2022-01-13 19:42:17 +00:00
|
|
|
return res.send(xml);
|
2022-01-13 19:20:01 +00:00
|
|
|
}
|
|
|
|
|
}
|