Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


blanket basic auth middleware

Subscribe to updates I use basic-auth

Statistics on basic-auth

Number of watchers on Github 79
Number of open issues 2
Average time to close an issue 28 days
Main language JavaScript
Average time to merge a PR about 10 hours
Open pull requests 3+
Closed pull requests 1+
Last commit about 2 years ago
Repo Created about 6 years ago
Repo Last Updated over 1 year ago
Size 14 KB
Organization / Authorkoajs
Page Updated
Do you use basic-auth? Leave a review!
View open issues (2)
View basic-auth activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating basic-auth for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

koa-basic-auth Build Status

Add simple blanket basic auth with username / password. If you require anything more specific just use the basic-auth module.


$ npm install koa-basic-auth


Password protect downstream middleware:

const auth = require('koa-basic-auth');
const Koa = require('koa');
const app = new Koa();

// custom 401 handling
app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    if (401 == err.status) {
      ctx.status = 401;
      ctx.set('WWW-Authenticate', 'Basic');
      ctx.body = 'cant haz that';
    } else {
      throw err;

// require auth
app.use(auth({ name: 'tj', pass: 'tobi' }));

// secret response
app.use(async (ctx) => {
  ctx.body = 'secret';

app.listen(3000, function () {
  console.log('listening on port 3000');

Example request:

$ curl -H "Authorization: basic dGo6dG9iaQ==" http://localhost:3000/ -i
HTTP/1.1 200 OK
X-Powered-By: koa
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Date: Sat, 30 Nov 2013 19:35:17 GMT
Connection: keep-alive


Using the mount middleware you may specify auth for a given prefix:

const mount = require('koa-mount');
const auth = require('koa-basic-auth');

app.use(mount('/admin', auth({ name: 'tobi', pass: 'ferret' })));



basic-auth open pull requests (View All Pulls)
  • Enable multiple credential validation.
  • Enable user validation through custom function.
  • Show authentication window in browser
basic-auth questions on Stackoverflow (View All Questions)
  • Spring - Http Basic Auth - Mark endpoint as public
  • Basic Auth after separating API From Laravel Web App
  • Web Api 2 Basic Auth Generic Principal Not Set
  • How to force BASIC auth with Apache HTTPClient 4 when calling a server with SSO configured?
  • Error adding enforce-valid-basic-auth-credentials to config.xml
  • Why does the Basic AUTH box repeatedly pop up after providing a correct user/pw?
  • Spring: How to change default massage in basic auth prompt window?
  • Basic auth through HAProxy
  • Gradle failing to resolve dependencies over https + basic auth
  • Authentication fail with okhttp + ssl + basic auth
  • Can't push image to Amazon ECR - fails with "no basic auth credentials"
  • Send BASIC auth credentials using cxf client
  • http basic auth with swashbuckle api documentation
  • Laravel - Setting session variables when using Basic Auth
  • Differences of JWT and OAuth2 (and Basic Auth)
  • How to use Basic Auth with jQuery and AJAX?
  • PyPi (401) basic auth failed
  • Basic Auth with WP-Json API (Wordpress) and Angular
  • Basic Auth and JWT
  • Python urllib2 Basic Auth Problem
  • Basic Auth Error Laravel 4
  • HTTP Basic Auth not bring up password prompt in <Directory> but in <Location> in Apache 2.4
  • Basic Auth is not working within my server, but works from my computer
  • Preventing HTTP Basic Auth Dialog using AngularJS Interceptors
  • SVN post-commit hook bat file returns Basic Auth error
  • LoopJ AndroidAsyncHttp Can't POST Image With Basic Auth
  • Integration test with rest assured and basic auth with CSRF
  • Distinguish between URL username and Basic auth username?
  • Custom HTML login form in HTTP Basic Auth
  • How to prevent browser to invoke basic auth popup and handle 401 error using Jquery?
basic-auth list of languages used
Other projects in JavaScript