
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
mongodb-simple-auth-express
Advanced tools
Simple http authorization middleware for express using mongoDB
Coming Soon!
In order to authenticate properly, it is recommended to have a custom login page at /login, with a form that submits POST data to the same path (omit action="...") with username, password, and optional referrer (to redirect the user where they came from)
Because the module needs the ability to use certain pre-processors, as well as injecting login middleware for authentication processing you must initialize the module first before using it.
// Setup express
let express = require("express");
let app = express();
// Setup auth
let auth = require("auth")({
dbUrl: "mongodb://127.0.0.1:27017",
dbName: "userdb",
collectionName: "users",
userExpire: 1 /*hour*/*60*60*1000,
anonData: {
access: 1
}
});
// These are the default values for the options property, but any of these can be either omitted or changed
auth.init(app,/*optional boolean, default: true*/ addLoginHandlers);
If you would prefer to setup the environment manually, the following code can be used.
// Parsers (required)
app.use(require("cookie-parser")());
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(auth.userMiddleware());
// USER MANAGEMENT PAGES (this is optional, but HIGHLY recommended)
// You must manually authenticate your clients without these, rendering this module mostly useless
app.use("/login",auth.loginMiddleware);
app.use("/logout",auth.logoutMiddleware);
In order to restrict a page, put this function before the handler for the page you would like to restrict
app.use(pageLocation,auth.restrict(restrictionLevel));
app.use(pageLocation,/*Your listener (works with express.static as well)*/);
auth.createUser(username,password,{
// User Data
access: 2 //access level of the user (required field)
});
auth.updateUserData(username,{
// User Data (uses update, so doesn't delete anything)
});
auth.updateUserPassword(username,newPassword);
auth.removeUser(username);
auth.checkAccess(username).then((accessLevel) => {
//Do stuff with accessLevels
});
An instance of this class is created every time a user logs in, and is deleted either when they log out or after an hour of inactivity. (This is configurable in the constants at the top of index.js) It is also returned in every request under req.user.
These are not meant to be used, but exposed anyway just in case you need to do something with them.
The auth.users property is a map with the user's uuid as the key, and their UserClient object as the property.
FAQs
Simple http authorization middleware for express using mongoDB
The npm package mongodb-simple-auth-express receives a total of 3 weekly downloads. As such, mongodb-simple-auth-express popularity was classified as not popular.
We found that mongodb-simple-auth-express demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.