diff --git a/example/socketsio-auth0-sample/README.md b/example/socketsio-auth0-sample/README.md new file mode 100644 index 0000000..a8467fc --- /dev/null +++ b/example/socketsio-auth0-sample/README.md @@ -0,0 +1,21 @@ +# Auth0 + Socket.io + +This is the seed project you need to use if you're going to create a Socket.io single page app that will use Auth0. + +### Configure your Auth0 credentials + +First, you need to put your `AUTH0_DOMAIN` (example.auth0.com), your `AUTH0_CLIENT_ID` and your `AUTH0_CLIENT_SECRET` on the `auth0-variables.js` file . You can find this information in the Application Settings on your Auth0.com dashboard. + +### Set up the Allowed Origin (CORS) in Auth0 + +Then, you need to put `http://localhost:3001` as an Allowed Origin (CORS) in the Application Settings on your Auth0.com dashboard. + +### Running the example + +In order to run the example, you need to have `node` installed. + +1. run `npm install` +1. run `node index.js` in the directory of this project. + + +Go to [http://localhost:3001](http://localhost:3001) and you'll see the app running :). diff --git a/example/socketsio-auth0-sample/auth0-variables.js b/example/socketsio-auth0-sample/auth0-variables.js new file mode 100644 index 0000000..b55e87d --- /dev/null +++ b/example/socketsio-auth0-sample/auth0-variables.js @@ -0,0 +1,5 @@ +(function (exports){ + exports.AUTH0_DOMAIN = 'Your_Auth0_Domain'; + exports.AUTH0_CLIENT_ID = 'Your_Auth0_Client_Id'; + exports.AUTH0_CLIENT_SECRET = 'Your_Auth0_Client_Secret'; +})(typeof exports === 'undefined' ? this['auth0Variables']={}: exports); diff --git a/example/index.html b/example/socketsio-auth0-sample/index.html similarity index 90% rename from example/index.html rename to example/socketsio-auth0-sample/index.html index 4a7ac34..8d61c02 100644 --- a/example/index.html +++ b/example/socketsio-auth0-sample/index.html @@ -15,10 +15,11 @@ #login button { width: 10%; padding: 8px; border: none; background: rgb(130, 255, 130);} - + +
@@ -81,8 +82,9 @@ var lock = null; $(document).ready(function() { - lock = new Auth0Lock('YOUR_CLIENT_ID', 'YOUR_NAMESPACE'); + //These are set in auth0-variables.js + lock = new Auth0Lock(auth0Variables.AUTH0_CLIENT_ID, auth0Variables.AUTH0_DOMAIN); }); - \ No newline at end of file + diff --git a/example/index.js b/example/socketsio-auth0-sample/index.js similarity index 64% rename from example/index.js rename to example/socketsio-auth0-sample/index.js index 9c7e337..a85192c 100644 --- a/example/index.js +++ b/example/socketsio-auth0-sample/index.js @@ -2,18 +2,23 @@ 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('YOUR_CLIENT_SECRET', 'base64'), + secret: Buffer(auth0Variables.AUTH0_CLIENT_SECRET, 'base64'), timeout: 15000 // 15 seconds to send the authentication message })) .on('authenticated', function(socket){ - console.log('connected & authenticated: ' + socket.decoded_token.toString()); + console.log('connected & authenticated: ' + JSON.stringify(socket.decoded_token)); socket.on('chat message', function(msg){ debugger; io.emit('chat message', msg); diff --git a/example/package.json b/example/socketsio-auth0-sample/package.json similarity index 100% rename from example/package.json rename to example/socketsio-auth0-sample/package.json