Sails.js + Passport.js authentication through websockets

前端 未结 4 1489
醉梦人生
醉梦人生 2020-12-08 04:22

When I use Sails.js with Passport.js, the isAuthenticated method does not exist on the req object when requested through websocket.

Could anyone tell me why this hap

4条回答
  •  不知归路
    2020-12-08 05:01

    Another way to extend socket.io req with the passport defined methods login, logout, ... is to rewrite the policy or middleware as below

    module.exports = (req, res, next) ->
        if req.isSocket
            req = _.extend req, _.pick(require('http').IncomingMessage.prototype, 'login', 'logIn', 'logout', 'logOut', 'isAuthenticated', 'isUnauthenticated')
        middleware = passport.authenticate('bearer', { session: false })
        middleware(req, res, next)
    

提交回复
热议问题