From 4022901ea923900a2812ef29ea943ab3e52c2681 Mon Sep 17 00:00:00 2001 From: Aswin V Date: Tue, 22 Feb 2022 11:06:06 +0530 Subject: [PATCH] Add prettier config and format files --- .prettierrc.js | 11 +++++++++++ lib/env.ts | 2 +- pages/api/saml/auth.ts | 9 +++++++++ pages/api/saml/metadata/download.ts | 10 +++------- pages/api/saml/sso.ts | 12 ++++-------- utils/request.ts | 7 ++----- 6 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 .prettierrc.js create mode 100644 pages/api/saml/auth.ts diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..b28ecb7 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,11 @@ +module.exports = { + bracketSpacing: true, + bracketSameLine: true, + singleQuote: true, + jsxSingleQuote: true, + trailingComma: "es5", + semi: true, + printWidth: 110, + arrowParens: "always", + importOrderSeparation: true, +}; diff --git a/lib/env.ts b/lib/env.ts index 31ca913..ee2001f 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -6,4 +6,4 @@ export default { appUrl, entityId, ssoUrl, -}; \ No newline at end of file +}; diff --git a/pages/api/saml/auth.ts b/pages/api/saml/auth.ts new file mode 100644 index 0000000..67bf527 --- /dev/null +++ b/pages/api/saml/auth.ts @@ -0,0 +1,9 @@ +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" }); + } else { + res.status(405).send(`Method ${req.method} Not Allowed`); + } +} diff --git a/pages/api/saml/metadata/download.ts b/pages/api/saml/metadata/download.ts index beee0f3..2781017 100644 --- a/pages/api/saml/metadata/download.ts +++ b/pages/api/saml/metadata/download.ts @@ -3,15 +3,11 @@ import { fetchPublicKey, createIdPMetadataXML } from '../../../../utils'; import { IdPMetadata } from '../../../../types'; import stream from 'stream'; import { promisify } from 'util'; -import config from '../../../../lib/env' +import config from '../../../../lib/env'; const pipeline = promisify(stream.pipeline); -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - +export default async function handler(req: NextApiRequest, res: NextApiResponse) { switch (req.method) { case 'GET': return await downloadMetadata(); @@ -32,4 +28,4 @@ export default async function handler( await pipeline(xml, res); } -} \ No newline at end of file +} diff --git a/pages/api/saml/sso.ts b/pages/api/saml/sso.ts index c6149f4..f1a59b1 100644 --- a/pages/api/saml/sso.ts +++ b/pages/api/saml/sso.ts @@ -1,15 +1,11 @@ import type { NextApiRequest, NextApiResponse } from 'next'; -import { createResponseForm, createResponseXML } from 'utils'; +import { createResponseForm, createResponseXML, extractSAMLRequestAttributes } from 'utils'; import { User } from 'types'; -import config from '../../../lib/env' +import config from '../../../lib/env'; import { signResponseXML } from 'utils/response'; import { fetchPrivateKey, fetchPublicKey } from 'utils/certificate'; -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - +export default async function handler(req: NextApiRequest, res: NextApiResponse) { switch (req.method) { case 'GET': return await processSAMLRequest(); @@ -48,4 +44,4 @@ export default async function handler( res.send(html); } -} \ No newline at end of file +} diff --git a/utils/request.ts b/utils/request.ts index 2a44664..fd63f42 100644 --- a/utils/request.ts +++ b/utils/request.ts @@ -8,7 +8,7 @@ const inflateRawAsync = promisify(inflateRaw); const parseXML = (xml: string): Promise> => { return new Promise((resolve, reject) => { xml2js.parseString(xml, (err: Error, result: any) => { - if(err) { + if (err) { reject(err); } @@ -34,7 +34,4 @@ const extractSAMLRequestAttributes = async (samlRequest: string) => { }; }; - -export { - extractSAMLRequestAttributes, -} \ No newline at end of file +export { extractSAMLRequestAttributes };