Applied prettier
This commit is contained in:
parent
4f361d4a11
commit
cb8b857008
@ -1,6 +1,6 @@
|
||||
import "styles/globals.css";
|
||||
import type { AppProps } from "next/app";
|
||||
import Layout from "components/Layout";
|
||||
import 'styles/globals.css';
|
||||
import type { AppProps } from 'next/app';
|
||||
import Layout from 'components/Layout';
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
|
||||
@ -1,22 +1,18 @@
|
||||
import Document, { Html, Head, Main, NextScript } from "next/document";
|
||||
import Document, { Html, Head, Main, NextScript } from 'next/document';
|
||||
|
||||
class MyDocument extends Document {
|
||||
render() {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel='preconnect' href='https://fonts.googleapis.com' />
|
||||
<link rel='preconnect' href='https://fonts.gstatic.com' crossOrigin='true' />
|
||||
<link
|
||||
rel="preconnect"
|
||||
href="https://fonts.gstatic.com"
|
||||
crossOrigin="true"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;700;800&display=swap"
|
||||
rel="stylesheet"
|
||||
href='https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;700;800&display=swap'
|
||||
rel='stylesheet'
|
||||
/>
|
||||
</Head>
|
||||
<body className="theme-default">
|
||||
<body className='theme-default'>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
export async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") {
|
||||
res.status(200).json({ name: "John Doe" });
|
||||
if (req.method === 'POST') {
|
||||
res.status(200).json({ name: 'John Doe' });
|
||||
} else {
|
||||
res.status(405).send(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
import type { GetServerSideProps } from 'next';
|
||||
import React from "react";
|
||||
import { AuthNRequest } from '../../types'
|
||||
import { extractSAMLRequestAttributes, createResponseForm } from '../../utils'
|
||||
import React from 'react';
|
||||
import { AuthNRequest } from '../../types';
|
||||
import { extractSAMLRequestAttributes, createResponseForm } from '../../utils';
|
||||
|
||||
const ProcessRequest: React.FC<AuthNRequest> = ({relayState, samlRequest}) => {
|
||||
return (
|
||||
<div>Processing request</div>
|
||||
);
|
||||
}
|
||||
const ProcessRequest: React.FC<AuthNRequest> = ({ relayState, samlRequest }) => {
|
||||
return <div>Processing request</div>;
|
||||
};
|
||||
|
||||
export default ProcessRequest;
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ const fetchPublicKey = async (): Promise<string> => {
|
||||
|
||||
const fetchPrivateKey = async (): Promise<string> => {
|
||||
return await fs.readFile(path.join('data', 'key.pem'), 'ascii');
|
||||
}
|
||||
};
|
||||
|
||||
const stripCertHeaderAndFooter = (cert: string): string => {
|
||||
cert = cert.replace(/-+BEGIN CERTIFICATE-+\r?\n?/, '');
|
||||
@ -17,8 +17,4 @@ const stripCertHeaderAndFooter = (cert: string): string => {
|
||||
return cert;
|
||||
};
|
||||
|
||||
export {
|
||||
fetchPublicKey,
|
||||
fetchPrivateKey,
|
||||
stripCertHeaderAndFooter,
|
||||
}
|
||||
export { fetchPublicKey, fetchPrivateKey, stripCertHeaderAndFooter };
|
||||
|
||||
@ -13,7 +13,7 @@ const createIdPMetadataXML = async ({
|
||||
}): Promise<string> => {
|
||||
const xmlPath = path.join('data', 'idp-metadata.xml');
|
||||
const xml = await fs.readFile(xmlPath, 'utf8');
|
||||
certificate = stripCertHeaderAndFooter(certificate)
|
||||
certificate = stripCertHeaderAndFooter(certificate);
|
||||
|
||||
return xml
|
||||
.replace('idp_entity_id', idpEntityId)
|
||||
@ -21,6 +21,4 @@ const createIdPMetadataXML = async ({
|
||||
.replace(/idp_sso_url/g, idpSsoUrl);
|
||||
};
|
||||
|
||||
export {
|
||||
createIdPMetadataXML,
|
||||
}
|
||||
export { createIdPMetadataXML };
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import xml2js from "xml2js";
|
||||
import { promisify } from "util";
|
||||
import { inflateRaw } from "zlib";
|
||||
import xml2js from 'xml2js';
|
||||
import { promisify } from 'util';
|
||||
import { inflateRaw } from 'zlib';
|
||||
|
||||
const inflateRawAsync = promisify(inflateRaw);
|
||||
|
||||
@ -19,18 +19,16 @@ const parseXML = (xml: string): Promise<Record<string, any>> => {
|
||||
|
||||
// Parse SAMLRequest attributes
|
||||
const extractSAMLRequestAttributes = async (samlRequest: string) => {
|
||||
const request = (
|
||||
await inflateRawAsync(Buffer.from(samlRequest, "base64"))
|
||||
).toString();
|
||||
const request = (await inflateRawAsync(Buffer.from(samlRequest, 'base64'))).toString();
|
||||
const result = await parseXML(request);
|
||||
|
||||
const attributes = result["samlp:AuthnRequest"]["$"];
|
||||
const issuer = result["samlp:AuthnRequest"]["saml:Issuer"];
|
||||
const attributes = result['samlp:AuthnRequest']['$'];
|
||||
const issuer = result['samlp:AuthnRequest']['saml:Issuer'];
|
||||
return {
|
||||
id: attributes.ID,
|
||||
acsUrl: attributes.AssertionConsumerServiceURL,
|
||||
providerName: attributes.ProviderName,
|
||||
audience: issuer[0]["_"],
|
||||
audience: issuer[0]['_'],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -5,12 +5,12 @@ import { SignedXml, FileKeyInfo } from 'xml-crypto';
|
||||
import { pki, util, asn1 } from 'node-forge';
|
||||
|
||||
const createResponseXML = async (params: {
|
||||
idpIdentityId: string,
|
||||
audience: string,
|
||||
acsUrl: string,
|
||||
user: User
|
||||
idpIdentityId: string;
|
||||
audience: string;
|
||||
acsUrl: string;
|
||||
user: User;
|
||||
}): Promise<string> => {
|
||||
const {idpIdentityId, audience, acsUrl, user} = params;
|
||||
const { idpIdentityId, audience, acsUrl, user } = params;
|
||||
|
||||
const authDate = new Date();
|
||||
const authTimestamp = authDate.toISOString();
|
||||
@ -21,46 +21,46 @@ const createResponseXML = async (params: {
|
||||
authDate.setMinutes(authDate.getMinutes() + 10);
|
||||
const notAfter = authDate.toISOString();
|
||||
|
||||
const inResponseTo = '_1234'
|
||||
const inResponseTo = '_1234';
|
||||
const responseId = crypto.randomBytes(10).toString('hex');
|
||||
|
||||
const attributeStatement = {
|
||||
'@xmlns:xs': 'http://www.w3.org/2001/XMLSchema',
|
||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'saml:Attribute' : [
|
||||
'saml:Attribute': [
|
||||
{
|
||||
'@Name': 'id',
|
||||
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic',
|
||||
'saml:AttributeValue': {
|
||||
'#text': user.id,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
'@Name': 'email',
|
||||
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic',
|
||||
'saml:AttributeValue': {
|
||||
'#text': user.email,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
'@Name': 'firstName',
|
||||
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic',
|
||||
'saml:AttributeValue': {
|
||||
'#text': user.firstName,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
'@Name': 'lastName',
|
||||
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic',
|
||||
'saml:AttributeValue': {
|
||||
'#text': user.lastName,
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const nodes = {
|
||||
'samlp:Response':{
|
||||
'samlp:Response': {
|
||||
'@xmlns:samlp': 'urn:oasis:names:tc:SAML:2.0:protocol',
|
||||
'@Version': '2.0',
|
||||
'@ID': responseId,
|
||||
@ -69,8 +69,8 @@ const createResponseXML = async (params: {
|
||||
'@IssueInstant': authTimestamp,
|
||||
'samlp:Status': {
|
||||
'samlp:StatusCode': {
|
||||
'@Value': 'urn:oasis:names:tc:SAML:2.0:status:Success'
|
||||
}
|
||||
'@Value': 'urn:oasis:names:tc:SAML:2.0:status:Success',
|
||||
},
|
||||
},
|
||||
'saml:Issuer': {
|
||||
'@xmlns:saml': 'urn:oasis:names:tc:SAML:2.0:assertion',
|
||||
@ -88,7 +88,7 @@ const createResponseXML = async (params: {
|
||||
'saml:NameID': {
|
||||
'@Format': 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
|
||||
'#text': user.email,
|
||||
}
|
||||
},
|
||||
},
|
||||
'saml:Conditions': {
|
||||
'@NotBefore': notBefore,
|
||||
@ -96,24 +96,24 @@ const createResponseXML = async (params: {
|
||||
'saml:AudienceRestriction': {
|
||||
'saml:Audience': {
|
||||
'#text': audience,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
'saml:AuthnStatement': {
|
||||
'@AuthnInstant': authTimestamp,
|
||||
'@SessionIndex': '_YIlFoNFzLMDYxdwf-T_BuimfkGa5qhKg',
|
||||
'saml:AuthnContext': {
|
||||
'saml:AuthnContextClassRef': {
|
||||
'#text': 'urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified'
|
||||
}
|
||||
}
|
||||
'#text': 'urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified',
|
||||
},
|
||||
},
|
||||
},
|
||||
'saml:AttributeStatement': attributeStatement,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return xmlbuilder.create(nodes).end({ pretty: true});
|
||||
return xmlbuilder.create(nodes).end({ pretty: true });
|
||||
};
|
||||
|
||||
// Create the HTML form to submit the response
|
||||
@ -171,8 +171,10 @@ function GetKeyInfo(x509Certificate: string, signatureConfig: any = {}) {
|
||||
|
||||
const signResponseXML = async (xml: string, signingKey: any, publicKey: any): Promise<string> => {
|
||||
const sig = new SignedXml();
|
||||
const responseXPath = '/*[local-name(.)="Response" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]';
|
||||
const issuerXPath = '/*[local-name(.)="Issuer" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:assertion"]';
|
||||
const responseXPath =
|
||||
'/*[local-name(.)="Response" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]';
|
||||
const issuerXPath =
|
||||
'/*[local-name(.)="Issuer" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:assertion"]';
|
||||
|
||||
sig.signatureAlgorithm = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256';
|
||||
|
||||
@ -180,17 +182,17 @@ const signResponseXML = async (xml: string, signingKey: any, publicKey: any): Pr
|
||||
sig.keyInfoProvider = new GetKeyInfo(publicKey, {});
|
||||
sig.signingKey = signingKey;
|
||||
|
||||
sig.addReference(responseXPath, ['http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#'], 'http://www.w3.org/2001/04/xmlenc#sha256');
|
||||
sig.addReference(
|
||||
responseXPath,
|
||||
['http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#'],
|
||||
'http://www.w3.org/2001/04/xmlenc#sha256'
|
||||
);
|
||||
|
||||
sig.computeSignature(xml, {
|
||||
location: { reference: responseXPath + issuerXPath, action: 'after' },
|
||||
});
|
||||
|
||||
return sig.getSignedXml();
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
createResponseXML,
|
||||
createResponseForm,
|
||||
signResponseXML
|
||||
}
|
||||
export { createResponseXML, createResponseForm, signResponseXML };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user