mocksaml/pages/api/saml/metadata/index.ts
Kiran K c5ab7761d1
Download metadata url (#91)
* Bump eslint from 8.23.1 to 8.24.0

Bumps [eslint](https://github.com/eslint/eslint) from 8.23.1 to 8.24.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.23.1...v8.24.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump next from 12.3.0 to 12.3.1

Bumps [next](https://github.com/vercel/next.js) from 12.3.0 to 12.3.1.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](https://github.com/vercel/next.js/compare/v12.3.0...v12.3.1)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Add Download Metadata URL

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-25 17:38:56 +01:00

28 lines
796 B
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next';
import saml from '@boxyhq/saml20';
import config from 'lib/env';
import type { IdPMetadata } from 'types';
import { createIdPMetadataXML } from 'utils';
export default async function handler(req: NextApiRequest, res: NextApiResponse<IdPMetadata | string>) {
switch (req.method) {
case 'GET':
return await MetadataUrl();
default:
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
// Metadata URL
async function MetadataUrl() {
const xml = await createIdPMetadataXML({
idpEntityId: config.entityId,
idpSsoUrl: config.ssoUrl,
certificate: saml.stripCertHeaderAndFooter(config.publicKey),
});
res.setHeader('Content-type', 'text/xml');
res.send(xml);
}
}