This repository was archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eran Hammer
committed
May 12, 2015
1 parent
c3a0fec
commit 51cec7c
Showing
5 changed files
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,25 @@ | |
var Basic = require('hapi-auth-basic'); | ||
var Users = require('./users.json'); | ||
|
||
|
||
// Declare internals | ||
|
||
var internals = {}; | ||
|
||
|
||
internals.validateFunc = function (username, password, callback) { | ||
|
||
var user = Users[username]; | ||
if (!user || user.password !== password) { | ||
return callback(null, false); | ||
} | ||
|
||
user.username = username; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return callback(null, true, user); | ||
}; | ||
|
||
|
||
exports.register = function (server, options, next) { | ||
|
||
server.register(Basic, function (err) { | ||
|
@@ -25,12 +30,12 @@ exports.register = function (server, options, next) { | |
return next(err); | ||
} | ||
|
||
server.auth.strategy('simple', 'basic', { validateFunc: internals.validateFunc }); | ||
server.auth.strategy('basic', 'basic', { validateFunc: internals.validateFunc }); | ||
This comment has been minimized.
Sorry, something went wrong.
hueniverse
|
||
server.route({ | ||
method: 'GET', | ||
path: '/private', | ||
config: { | ||
auth: 'simple', | ||
auth: 'basic', | ||
description: 'Returns a greeting message to the authenticated user', | ||
handler: function (request, reply) { | ||
|
||
|
@@ -44,6 +49,7 @@ exports.register = function (server, options, next) { | |
}); | ||
}; | ||
|
||
|
||
exports.register.attributes = { | ||
name: 'Private' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
{ | ||
"Foo": { | ||
"username": "Foo", | ||
"password": "mysupersecuredpassword" | ||
"foo": { | ||
"password": "foo" | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
"Bar": { | ||
"username": "Bar", | ||
"password": "mysupersecuredpassword2" | ||
"bar": { | ||
"password": "bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Better to set duplicate values in code than repeat them in the JSON file.