commit
7d77b59bea
21
example/socketsio-auth0-sample/README.md
Normal file
21
example/socketsio-auth0-sample/README.md
Normal file
@ -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 :).
|
5
example/socketsio-auth0-sample/auth0-variables.js
Normal file
5
example/socketsio-auth0-sample/auth0-variables.js
Normal file
@ -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);
|
@ -15,10 +15,11 @@
|
|||||||
#login button { width: 10%; padding: 8px; border: none; background: rgb(130, 255, 130);}
|
#login button { width: 10%; padding: 8px; border: none; background: rgb(130, 255, 130);}
|
||||||
</style>
|
</style>
|
||||||
<!-- Auth0 lock script -->
|
<!-- Auth0 lock script -->
|
||||||
<script src="//cdn.auth0.com/js/lock-7.5.min.js"></script>
|
<script src="//cdn.auth0.com/js/lock-7.12.min.js"></script>
|
||||||
|
|
||||||
<!-- Setting the right viewport -->
|
<!-- Setting the right viewport -->
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
|
<script src="auth0-variables.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="login">
|
<div id="login">
|
||||||
@ -81,7 +82,8 @@
|
|||||||
|
|
||||||
var lock = null;
|
var lock = null;
|
||||||
$(document).ready(function() {
|
$(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);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
@ -2,18 +2,23 @@ var app = require('express')();
|
|||||||
var http = require('http').Server(app);
|
var http = require('http').Server(app);
|
||||||
var io = require('socket.io')(http);
|
var io = require('socket.io')(http);
|
||||||
var socketioJwt = require('socketio-jwt');
|
var socketioJwt = require('socketio-jwt');
|
||||||
|
var auth0Variables = require('./auth0-variables');
|
||||||
|
|
||||||
app.get('/', function(req, res){
|
app.get('/', function(req, res){
|
||||||
res.sendFile(__dirname + '/index.html');
|
res.sendFile(__dirname + '/index.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/auth0-variables.js', function(req, res){
|
||||||
|
res.sendFile(__dirname + '/auth0-variables.js');
|
||||||
|
});
|
||||||
|
|
||||||
io
|
io
|
||||||
.on('connection', socketioJwt.authorize({
|
.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
|
timeout: 15000 // 15 seconds to send the authentication message
|
||||||
}))
|
}))
|
||||||
.on('authenticated', function(socket){
|
.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){
|
socket.on('chat message', function(msg){
|
||||||
debugger;
|
debugger;
|
||||||
io.emit('chat message', msg);
|
io.emit('chat message', msg);
|
Reference in New Issue
Block a user