New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pubcore/express-basic-auth

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pubcore/express-basic-auth

express middleware to perform http basic authentication

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Express middleware for basic authentication

Prerequisites

  • express based webserver
  • mysql (knex compatible) database (see @pubcore/knex-auth)

Features

  • supports two type of users: SYSTEM and HUMAN
  • will set an user object to express req object (if authentication succeeded)
  • serves allways "401 Unauthorized" and cancel URI, if no credentials
  • serves allways "401 Unautherized" and cancel URI, if user not found
  • calls express "next", if username and password is ok
  • redirect to "deactivated" page, if wrong password used too much within a time window (105ms)
  • redirect to "deactivated" page, if last login of user is long time ago
  • updates last login stamp, one time within defined time frame
  • redirects to change password page (including a back-uri), on first request of new user
  • redirects to change password page (including a back-uri), if password is expired
  • support secondary password for SYSTEM users
  • does set a flag to user object (oldPwUsed), if secondary password exists, but old password has been used
  • optinal support of login by JsonWebToken cookie (Jwt), enabled if option "jwtKeyFile" is available

activity diagram

Configuration options (set on server startup)

	options = {
		publicCancelLoginUri:'/login/canceled',
		publicDeactivatedUri:'/login/deactivated',
		changePasswordUri:'/login/pwchange',
		maxTimeWithoutActivity: 1000 * 60 * 60 * 24 * 180,//[msec]
		maxLoginAttempts:10,
		maxLoginAttemptsTimeWindow:1000 * 3600 * 24,//[msec]
		minTimeBetweenUpdates:1000 * 3600,//[msec],
		jwtKeyFile:'/run/secret/jwt-key.txt' //optional
	},
	table = 'user',

Example

	const
		createLoginMiddleware = require('@pubcore/express-basic-auth').default,
		options = {
			changePasswordUri:'/login/pwchange',
			publicDeactivatedUri:'/login/deactivated',
			publicCancelLoginUri:'/login/canceled',
			maxTimeWithoutActivity: 1000 * 60 * 60 * 24 * 180,//[msec]
			maxLoginAttempts:10,
			maxLoginAttemptsTimeWindow:1000 * 3600 * 24,//[msec]
			minTimeBetweenUpdates:1000 * 3600,//[msec]
		},
		table = 'user',
		knex = new Knex({
			client: 'mysql', connection: {/* see knex*/}
		}),
		db = {knex, table}

	const login = createLoginMiddleware({db, options})
	var router = express.Router()
	router.all('/', login)

Keywords

FAQs

Package last updated on 16 Jan 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc