mocksaml/utils/idp.ts
Deepak Prabhakara 331c3cf318
Switch to saml20 (#21)
* Use boxyhq/saml20

* use sign from saml20

* cleaned up GetKeyInfo

* cleaned up getPublicKeyPemFromCertificate

* cleaned up node-forge

* use hasValidSignature from saml20

* cleanup and update saml20 to the beta version

* throw an error if signature is not valid

* updated saml20
2022-04-26 18:02:12 +01:00

55 lines
1.5 KiB
TypeScript

import xmlbuilder from 'xmlbuilder';
import saml from '@boxyhq/saml20';
const createIdPMetadataXML = async ({
idpEntityId,
idpSsoUrl,
certificate,
}: {
idpEntityId: string;
idpSsoUrl: string;
certificate: string;
}): Promise<string> => {
certificate = saml.stripCertHeaderAndFooter(certificate);
const nodes = {
EntityDescriptor: {
'@xmlns:md': 'urn:oasis:names:tc:SAML:2.0:metadata',
'@entityID': idpEntityId,
'@validUntil': '2026-06-22T18:39:53.000Z',
IDPSSODescriptor: {
'@WantAuthnRequestsSigned': false,
'@protocolSupportEnumeration': 'urn:oasis:names:tc:SAML:2.0:protocol',
KeyDescriptor: {
'@use': 'signing',
KeyInfo: {
'@xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
X509Data: {
X509Certificate: {
'#text': certificate,
},
},
},
},
NameIDFormat: {
'#text': 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
},
SingleSignOnService: [
{
'@Binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'@Location': idpSsoUrl,
},
{
'@Binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
'@Location': idpSsoUrl,
},
],
},
},
};
return xmlbuilder.create(nodes, { encoding: 'UTF-8', standalone: false }).end({ pretty: true });
};
export { createIdPMetadataXML };