From 598558beba54e91178d3698f40afcd38cd7f5836 Mon Sep 17 00:00:00 2001 From: Annyv2 Date: Wed, 25 Nov 2015 19:25:27 -0430 Subject: [PATCH] Create index.js --- example/socketsio-auth0-sample/index.js | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 example/socketsio-auth0-sample/index.js diff --git a/example/socketsio-auth0-sample/index.js b/example/socketsio-auth0-sample/index.js new file mode 100644 index 0000000..a85192c --- /dev/null +++ b/example/socketsio-auth0-sample/index.js @@ -0,0 +1,30 @@ +var app = require('express')(); +var http = require('http').Server(app); +var io = require('socket.io')(http); +var socketioJwt = require('socketio-jwt'); +var auth0Variables = require('./auth0-variables'); + +app.get('/', function(req, res){ + res.sendFile(__dirname + '/index.html'); +}); + +app.get('/auth0-variables.js', function(req, res){ + res.sendFile(__dirname + '/auth0-variables.js'); +}); + +io + .on('connection', socketioJwt.authorize({ + secret: Buffer(auth0Variables.AUTH0_CLIENT_SECRET, 'base64'), + timeout: 15000 // 15 seconds to send the authentication message + })) + .on('authenticated', function(socket){ + console.log('connected & authenticated: ' + JSON.stringify(socket.decoded_token)); + socket.on('chat message', function(msg){ + debugger; + io.emit('chat message', msg); + }); + }); + +http.listen(3001, function(){ + console.log('listening on *:3001'); +});