I Need to impliment the saml in my nodebb forum and i have created a plugin for that and im getting the response of the saml on my code but i'm not able to do the user login or signup with that, i have confussion on that what hook's or plugin i need to use to make that login or signup work. i'm also sharing my code so that you can help better. @baris @julian
router.post('/assert', async function (req, res) {
const decodedResponse = Buffer.from(req.body.SAMLResponse, 'base64').toString('utf-8');
const parser = new xml2js.Parser();
const saml_response = await parser.parseStringPromise(decodedResponse);
const issuer = saml_response['saml2p:Response']['saml2:Issuer'][0];
const assertion = saml_response['saml2p:Response']['saml2:Assertion'][0];
const subject = assertion['saml2:Subject'][0];
const nameId = subject['saml2:NameID'][0];
const existingUser = await User.getUidByEmail(nameId._);
if (existingUser) {
await authenticationController.onSuccessfulLogin(req, existingUser.uid);
return res.redirect('/home');
} else {
// Create a new user
const newUser = {
fullname: 'testfullname',
username: 'testfullname',
email: nameId._,
created_at: new Date(),
};
const result = await db.client.collection('objects').insertOne(newUser);
if (result.insertedId) {
await User.setUserField(result.insertedId, 'email', newUser.email);
// await UserEmail.confirmByUid(result.insertedId);
await authenticationController.onSuccessfulLogin(req, result.insertedId);
return res.redirect('/');
} else {
return res.status(500).send('Error creating new user.');
}
}
});