Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deepstream-passport

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepstream-passport - npm Package Compare versions

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)
}
})
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc