parent
45e3260c1b
commit
feadffce44
11
package-lock.json
generated
11
package-lock.json
generated
@ -9,13 +9,12 @@
|
|||||||
"version": "1.3.6",
|
"version": "1.3.6",
|
||||||
"license": "Apache 2.0",
|
"license": "Apache 2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@boxyhq/saml20": "1.4.13",
|
"@boxyhq/saml20": "1.4.14",
|
||||||
"daisyui": "4.7.2",
|
"daisyui": "4.7.2",
|
||||||
"next": "14.1.3",
|
"next": "14.1.3",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-gtm-module": "2.0.11",
|
"react-gtm-module": "2.0.11"
|
||||||
"xmlbuilder": "15.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "20.11.25",
|
"@types/node": "20.11.25",
|
||||||
@ -248,9 +247,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@boxyhq/saml20": {
|
"node_modules/@boxyhq/saml20": {
|
||||||
"version": "1.4.13",
|
"version": "1.4.14",
|
||||||
"resolved": "https://registry.npmjs.org/@boxyhq/saml20/-/saml20-1.4.13.tgz",
|
"resolved": "https://registry.npmjs.org/@boxyhq/saml20/-/saml20-1.4.14.tgz",
|
||||||
"integrity": "sha512-ypj3/0pQqLGJxWtXjAr+sXcCNQz0DnMK00FTb3RUyTxFyksr8gVTO66cd+Qlu3rDzYLSEp+d6PLAGTb4ThTwkA==",
|
"integrity": "sha512-aLoCe6MTxoA65GXAXCZ+2bmZbb+9OZVUp7w0VbWlpFTcQpBOpKjkFnYqEfh3tkPZqDsFgjIESnBYfYDqbtPOvQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xmldom/xmldom": "0.8.10",
|
"@xmldom/xmldom": "0.8.10",
|
||||||
"xml-crypto": "6.0.0",
|
"xml-crypto": "6.0.0",
|
||||||
|
|||||||
@ -14,13 +14,12 @@
|
|||||||
"release": "git checkout release && git merge origin/main && release-it && git checkout main && git merge origin/release && git push origin main"
|
"release": "git checkout release && git merge origin/main && release-it && git checkout main && git merge origin/release && git push origin main"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@boxyhq/saml20": "1.4.13",
|
"@boxyhq/saml20": "1.4.14",
|
||||||
"daisyui": "4.7.2",
|
"daisyui": "4.7.2",
|
||||||
"next": "14.1.3",
|
"next": "14.1.3",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-gtm-module": "2.0.11",
|
"react-gtm-module": "2.0.11"
|
||||||
"xmlbuilder": "15.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "20.11.25",
|
"@types/node": "20.11.25",
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import saml from '@boxyhq/saml20';
|
|||||||
|
|
||||||
import config from 'lib/env';
|
import config from 'lib/env';
|
||||||
import type { IdPMetadata } from 'types';
|
import type { IdPMetadata } from 'types';
|
||||||
import { createIdPMetadataXML } from 'utils';
|
|
||||||
import stream from 'stream';
|
import stream from 'stream';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { getEntityId, getSSOUrl } from 'lib/entity-id';
|
import { getEntityId, getSSOUrl } from 'lib/entity-id';
|
||||||
@ -24,10 +23,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
|
|
||||||
const filename = 'mock-saml-metadata' + (req.query.namespace ? `-${req.query.namespace}` : '') + '.xml';
|
const filename = 'mock-saml-metadata' + (req.query.namespace ? `-${req.query.namespace}` : '') + '.xml';
|
||||||
|
|
||||||
const xml = await createIdPMetadataXML({
|
const xml = saml.createIdPMetadataXML({
|
||||||
idpEntityId: getEntityId(config.entityId, req.query.namespace as any),
|
entityId: getEntityId(config.entityId, req.query.namespace as any),
|
||||||
idpSsoUrl: getSSOUrl(config.appUrl, req.query.namespace as any),
|
ssoUrl: getSSOUrl(config.appUrl, req.query.namespace as any),
|
||||||
certificate: saml.stripCertHeaderAndFooter(config.publicKey),
|
x509cert: saml.stripCertHeaderAndFooter(config.publicKey),
|
||||||
|
wantAuthnRequestsSigned: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.setHeader('Content-type', 'text/xml');
|
res.setHeader('Content-type', 'text/xml');
|
||||||
|
|||||||
55
utils/idp.ts
55
utils/idp.ts
@ -1,55 +0,0 @@
|
|||||||
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 today = new Date();
|
|
||||||
const nodes = {
|
|
||||||
'md:EntityDescriptor': {
|
|
||||||
'@xmlns:md': 'urn:oasis:names:tc:SAML:2.0:metadata',
|
|
||||||
'@entityID': idpEntityId,
|
|
||||||
'@validUntil': new Date(today.setFullYear(today.getFullYear() + 10)).toISOString(),
|
|
||||||
'md:IDPSSODescriptor': {
|
|
||||||
'@WantAuthnRequestsSigned': true,
|
|
||||||
'@protocolSupportEnumeration': 'urn:oasis:names:tc:SAML:2.0:protocol',
|
|
||||||
'md:KeyDescriptor': {
|
|
||||||
'@use': 'signing',
|
|
||||||
'ds:KeyInfo': {
|
|
||||||
'@xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
|
||||||
'ds:X509Data': {
|
|
||||||
'ds:X509Certificate': {
|
|
||||||
'#text': certificate,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'md:NameIDFormat': {
|
|
||||||
'#text': 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
|
|
||||||
},
|
|
||||||
'md: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 };
|
|
||||||
@ -1,2 +1 @@
|
|||||||
export * from './certificate';
|
export * from './certificate';
|
||||||
export * from './idp';
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user