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

koa-basic-auth

Package Overview
Dependencies
Maintainers
8
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-basic-auth - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

8

History.md
3.0.0 / 2018-05-16
==================
* show authentication window in browser (#15)
* npm: disable package-lock
* travis: add node 10
* bump deps
2.0.0 / 2016-03-18

@@ -3,0 +11,0 @@ ==================

8

index.js

@@ -29,3 +29,5 @@

return function basicAuth(ctx, next){
if (!opts.realm) opts.realm = 'Secure Area';
return function basicAuth(ctx, next) {
const user = auth(ctx);

@@ -36,5 +38,7 @@

} else {
ctx.throw(401);
ctx.throw(401, null, { headers: {
'WWW-Authenticate': 'Basic realm="' + opts.realm.replace(/"/g, '\\"') + '"'
} });
}
};
};

@@ -5,7 +5,7 @@ {

"repository": "koajs/basic-auth",
"version": "2.0.0",
"version": "3.0.0",
"scripts": {
"test": "NODE_ENV=test mocha --reporter spec",
"test-cov": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha",
"test-travis": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha --report lcovonly"
"test": "NODE_ENV=test mocha --reporter spec --exit",
"test-cov": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha -- --exit",
"test-travis": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --exit"
},

@@ -23,11 +23,11 @@ "keywords": [

"devDependencies": {
"istanbul": "0",
"koa": "^2.0.0-alpha.3",
"mocha": "2",
"supertest": "1"
"istanbul": "^0.4.5",
"koa": "^2.5.1",
"mocha": "^5.1.1",
"supertest": "^3.1.0"
},
"license": "MIT",
"dependencies": {
"basic-auth": "^1.0.3"
"basic-auth": "^2.0.0"
}
}

@@ -17,16 +17,15 @@ # koa-basic-auth [![Build Status](https://travis-ci.org/koajs/basic-auth.png)](https://travis-ci.org/koajs/basic-auth)

```js
var auth = require('koa-basic-auth');
var koa = require('koa');
var app = koa();
const auth = require('koa-basic-auth');
const Koa = require('koa');
const app = new Koa();
// custom 401 handling
app.use(function *(next){
app.use(async (ctx, next) => {
try {
yield next;
await next();
} catch (err) {
if (401 == err.status) {
this.status = 401;
this.set('WWW-Authenticate', 'Basic');
this.body = 'cant haz that';
ctx.status = 401;
ctx.set('WWW-Authenticate', 'Basic');
ctx.body = 'cant haz that';
} else {

@@ -39,13 +38,12 @@ throw err;

// require auth
app.use(auth({ name: 'tj', pass: 'tobi' }));
// secret response
app.use(async (ctx) => {
ctx.body = 'secret';
});
app.use(function *(){
this.body = 'secret';
app.listen(3000, function () {
console.log('listening on port 3000');
});
app.listen(3000);
console.log('listening on port 3000');
```

@@ -70,4 +68,4 @@

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

@@ -74,0 +72,0 @@ app.use(mount('/admin', auth({ name: 'tobi', pass: 'ferret' })));

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