Applying Basic HTTP Authentication

Another common use for Express middleware is to apply basic HTTP authentication. HTTP authentication uses the Authorization header to send an encoded username and password from a browser to a server. If no authorization information is stored in the browser for the URL, the browser launches a basic login dialog box to allow the user to enter the username and password. Basic HTTP authentication works well for basic sites that require a minimal authenticate method and is very easy to implement.

The basic-auth-connect middleware function in Express provides the support to handle basic HTTP authentication. The basic-auth-connect middleware uses the following syntax:

var basicAuth = ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.