-
Notifications
You must be signed in to change notification settings - Fork 2
JWT authentication support #2
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ var inBoundRemoteStatsKeys; | |
| var outBoundRemoteStatsKeys; | ||
| var pcKeys; | ||
|
|
||
| var room = 'foo'; | ||
| var room = "'><img src='' onerror=alert('foo') />"; | ||
| console.log("Room is " + room); | ||
|
|
||
| var temp = Math.floor(Math.random()*10000); | ||
|
|
@@ -74,14 +74,13 @@ if (room !== ''){ | |
| //socket.emit('participant', room,myUserId); | ||
| doGetUserMedia(function(status){ | ||
| if (status === true) { | ||
| socket.emit('participant', room,myUserId); | ||
| socket.emit('participant', room, myUserId); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| var appConfig = AppConfiguration(); | ||
| var appId = appConfig.appId; | ||
| var appSecret = appConfig.appSecret; | ||
|
|
||
| var callStats = new callstats($,io,jsSHA); | ||
|
Contributor
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. $ should be replaced with 'null'. According to the latest dependencies schema. |
||
|
|
||
|
|
@@ -488,8 +487,33 @@ function csReportErrorCallback (err, msg){ | |
| var params = { | ||
| //disableBeforeUnloadHandler: false | ||
| }; | ||
| var createTokenGeneratorTimer; | ||
|
|
||
| var tokenGenerator = (function () { | ||
| var cached = null; | ||
| return function(forcenew, callback) { | ||
| if (!forcenew && cached !== null) { | ||
| return callback(null, cached); | ||
| } | ||
| socket.emit('generateToken', "foobar", function (err, token) { | ||
| if (err) { | ||
| console.log('Token generation failed'); | ||
| console.log("try again"); | ||
| return createTokenGeneratorTimer(forcenew, callback); | ||
| } | ||
| console.log("got token"); | ||
| callback(null, token); | ||
| }); | ||
| }; | ||
| })(); | ||
|
|
||
| createTokenGeneratorTimer = function (forcenew, callback) { | ||
| return setTimeout(function () { console.log("calling tokenGenerator"); tokenGenerator(forcenew, callback);}, 100); | ||
| }; | ||
|
|
||
|
|
||
| callStats.initialize(appId, tokenGenerator, myUserId, csInitCallback,statsCallback); | ||
|
|
||
| callStats.initialize(appId, appSecret, myUserId, csInitCallback,statsCallback); | ||
|
|
||
| document.getElementById("switchBtn").onclick = switchScreen; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ var http = require('http'); | |
| var https = require('https'); | ||
| var fs = require('fs'); | ||
| var path = require('path'); | ||
| var jwt = require('jsonwebtoken'); | ||
| var crypto = require('crypto'); | ||
| var config = require('./config.js'); | ||
| var numClients = 0; | ||
|
|
||
| var usernames = []; | ||
|
|
@@ -13,6 +16,9 @@ var ids = {}; | |
|
|
||
| var server = http.createServer(app); | ||
| fs.exists = fs.exists || require('path').exists; | ||
| var privKey = null; | ||
|
|
||
| privKey = fs.readFileSync('ssl/ecprivate.key'); | ||
|
|
||
| //app.listen(8080); | ||
| app.root = __dirname; | ||
|
|
@@ -22,7 +28,7 @@ server.listen(8080); | |
| app.use("/", express.static(__dirname + '/app')); | ||
| app.get('/', function (req, res) { | ||
| console.log("Req ",req); | ||
| res.sendFile('/app/index.html',{root: __dirname}) | ||
| res.sendFile('/app/index.html',{root: __dirname}); | ||
| }); | ||
|
|
||
| app.get('/dailystatstest', function (req, res) { | ||
|
|
@@ -97,6 +103,39 @@ io.sockets.on('connection', function (socket){ | |
|
|
||
| }); | ||
|
|
||
| socket.on('generateToken', function (data, callback) { | ||
| if (socket.username === undefined || socket.username === null) { | ||
| return callback('userNotJoined'); | ||
| } | ||
| // First generate the JWTID | ||
| crypto.randomBytes(48, function(err, buffer) { | ||
| if (err) { | ||
| return callback(err); | ||
| } | ||
| var tokenid = buffer.toString('hex'); | ||
| var token = null; | ||
| try { | ||
| // Try to sign teh token | ||
| token = jwt.sign( | ||
| { | ||
| userID: socket.username, | ||
| appID: config.appID | ||
| }, privKey, | ||
| { | ||
| algorithm: "ES256", | ||
| jwtid: tokenid, | ||
| expiresIn: 300, //5 minutes | ||
| notBefore: -300 //-5 minutes | ||
| }); | ||
| } catch (error) { | ||
| console.log(error); | ||
| return callback(error); | ||
| } | ||
| console.log({action: "GrantToken", user: socket.username, tokenid: tokenid}); | ||
|
Contributor
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. What's happening with tokenid?
Contributor
Author
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. In real system, for audit purposes you should log the generated tokens. As this is a sample implementation, we will just log the fact that the token was granted. |
||
| callback(null, token); | ||
| }); | ||
| }); | ||
|
|
||
| socket.on('disconnect', function () { | ||
| var room = socket.roomId; | ||
| console.log('User disconnected ',socket.username,room); | ||
|
|
||
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.
Why such a room name?
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.
was this to test an XSS attack vector?