2022-02-21 16:23:43 +00:00
|
|
|
import { promises as fs } from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { stripCertHeaderAndFooter } from './certificate';
|
|
|
|
|
|
|
|
|
|
const createIdPMetadataXML = async ({
|
|
|
|
|
idpEntityId,
|
|
|
|
|
idpSsoUrl,
|
|
|
|
|
certificate,
|
|
|
|
|
}: {
|
|
|
|
|
idpEntityId: string;
|
|
|
|
|
idpSsoUrl: string;
|
|
|
|
|
certificate: string;
|
|
|
|
|
}): Promise<string> => {
|
|
|
|
|
const xmlPath = path.join('data', 'idp-metadata.xml');
|
|
|
|
|
const xml = await fs.readFile(xmlPath, 'utf8');
|
2022-02-22 06:14:12 +00:00
|
|
|
certificate = stripCertHeaderAndFooter(certificate);
|
2022-02-21 16:23:43 +00:00
|
|
|
|
|
|
|
|
return xml
|
2022-02-23 23:30:02 +00:00
|
|
|
.replace('{{idp_entity_id}}', idpEntityId)
|
|
|
|
|
.replace('{{idp_certificate}}', certificate)
|
|
|
|
|
.replace(/{{idp_sso_url}}/g, idpSsoUrl);
|
2022-02-21 16:23:43 +00:00
|
|
|
};
|
|
|
|
|
|
2022-02-22 06:14:12 +00:00
|
|
|
export { createIdPMetadataXML };
|