Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Login/Logout functions #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

dwarburt
Copy link

These two functions are useful if you want to do authentication by socket.io. The user parameter should be the serialized form of the user (i.e. user._id or what have you).

David Warburton added 2 commits November 25, 2014 16:20
Change-Id: I33737781061d47e88991dc19dfd8413e66894da2
Change-Id: I40be75c884bf96ef04f465308aa189cd9c209ac4
@jfromaniello
Copy link
Owner

How are you planning to use this (big picture)?

I don't get the point

@dwarburt
Copy link
Author

So, the problem I was facing was is this: a user arrives on the site unauthenticated and makes a socket.io connection. Some time later they like to log in, username and password are passed along the websocket, and not a http request, so of course it bypasses all of the passport middleware. I can authenticate the user, using the same strategy configured in passport, but now how to you log in their session? You need the same kind of logic that passport.socketio provides, to take the serialized user and access their session and do some work on it in a way that plays nice with passport. So I add this feature.

@jfromaniello
Copy link
Owner

It seems to me that using passport in this case doesn't worth (since passport is designed to run on connect/express). You might want to check this other module:

https://github.com/jfromaniello/socket-io.sessions

@dwarburt
Copy link
Author

Well, @jfromaniello, I'm a little mystified why you don't want this feature. Your module's purpose is to make passport accessible from a socket.io callback. The features you have allow a sessions identity to be accessed from a socket.io callback. This code adds the feature to login a user from a socket.io callback... It seemed like a good fit for this module, which is why I contributed it.

@jfromaniello jfromaniello reopened this Mar 23, 2015
@jfromaniello
Copy link
Owner

Can you show me an example usage? It is not clear who is going to call this login method

@dwarburt
Copy link
Author

The app I need this for is here: https://bitbucket.org/dwarburton/nodecode. The idea is that you can join as anonymous, and over your socket.io connection do a login or register operation.

@Lichtjaeger
Copy link

I'm looking for this feature too.

@Lichtjaeger
Copy link

Thanks dwarburt. I forked your version and merged it with the latest version of jfromaniello and tried it out. It works as expected. pefect.

I'm now able to login and logout over websocket instead (or in addition) of html request. It's a lot saver and cleaner in my application.

Login/Logout merge with latest version from jfromaniello
@efueyo
Copy link

efueyo commented Jul 11, 2016

I'd also need this feature.
My use case:
A user updates something in their profile (like it's name) and I update it into DB, then I also want the session to show those changes. I typically use login funciton in passport to update those changes

user.update(data, function() {
  socket.request.login(user, function() { // this throws "passport.initialize() middleware not in use" error
    socket.emit('responseEvent', {message: 'User updated!'});
  });
});

@Lichtjaeger
Copy link

Lichtjaeger commented Jul 11, 2016

Sorry @efueyo, I don't think this will happen someday: #108

Try npm install --save github:Lichtjaeger/passport.socketio

@efueyo
Copy link

efueyo commented Jul 11, 2016

Thanks @Lichtjaeger. That's what I think too.

I forked it as well and merged login branch into master. Already working
https://github.com/sentisis/passport.socketio

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants