cleanup (#129)
This commit is contained in:
parent
07f1000329
commit
9db5fed873
@ -1,32 +0,0 @@
|
||||
import config from 'lib/env';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import stream from 'stream';
|
||||
import { IdPMetadata } from 'types';
|
||||
import { promisify } from 'util';
|
||||
import { createIdPMetadataXML } from 'utils';
|
||||
import saml from '@boxyhq/saml20';
|
||||
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<IdPMetadata | string>) {
|
||||
switch (req.method) {
|
||||
case 'GET':
|
||||
return await downloadMetadata();
|
||||
default:
|
||||
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
|
||||
// Download metadata
|
||||
async function downloadMetadata() {
|
||||
const xml = await createIdPMetadataXML({
|
||||
idpEntityId: config.entityId,
|
||||
idpSsoUrl: config.ssoUrl,
|
||||
certificate: saml.stripCertHeaderAndFooter(config.publicKey),
|
||||
});
|
||||
|
||||
res.setHeader('Content-type', 'text/xml');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=mock-saml-metadata.xml');
|
||||
|
||||
await pipeline(xml, res);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,10 @@ import saml from '@boxyhq/saml20';
|
||||
import config from 'lib/env';
|
||||
import type { IdPMetadata } from 'types';
|
||||
import { createIdPMetadataXML } from 'utils';
|
||||
import stream from 'stream';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<IdPMetadata | string>) {
|
||||
switch (req.method) {
|
||||
@ -15,6 +19,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
|
||||
// Metadata URL
|
||||
async function MetadataUrl() {
|
||||
const { download } = req.query as { download: any };
|
||||
|
||||
const xml = await createIdPMetadataXML({
|
||||
idpEntityId: config.entityId,
|
||||
idpSsoUrl: config.ssoUrl,
|
||||
@ -22,6 +28,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
});
|
||||
|
||||
res.setHeader('Content-type', 'text/xml');
|
||||
|
||||
if (download || download === '') {
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=mock-saml-metadata.xml');
|
||||
|
||||
await pipeline(xml, res);
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(xml);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ const Home: React.FC<{ metadata: IdPMetadata }> = ({ metadata }) => {
|
||||
</h1>
|
||||
<div className='flex flex-col justify-between space-y-5 md:flex-row md:space-y-0'>
|
||||
<div className='flex flex-col space-y-5 md:flex-row md:space-x-5 md:space-y-0'>
|
||||
<Link href='/api/saml/metadata/download' className='btn-primary btn-active btn'>
|
||||
<Link href='/api/saml/metadata?download=true' className='btn-primary btn-active btn'>
|
||||
<svg
|
||||
className='mr-1 inline-block h-6 w-6'
|
||||
fill='none'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user