Skip to content

Commit

Permalink
Merge pull request #138 from camicroscope/develop
Browse files Browse the repository at this point in the history
For 3.9.11
  • Loading branch information
birm authored Aug 5, 2022
2 parents 0f24191 + df01939 commit aece38e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var HANDLERS = {
"loginHandler": function() {
return auth.loginHandler(auth.PUBKEY);
},
"loginWithHeader": auth.loginWithHeader,
"sanitizeBody": function() {
return sanitizeBody;
},
Expand Down
30 changes: 30 additions & 0 deletions handlers/authHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,35 @@ function firstSetupUserSignupExists() {
};
}

// Use a trusted header instead of a jwt for login. Use carefully if at all.
function loginWithHeader(header, signKey, userFunction) {
return function(req, res) {
// get the correct header, set it to use userFunction
let token = {"email": req.headers[header]};
// login using that
userFunction(token).then((x) => {
if (x === false) {
res.status(401).send({
'err': 'User Unauthorized',
});
} else {
data = x;
delete data['exp'];
// sign using the mounted key
var token = jwt.sign(data, signKey, {
algorithm: 'RS256',
expiresIn: EXPIRY,
});
res.send({
'token': token,
});
}
}).catch((e) => {
console.log(e);
res.status(401).send(e);
});
};
}

auth = {};
auth.jwkTokenTrade = jwkTokenTrade;
Expand All @@ -271,6 +300,7 @@ auth.filterHandler = filterHandler;
auth.loginHandler = loginHandler;
auth.editHandler = editHandler;
auth.firstSetupUserSignupExists = firstSetupUserSignupExists;
auth.loginWithHeader = loginWithHeader;
auth.CLIENT = CLIENT;
auth.PRIKEY = PRIKEY;
auth.PUBKEY = PUBKEY;
Expand Down
1 change: 0 additions & 1 deletion idx_mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const mongodb = require("./service/database");

function indexes() {
db = "camic";
mongodb.createIndex(db, "authorization", {"name": 1}, {unique: true});
mongodb.createIndex(db, "user", {"email": 1}, {unique: true});
mongodb.createIndex(db, "mark", {"provenance.image.slide": 1,
"provenance.analysis.execution_id": 1, "footprint": 1, "x": 1, "y": 1});
Expand Down

0 comments on commit aece38e

Please sign in to comment.