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

passport-headerapikey

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-headerapikey

Api key authentication strategy for Passport, which only handles headers (not body fields).

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is passport-headerapikey?

The passport-headerapikey npm package is a Passport strategy for authenticating with an API key passed in a header. It allows you to protect your routes by requiring a valid API key for access.

What are passport-headerapikey's main functionalities?

Basic API Key Authentication

This feature allows you to set up basic API key authentication using the passport-headerapikey strategy. The provided code demonstrates how to configure the strategy and protect a route in an Express application.

const passport = require('passport');
const HeaderAPIKeyStrategy = require('passport-headerapikey').HeaderAPIKeyStrategy;

passport.use(new HeaderAPIKeyStrategy(
  { header: 'Authorization', prefix: 'Api-Key ' },
  false,
  (apikey, done) => {
    if (apikey === 'your_api_key') {
      return done(null, true);
    } else {
      return done(null, false);
    }
  }
));

// Express setup
const express = require('express');
const app = express();

app.use(passport.initialize());

app.get('/protected', passport.authenticate('headerapikey', { session: false }), (req, res) => {
  res.send('This is a protected route');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to passport-headerapikey

Keywords

FAQs

Package last updated on 20 Aug 2020

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