Skip to content

Commit f381f2d

Browse files
committed
add deprecation message to req.auth
1 parent 12507cf commit f381f2d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

History.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ unreleased
22
==========
33

44
* add deprecation message to `app.configure`
5+
* add deprecation message to `req.auth`
6+
* use `basic-auth` to parse `Authorization` header
57
68
- deps: csurf@~1.3.0
79
- deps: express-session@~1.6.1

lib/request.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Module dependencies.
44
*/
55

6+
var auth = require('basic-auth');
7+
var deprecate = require('depd')('express');
68
var http = require('http')
79
, utils = require('./utils')
810
, connect = require('connect')
@@ -422,20 +424,13 @@ req.__defineGetter__('ips', function(){
422424
*/
423425

424426
req.__defineGetter__('auth', function(){
425-
// missing
426-
var auth = this.get('Authorization');
427-
if (!auth) return;
428-
429-
// malformed
430-
var parts = auth.split(' ');
431-
if ('basic' != parts[0].toLowerCase()) return;
432-
if (!parts[1]) return;
433-
auth = parts[1];
427+
deprecate('req.auth: Use basic-auth module directly');
434428

435429
// credentials
436-
auth = new Buffer(auth, 'base64').toString().match(/^([^:]*):(.*)$/);
437-
if (!auth) return;
438-
return { username: auth[1], password: auth[2] };
430+
var creds = auth(this);
431+
if (!creds) return;
432+
433+
return { username: creds.name, password: creds.pass };
439434
});
440435

441436
/**

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"repository": "visionmedia/express",
2626
"license": "MIT",
2727
"dependencies": {
28+
"basic-auth": "0.0.1",
2829
"buffer-crc32": "0.2.3",
2930
"connect": "2.22.0",
3031
"commander": "1.3.2",

0 commit comments

Comments
 (0)