From 3d92717b7a4d4ac7942f62b9743ff6d65109edc3 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Mon, 19 Aug 2013 18:24:17 -0700 Subject: [PATCH] remove Context#auth. Closes #26 --- docs/api.md | 5 ----- lib/context.js | 30 ------------------------------ test/context.js | 9 --------- 3 files changed, 44 deletions(-) diff --git a/docs/api.md b/docs/api.md index 57b34fb..a14a090 100644 --- a/docs/api.md +++ b/docs/api.md @@ -375,11 +375,6 @@ this.body = yield db.find('something'); of these ips is returned, ordered from upstream -> downstream. When disabled an empty array is returned. -### ctx.auth - - Parses basic auth credentials and returns an object with `.username` and `.password`. It's recommended to use `ctx.secure` to ensure basic auth is only - used over HTTPS. - ### ctx.subdomains Return subdomains as an array. diff --git a/lib/context.js b/lib/context.js index 642d359..deb142c 100644 --- a/lib/context.js +++ b/lib/context.js @@ -378,36 +378,6 @@ module.exports = { : []; }, - /** - * Return basic auth credentials. - * - * Examples: - * - * // http://tobi:hello@example.com - * this.auth - * // => { username: 'tobi', password: 'hello' } - * - * @return {Object} or undefined - * @api public - */ - - get auth() { - // missing - var auth = this.get('Authorization'); - if (!auth) return; - - // malformed - var parts = auth.split(' '); - if ('basic' != parts[0].toLowerCase()) return; - if (!parts[1]) return; - auth = parts[1]; - - // credentials - auth = new Buffer(auth, 'base64').toString().match(/^([^:]*):(.*)$/); - if (!auth) return; - return { username: auth[1], password: auth[2] }; - }, - /** * Return subdomains as an array. * diff --git a/test/context.js b/test/context.js index 645f4ba..6788e87 100644 --- a/test/context.js +++ b/test/context.js @@ -71,15 +71,6 @@ describe('ctx.header', function(){ }) }) -describe('ctx.auth', function(){ - it('should parse basic auth', function(){ - var ctx = context(); - ctx.header.authorization = 'basic Zm9vOmJhcg=='; - ctx.auth.username.should.equal('foo'); - ctx.auth.password.should.equal('bar'); - }) -}) - describe('ctx.protocol', function(){ describe('when encrypted', function(){ it('should return "https"', function(){