Comparing version 0.1.0 to 1.0.0
22
index.js
@@ -8,3 +8,3 @@ /* | ||
var MemoryStore = require('./memory-store'); | ||
var uuid = require('node-uuid'); | ||
var uuid = require('uuid'); | ||
@@ -27,3 +27,3 @@ var Scalper = function Scalper(options) { | ||
var self = this; | ||
return function (req, res, next) { | ||
return async function (req, res, next) { | ||
// if this is a GET for a ticket create it and send it back | ||
@@ -33,10 +33,12 @@ if (req.method === 'GET' && (req.url === self.route || req.originalUrl === self.route)) { | ||
if (value) { | ||
var ticket = self.generateTicket(); | ||
return self.store.set(ticket, value, function (err) { | ||
if (err) return next(err); | ||
res.send({ticket: ticket}); | ||
}); | ||
try { | ||
var ticket = self.generateTicket(); | ||
await self.store.set(ticket, value); | ||
return res.json({ticket: ticket});; | ||
} catch (err) { | ||
return next(err); | ||
} | ||
} | ||
// authentication failed | ||
return res.send(401); | ||
return res.sendStatus(401); | ||
} | ||
@@ -48,4 +50,4 @@ next(); | ||
// don't expose the store directly | ||
Scalper.prototype.get = function (ticket, done) { | ||
this.store.get(ticket, done); | ||
Scalper.prototype.get = async function (ticket) { | ||
return await this.store.get(ticket); | ||
}; | ||
@@ -52,0 +54,0 @@ |
@@ -13,12 +13,12 @@ /* | ||
// Store should return a one time access ticket | ||
MemoryStore.prototype.get = function(ticket, done) { | ||
MemoryStore.prototype.get = function(ticket) { | ||
// delete the ticket from the store and return its value | ||
var val = this.tickets[ticket]; | ||
delete this.tickets[ticket]; | ||
done && done(null, val); | ||
return Promise.resolve(val); | ||
}; | ||
MemoryStore.prototype.set = function (ticket, val, done) { | ||
MemoryStore.prototype.set = function (ticket, val) { | ||
this.tickets[ticket] = val; | ||
done && done(null, val); | ||
return Promise.resolve(val); | ||
}; |
@@ -5,15 +5,17 @@ { | ||
"author": "Joe Wagner", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"test": "NODE_ENV=test mocha" | ||
"test": "NODE_ENV=test mocha --exit" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"node-uuid": "~1.4.1" | ||
"uuid": "^8.2.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.12.0", | ||
"mocha": "^8.0.1", | ||
"should": "~3.3.0" | ||
}, | ||
"engines": { "node": ">=0.10.0" }, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"repository": { | ||
@@ -20,0 +22,0 @@ "type": "git", |
scalper | ||
======= | ||
A ticket store designed to allow an application to use an express app to do auth for a socket.io app | ||
A ticket store designed to allow an application to use an express app to do auth for a socket.io app. compatible with Express 4 | ||
@@ -28,10 +28,4 @@ Installation | ||
Look at [mongo-ticket](https://github.com/JoeWagner/mongo-ticket) for an example implementation with mongodb. | ||
Look at [redis-ticket](https://github.com/JoeWagner/redis-ticket) for an example implementation with mongodb. | ||
Setup | ||
===== | ||
See `example/passport-auth/` for basic usage with express 4, passport, and socket.io. Notice the socket.io server and the express server are completely separated. They could potentially be hosted on separate domains without issue. | ||
Worth noting that the example uses http for simplicity, but its recommended to use https. | ||
Motivation | ||
@@ -38,0 +32,0 @@ ========== |
@@ -24,3 +24,3 @@ | ||
var res = { | ||
send: function (status) { | ||
sendStatus: function (status) { | ||
status.should.equal(401); | ||
@@ -59,3 +59,3 @@ done(); | ||
var res = { | ||
send: function (data) { | ||
json: function (data) { | ||
should.exist(data.ticket); | ||
@@ -80,3 +80,3 @@ count.should.equal(1); | ||
var res = { | ||
send: function (data) { | ||
json: function (data) { | ||
should.exist(data.ticket); | ||
@@ -100,3 +100,3 @@ done(); | ||
var res = { | ||
send: function (data) { | ||
json: function (data) { | ||
should.exist(data.ticket); | ||
@@ -133,3 +133,3 @@ done(); | ||
var res = { | ||
send: function (data) { | ||
json: function (data) { | ||
should.exist(data.ticket); | ||
@@ -170,3 +170,3 @@ Object.keys(memStore.tickets).length.should.equal(1); | ||
middleware(req, res, function () { | ||
res.send = function (data) { | ||
res.json = function (data) { | ||
should.exist(data.ticket); | ||
@@ -198,3 +198,3 @@ done(); | ||
var res = { | ||
send: function (data) { | ||
json: function (data) { | ||
should.exist(data.ticket); | ||
@@ -201,0 +201,0 @@ data.ticket.should.equal('custom-value'); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
11072
6
237
36
+ Addeduuid@^8.2.0
+ Addeduuid@8.3.2(transitive)
- Removednode-uuid@~1.4.1
- Removednode-uuid@1.4.8(transitive)