tweaked firstName and lastName
This commit is contained in:
parent
b024b30f6e
commit
d1f6cba776
@ -6,32 +6,33 @@ import { createResponseForm, createResponseXML, signResponseXML } from 'utils';
|
|||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const email = req.body.email;
|
const { email, audience, acsUrl, id, relayState } = req.body;
|
||||||
|
|
||||||
if (!email.endsWith('@example.com') && !email.endsWith('@example.org')) {
|
if (!email.endsWith('@example.com') && !email.endsWith('@example.org')) {
|
||||||
res.status(403).send(`${email} denied access`);
|
res.status(403).send(`${email} denied access`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = createHash('sha256').update(email).digest('hex');
|
const userId = createHash('sha256').update(email).digest('hex');
|
||||||
|
const userName = email.split('@')[0];
|
||||||
|
|
||||||
const user: User = {
|
const user: User = {
|
||||||
id,
|
id: userId,
|
||||||
email,
|
email,
|
||||||
firstName: id,
|
firstName: userName,
|
||||||
lastName: id,
|
lastName: userName,
|
||||||
};
|
};
|
||||||
|
|
||||||
const xml = await createResponseXML({
|
const xml = await createResponseXML({
|
||||||
idpIdentityId: config.entityId,
|
idpIdentityId: config.entityId,
|
||||||
audience: req.body.audience,
|
audience,
|
||||||
acsUrl: req.body.acsUrl,
|
acsUrl,
|
||||||
samlReqId: req.body.id,
|
samlReqId: id,
|
||||||
user: user,
|
user: user,
|
||||||
});
|
});
|
||||||
|
|
||||||
const xmlSigned = await signResponseXML(xml, config.privateKey, config.publicKey);
|
const xmlSigned = await signResponseXML(xml, config.privateKey, config.publicKey);
|
||||||
const encodedSamlResponse = Buffer.from(xmlSigned).toString('base64');
|
const encodedSamlResponse = Buffer.from(xmlSigned).toString('base64');
|
||||||
const html = createResponseForm(req.body.relayState, encodedSamlResponse, req.body.acsUrl);
|
const html = createResponseForm(relayState, encodedSamlResponse, acsUrl);
|
||||||
|
|
||||||
res.send(html);
|
res.send(html);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user