Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

basic-auth

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-auth

node.js basic auth parser

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.7M
increased by4.43%
Maintainers
4
Weekly downloads
 
Created

What is basic-auth?

The basic-auth npm package is a simple module to parse `Authorization` header for basic authentication in Node.js applications. It extracts the user credentials from the header and makes them available for authentication purposes.

What are basic-auth's main functionalities?

Parse Basic Auth Credentials

This code demonstrates how to use basic-auth to parse the `Authorization` header in an Express.js application. It checks if the credentials match a predefined username and password, and either grants access or denies it with a 401 status code.

const auth = require('basic-auth');
const express = require('express');
const app = express();

app.use((req, res) => {
  const credentials = auth(req);
  if (!credentials || credentials.name !== 'user' || credentials.pass !== 'pass') {
    res.statusCode = 401;
    res.setHeader('WWW-Authenticate', 'Basic realm="example"');
    res.end('Access denied');
  } else {
    res.end('Access granted');
  }
});

app.listen(3000);

Other packages similar to basic-auth

Keywords

FAQs

Package last updated on 20 Sep 2018

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