-
Notifications
You must be signed in to change notification settings - Fork 2k
[UNRESOLVED] JWT Authentication #1163
Changes from all commits
09389f0
e3d6b87
a7d0131
02a7ad4
038e84e
68307b7
bc363d2
7838bfd
1a83938
268e20d
1080062
e8d5be3
5ca49d1
51aef0b
03c2b35
c2c5bec
61b28bc
939791b
aaf2479
b178052
b937bc7
690ebfc
e4d0bd4
b46c6a7
fe7b751
f7d571c
c79b65d
c3bdd39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can rename this file to |
||
|
||
var config = require('../config'), | ||
jwt = require('jsonwebtoken'), | ||
lodash = require('lodash'); | ||
|
||
|
||
|
||
// export the token auth service | ||
exports.signToken = function (user, options) { | ||
var payload, | ||
token, | ||
jwtOptions; | ||
|
||
if (!user || !user._id) { | ||
return null; | ||
} | ||
|
||
options = options || {}; | ||
|
||
payload = { | ||
user: user._id.toString() | ||
}; | ||
|
||
jwtOptions = lodash.merge(config.jwt.options, options); | ||
|
||
token = jwt.sign(payload, config.jwt.secret, jwtOptions); | ||
|
||
return token; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,14 +85,15 @@ module.exports = function (app, db) { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The stuff above here talks about sessionSecret sessionId not sure if that's need/was causing my problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the above code (everything about Session and cookies and everything worked just fine! Except the tests I guess... so might have to change those |
||
// Use Passport to populate the user details | ||
passport.initialize()(socket.request, {}, function () { | ||
passport.session()(socket.request, {}, function () { | ||
passport.authenticate('jwt', { session: false })(socket.request, {}, function () { | ||
if (socket.request.user) { | ||
next(null, true); | ||
} else { | ||
next(new Error('User is not authenticated'), false); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jwt: { secret: process.env.TOKEN_AUTH_SECRET || 'M3@N_R0CK5!', options: { //Anything From https://www.npmjs.com/package/jsonwebtoken expiresIn: process.env.TOKEN_EXPIRES || '1d' } }
Basically not a big deal but gives a formatting warning.