koa-basic-auth
Advanced tools
Comparing version 2.0.0 to 3.0.0
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 @@ ================== |
@@ -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' }))); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3563
19472
33
0
75
+ Addedbasic-auth@2.0.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
- Removedbasic-auth@1.1.0(transitive)
Updatedbasic-auth@^2.0.0