Permalink
Browse files

Username logic improved!

  • Loading branch information...
1 parent e46d8fe commit e995349493db7641faa869ed38e91ea59d74a40a @gevorg gevorg committed Jan 28, 2012
Showing with 20 additions and 16 deletions.
  1. +6 −4 README.md
  2. +2 −2 examples/example.js
  3. +6 −4 examples/example_express.js
  4. +2 −2 examples/example_file.js
  5. +2 −2 tests/auth/test-basic.js
  6. +2 −2 tests/auth/test-digest.js
View
@@ -29,8 +29,8 @@ var basic = auth({
*/
http.createServer(function(req, res) {
// Apply authentication to server.
- basic.apply(req, res, function() {
- res.end("Welcome to private area!");
+ basic.apply(req, res, function(username) {
+ res.end("Welcome to private area - " + username + "!");
});
}).listen(1337);
```
@@ -67,8 +67,10 @@ var basic = auth({
/**
* Handler for path with authentication.
*/
-app.get('/', basic.apply, function(req, res) {
- res.send("Welcome to private area!");
+app.get('/', function(req, res) {
+ basic.apply(req, res, function(username) {
+ res.send("Welcome to private area - " + username + "!");
+ });
});
```
## Example with [http-proxy](https://github.com/nodejitsu/node-http-proxy/) integration
View
@@ -22,8 +22,8 @@ var basic = auth({
*/
http.createServer(function(req, res) {
// Apply authentication to server.
- basic.apply(req, res, function() {
- res.end("Welcome to private area!");
+ basic.apply(req, res, function(username) {
+ res.end("Welcome to private area - " + username + "!");
});
}).listen(1337);
@@ -12,8 +12,8 @@ var express = require('express');
* Requesting new authentication instance.
*/
var basic = auth({
- authRealm : "Private area.",
- authList : ['Shi:many222', 'Lota:123456']
+ authRealm : "Private area.",
+ authList : ['Shi:many222', 'Lota:123456']
});
/**
@@ -24,8 +24,10 @@ var app = express.createServer();
/**
* Handler for path with authentication.
*/
-app.get('/', basic.apply, function(req, res) {
- res.send("Welcome to private area!");
+app.get('/', function(req, res) {
+ basic.apply(req, res, function(username) {
+ res.send("Welcome to private area - " + username + "!");
+ });
});
/**
@@ -21,8 +21,8 @@ var basic = auth({
*/
http.createServer(function(req, res) {
// Apply authentication to server.
- basic.apply(req, res, function() {
- res.end("Welcome to private area!");
+ basic.apply(req, res, function(username) {
+ res.end("Welcome to private area - " + username + "!");
});
}).listen(1337);
@@ -69,8 +69,8 @@ exports['testIsAuthenticatedTrue'] = function(test) {
var header = "Basic: " + utils.base64('user:hash1');
var request = {headers : {authorization : header}};
- // Source method call, that must return true.
- test.ok(source.isAuthenticated(request), "User must be valid!");
+ // Source method call, that must return username.
+ test.equals(source.isAuthenticated(request), "user", "User must be valid!");
// Test is done.
test.done();
@@ -117,8 +117,8 @@ exports['testIsAuthenticatedTrue'] = function(test) {
// Initiates input request.
var request = {headers : {authorization : header}};
- // Source method call, that must return true.
- test.ok(source.isAuthenticated(request), "User must be valid!");
+ // Source method call, that must return username.
+ test.equals(source.isAuthenticated(request), "mia", "User must be valid!");
// Test is done.
test.done();

0 comments on commit e995349

Please sign in to comment.