passport.socketio | access passport.js authenticated user information | Socket library
kandi X-RAY | passport.socketio Summary
kandi X-RAY | passport.socketio Summary
Access passport.js user information from a socket.io connection.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Initialize the socket .
- Parses the cookie header
- Filter socket list by socket .
passport.socketio Key Features
passport.socketio Examples and Code Snippets
Community Discussions
Trending Discussions on passport.socketio
QUESTION
The Problem
I keep getting the error failed connection to socket.io: No session found using passport.socketio.js and cant find why. I have looked at other similar posts but that doesn't seem to be a problem. Configuration seems fine to me so I guess the problem is in connecting to MongoDB store which is working ok because I can see session data there but only cookie object is getting passed with passport object empty if user is not authenticated or with information if logged in. So session seems ok to me but I cant access the session details with socket.handshake as documented. How do I confirm if user is authenticated in socket.io
EDIT
I tried using this to share sessions but I can't get passport returned only empty cookie object even if user is authenticated there is no passport
ANSWER
Answered 2020-Dec-14 at 16:03Handshake data is no longer stored in the same place. Not socket.handshake.user
but socket.request.user
. Also you need to use the ip address (127.0.0.1) instead of localhost
. So you go to 127.0.0.1:PORT
instead of localhost:PORT
QUESTION
I've recently implemented passport.js for authentication onto my express server. I'm trying to leverage this authentication for my socket.io server as well. So I'm trying to use the passport.socketio package to do this.
I'm using it as such:
...ANSWER
Answered 2020-Oct-03 at 18:44The namespace.use method is a method that adds a middleware(function) to your socket. So it's expecting a function. In the other hand passportSocketIo.authorize is returning the middleware function you can check the code here. So you have 2 options either you use it like it's specified in the docs:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install passport.socketio
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page