Skip to content

Commit

Permalink
add custom login fcn
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Jan 16, 2024
1 parent ba3adc5 commit 450f7e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const fileHandlers = require('./handlers/fileHandlers.js');
const sanitizeBody = require('./handlers/sanitizeHandler.js');
const DataTransformationHandler = require('./handlers/dataTransformationHandler.js');
const envEcho = require("./handlers/envEcho.js");
const customLogin = require("./handlers/customLogin.js");

const mongoDB = require('./service/database');
const nodemailer = require('nodemailer');
Expand Down Expand Up @@ -86,6 +87,7 @@ var HANDLERS = {
"proxyHandler": proxyHandler,
"writeFile": fileHandlers.writeFile,
"envEcho": envEcho,
"customLogin": customLogin,
"iipHandler": function() {
return iipHandler;
},
Expand Down
26 changes: 26 additions & 0 deletions handlers/customLogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var jwt = require('jsonwebtoken');

var EXPIRY = process.env.EXPIRY || '1d';


function customLogin(usernameField, usertypeField) {
return function(req, res) {
let token = {};
// get user id from env
username = process.env[usernameField] || "unknown user";
token.sub = username;
token.email = username;
token.name = username;
usertype = process.env[usertypeField];
token.userType = usertype || "Participant";
// generate token with this info
// return the token
signedToken = jwt.sign(data, "precision-fda-not-secure-token", {
algorithm: 'RS256',
expiresIn: EXPIRY,
});
res.json({"token": signedToken});
};
}

module.expoers = customLogin;

0 comments on commit 450f7e5

Please sign in to comment.