Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting expiration time to be 7 days #78

Merged
merged 3 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions example/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ function generateToken(req, GUID, opts) {
// By default, expire the token after 7 days.
// NOTE: the value for 'exp' needs to be in seconds since
// the epoch as per the spec!
var expiresDefault = Math.floor(new Date().getTime()/1000) + 7*24*60*60;
var expiresDefault = '7d';

var token = jwt.sign({
auth: GUID,
agent: req.headers['user-agent'],
exp: opts.expires || expiresDefault
}, secret);
agent: req.headers['user-agent']
}, secret, { expiresIn: expiresDefault });

return token;
}

Expand Down
16 changes: 9 additions & 7 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
var port = process.env.PORT || 1337; // let heroku define port or use 1337
var http = require('http'); // core node.js http (no frameworks)
var url = require('url'); // core node.js url (no frameworks)
var app = require('./lib/helpers'); // auth, token verification & render helpers
var c = function(res){ /* */ };

http.createServer(function (req, res) {
var url = req.url;
if( url === '/' || url === '/home' ) { app.home(res); } // homepage
else if( url === '/auth') { app.handler(req, res); } // authenticator
else if( url === '/private') { app.validate(req, res, app.done); } // private content
else if( url === '/logout') { app.logout(req, res, app.done); } // end session
else if( url === '/exit') { app.exit(res); } // for testing ONLY
else { app.notFound(res); } // 404 error
var path = url.parse(req.url).pathname;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good plan. 👍

if( path === '/' || path === '/home' ) { app.home(res); } // homepage
else if( path === '/auth') { app.handler(req, res); } // authenticator
else if( path === '/private') { app.validate(req, res, app.done); } // private content
else if( path === '/logout') { app.logout(req, res, app.done); } // end session
else if( path === '/exit') { app.exit(res); } // for testing ONLY
else { app.notFound(res); } // 404 error
}).listen(port);

console.log("Visit: http://127.0.0.1:" + port);