deepstream-passport
Advanced tools
Comparing version 1.0.0 to 1.1.0
75
main.js
@@ -9,41 +9,52 @@ "use strict" | ||
function deepstreamPassport(session, handler) { | ||
return function(connectionData, authData, callback) { | ||
var req = new MockExpressRequest({ | ||
method: 'GET', | ||
url: '/', | ||
headers: { | ||
Cookie: connectionData.headers.cookie | ||
} | ||
}) | ||
var res = new MockExpressResponse({request: req}) | ||
function deepstreamPassport(session, props) { | ||
var user = null | ||
function use(fn) { | ||
return new Promise(function(resolve, reject) { | ||
return fn(req, res, function(err) { | ||
return err ? reject(err) : resolve() | ||
}) | ||
return { | ||
isValidUser: function(connectionData, authData, callback) { | ||
var req = new MockExpressRequest({ | ||
method: 'GET', | ||
url: '/', | ||
headers: { | ||
Cookie: connectionData.headers.cookie | ||
} | ||
}) | ||
} | ||
var res = new MockExpressResponse({request: req}) | ||
return use(session).then(function() { | ||
return use(passport.initialize()) | ||
function use(fn) { | ||
return new Promise(function(resolve, reject) { | ||
return fn(req, res, function(err) { | ||
return err ? reject(err) : resolve() | ||
}) | ||
}) | ||
} | ||
}).then(function() { | ||
return use(passport.session()) | ||
return use(session).then(function() { | ||
return use(passport.initialize()) | ||
}).then(function() { | ||
if(handler !== undefined) { | ||
return handler({ | ||
connection: connectionData, | ||
auth: authData | ||
}, req.user, callback) | ||
} | ||
}).then(function() { | ||
return use(passport.session()) | ||
if(req.user) { | ||
return callback(null, req.user.id) | ||
} | ||
}).then(function() { | ||
user = req.user | ||
return callback(null, 'anon') | ||
}) | ||
if(props.isValidUser !== undefined) { | ||
return props.isValidUser(user, callback) | ||
} | ||
if(user) { | ||
return callback(null, user.id) | ||
} | ||
return callback(null, 'anon') | ||
}) | ||
}, | ||
canPerformAction: function(id, message, callback) { | ||
props.canPerformAction(user, callback) | ||
}, | ||
onClientDisconnect: function(user) { | ||
props.onClientDisconnect(user) | ||
} | ||
} | ||
@@ -50,0 +61,0 @@ } |
{ | ||
"name": "deepstream-passport", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Passport Session Authentication for Deepstream.io", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -28,13 +28,11 @@ # deepstream-passport | ||
// Basic: | ||
server.set('permissionHandler', { | ||
isValidUser: deepstreamPassport(session), | ||
canPerformAction(id, message, callback) { | ||
callback(null, true) | ||
server.set('permissionHandler', deepstreamPassport(session, { | ||
canPerformAction(user, callback) { | ||
callback(null, user.isAdmin) | ||
} | ||
} | ||
}) | ||
// Custom handler (with user object): | ||
server.set('permissionHandler', { | ||
isValidUser: deepstreamPassport(session, (data, user, callback) => { | ||
// Custom `isValidUser`: | ||
server.set('permissionHandler', deepstreamPassport(session, { | ||
isValidUser: (user, callback) => { | ||
if(user) { | ||
@@ -45,6 +43,8 @@ callback(null, user.id) | ||
} | ||
}), | ||
... | ||
} | ||
}, | ||
canPerformAction(user, callback) { | ||
callback(null, user.isAdmin) | ||
} | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4808
48