mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Add hapi-auth-basic to enable fixing nes properly
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import Bcrypt = require('bcrypt');
|
||||
import Basic = require('hapi-auth-basic');
|
||||
import * as Hapi from 'hapi';
|
||||
|
||||
const server = new Hapi.Server();
|
||||
|
||||
interface User {
|
||||
username: string;
|
||||
password: string;
|
||||
name: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
const users: {[index: string]: User} = {
|
||||
john: {
|
||||
username: 'john',
|
||||
password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // 'secret'
|
||||
name: 'John Doe',
|
||||
id: '2133d32a'
|
||||
}
|
||||
};
|
||||
|
||||
const validate: Basic.ValidateFunc = function (request, username, password, callback) {
|
||||
|
||||
const user = users[username];
|
||||
if (!user) {
|
||||
return callback(null, false);
|
||||
}
|
||||
|
||||
Bcrypt.compare(password, user.password, (err, isValid) => {
|
||||
|
||||
callback(err, isValid, { id: user.id, name: user.name });
|
||||
});
|
||||
};
|
||||
|
||||
server.register(Basic, (err) => {
|
||||
|
||||
server.auth.strategy('simple', 'basic', { validateFunc: validate });
|
||||
server.route({ method: 'GET', path: '/', config: { auth: 'simple' } });
|
||||
});
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// Type definitions for hapi 4.2
|
||||
// Project: https://github.com/hapijs/hapi-auth-basic
|
||||
// Definitions by: AJP <https://github.com/AJamesPhillips>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import * as Hapi from 'hapi';
|
||||
|
||||
declare namespace Basic {
|
||||
interface ValidateFuncCallback {
|
||||
(err: Error | null, isValid: boolean, userCredentials?: any): void;
|
||||
}
|
||||
|
||||
interface ValidateFunc {
|
||||
(request: Hapi.Request, username: string, password: string, callback: ValidateFuncCallback): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare var Basic: Hapi.PluginFunction<{}>;
|
||||
|
||||
export = Basic;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"hapi-auth-basic-tests"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user