Redirect to login after req parsing
This commit is contained in:
parent
4022901ea9
commit
6f9bab1969
@ -1,9 +1,5 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { createResponseForm, createResponseXML, extractSAMLRequestAttributes } from 'utils';
|
import { extractSAMLRequestAttributes } from 'utils';
|
||||||
import { User } from 'types';
|
|
||||||
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<string>) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<string>) {
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
@ -16,32 +12,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
async function processSAMLRequest() {
|
async function processSAMLRequest() {
|
||||||
const relayState = <string>req.query.RelayState;
|
const relayState = <string>req.query.RelayState;
|
||||||
const samlRequest = <string>req.query.SAMLRequest;
|
const samlRequest = <string>req.query.SAMLRequest;
|
||||||
const { id, audience, acsUrl, providerName } = await extractSAMLRequestAttributes(samlRequest);
|
try {
|
||||||
|
const { id, audience, acsUrl, providerName } = await extractSAMLRequestAttributes(samlRequest);
|
||||||
|
const params = new URLSearchParams({ id, audience, acsUrl, providerName, relayState });
|
||||||
|
res.redirect(307, `/saml/login?${params.toString()}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).send(`Error parsing SAML request`);
|
||||||
|
}
|
||||||
|
|
||||||
const idpIdentityId = audience;
|
|
||||||
// const audience = config.entityId;
|
// const audience = config.entityId;
|
||||||
|
|
||||||
const user: User = {
|
|
||||||
id: '1',
|
|
||||||
email: 'kiran@boxyhq.com',
|
|
||||||
firstName: 'Kiran',
|
|
||||||
lastName: 'K',
|
|
||||||
};
|
|
||||||
|
|
||||||
const xml = await createResponseXML({
|
|
||||||
idpIdentityId: idpIdentityId,
|
|
||||||
audience: audience,
|
|
||||||
acsUrl: acsUrl,
|
|
||||||
user: user,
|
|
||||||
});
|
|
||||||
|
|
||||||
const signingKey = await fetchPrivateKey();
|
|
||||||
const publicKey = await fetchPublicKey();
|
|
||||||
const xmlSigned = await signResponseXML(xml, signingKey, publicKey);
|
|
||||||
const encodedSamlResponse = Buffer.from(xmlSigned).toString('base64');
|
|
||||||
|
|
||||||
const html = createResponseForm(relayState, encodedSamlResponse, acsUrl);
|
|
||||||
|
|
||||||
res.send(html);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user