Uname : Linux premium36.web-hosting.com 4.18.0-513.24.1.lve.1.el8.x86_64 #1 SMP Thu May 9 15:10:09 UTC 2024 x86_64
Soft : LiteSpeed
Ip : 198.54.115.237
Port : 443
~
/
opt
/
alt
/
alt-nodejs6
/
root
/
usr
/
lib
/
node_modules
/
npm
/
node_modules
/
request
/
node_modules
/
hawk
/
example
[ HOME ]
Exec
Submit
usage.js
// Load modules var Http = require('http'); var Request = require('request'); var Hawk = require('../lib'); // Declare internals var internals = { credentials: { dh37fgj492je: { id: 'dh37fgj492je', // Required by Hawk.client.header key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', user: 'Steve' } } }; // Credentials lookup function var credentialsFunc = function (id, callback) { return callback(null, internals.credentials[id]); }; // Create HTTP server var handler = function (req, res) { Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { var payload = (!err ? 'Hello ' + credentials.user + ' ' + artifacts.ext : 'Shoosh!'); var headers = { 'Content-Type': 'text/plain', 'Server-Authorization': Hawk.server.header(credentials, artifacts, { payload: payload, contentType: 'text/plain' }) }; res.writeHead(!err ? 200 : 401, headers); res.end(payload); }); }; Http.createServer(handler).listen(8000, '127.0.0.1'); // Send unauthenticated request Request('http://127.0.0.1:8000/resource/1?b=1&a=2', function (error, response, body) { console.log(response.statusCode + ': ' + body); }); // Send authenticated request credentialsFunc('dh37fgj492je', function (err, credentials) { var header = Hawk.client.header('http://127.0.0.1:8000/resource/1?b=1&a=2', 'GET', { credentials: credentials, ext: 'and welcome!' }); var options = { uri: 'http://127.0.0.1:8000/resource/1?b=1&a=2', method: 'GET', headers: { authorization: header.field } }; Request(options, function (error, response, body) { var isValid = Hawk.client.authenticate(response, credentials, header.artifacts, { payload: body }); console.log(response.statusCode + ': ' + body + (isValid ? ' (valid)' : ' (invalid)')); process.exit(0); }); });
Submit
Back
Folder Name
Submit
File Name
File Content
Submit
Name
Type
Size
Permission
Last Modified
Actions
.
dir
-
0755
2024-03-03 10:41:43
..
dir
-
0755
2024-03-03 10:41:43
usage.js
text/plain
2.03 KB
0644
2021-09-28 09:36:06