[nodebb-plugin-session-sharing] Session Sharing
-
Session Sharing for NodeBB
In a nutshell, this plugin allows you to share sessions between your application and NodeBB. You'll need to set a
special cookie with a common domain, containing a JSON Web Token with user data. If sufficient, this plugin will
handle the rest (user registration/login).How is this related to SSO?
Single Sign-On allows a user to log into NodeBB through a third-party service. It is best (and most securely)
achieved via OAuth2 provider, although other alternatives exist. An example of a single sign-on plugin is
nodebb-plugin-sso-facebook.Single sign-on does not allow a session to become automatically created if a login is made to another site.
This is the one misconception that people hold when thinking about SSO and session sharing.This session sharing plugin will allow NodeBB to automatically log in users (and optionally, log out users)
if the requisite shared cookie is found (more on that below).You can use this plugin and single sign-on plugins together, but they won't be seamlessly integrated.
How does this work?
This plugin checks incoming requests for a shared cookie that is saved by your application when a user
logs in. This cookie contains in its value, a specially crafted signed token containing unique identifying
information for that user.If the user can be found in NodeBB, that user will be logged in. If not, then a user is created, and that
unique indentifier is saved for future reference.
Read more at the project repository
Updates
-
-
This sounds perfect -- for our game (forum at http://forum.traverse.world/) I'd love to authenticate on forum, and share session with the game.
Can I use this plugin to share session in that direction? (from nodeBB to app)
-
v1.0.13 released
- [Bug] Fixed issue where if a user was created by the session sharing plugin and subsequently deleted (in the ACP), a new login through session-sharing would result in an endless loop as the user reference was missing. A new user is now created.
-
@julian This plugin looks great. I'm linking to the forum from within a mobile app, so it will be perfect for user experience.
I'm having a couple of issues getting it to work though:
-
From the Session Sharing admin page on user search I keep getting 'We were unable to find a remote id belonging to that user'. I assumed this was just the uid? I don't get any results for remote ID search using uids.
-
Running NodeBB in dev mode, I can call the '/debug/session/' endpoint and get a 200 OK response. A document in the sessions collection is created with session value
{"cookie":{"originalMaxAge":1209600000,"expires":"2016-05-25T14:36:09.230Z","httpOnly":true,"path":"/"}}'
but no testUser is created. -
I've tried creating a cookie to test in the browser with 'javascript:document.cookie="token=<JWT token>" 'but it doesn't seem to be picked up by the page
I do have the authentication overridden (hook "action:auth.overrideLogin") with my own system, so I'm hoping that isn't related to this, or likely to cause issues down the line.
I'm currently running v1.0.2, if that helps.
-
-
I keep getting 'We were unable to find a remote id belonging to that user'. I assumed this was just the uid? I don't get any results for remote ID search using uids.
That search would be for putting in a NodeBB ID and finding the "remote id" associated with it. e.g. uid 1 on NodeBB is linked to session share id of
2b54c8d65eaff
, so you can search for1
and get that ID back./debug/session
gives you the cookie, but won't create the user until you access the site itself.The cookie set via javascript may not be read because the session sharing cookie is http only. That may be why...
-
Hey @julian , thanks for this useful plugin.
Why is username or first and last name required in addition to ID inside the JWT? Is it possible to remove this requirement and only require ID to be contained in the JWT?
Surely the user's account can be located with just the ID, correct?
-
When I remove the requirement for username or full name, the findUser does not find the user, the async.parallel returns:
{ uid: null, mergeUid: null }
https://github.com/julianlam/nodebb-plugin-session-sharing/blob/master/library.js
and line 185, the last else clause, would be executedI suspect it has to do with lines 159 and 160, but I do not understand the code here, do you have any ideas?
-
I dont know how is this auth process works with jwt.
I have nodebb inforum.example.com
and nodejs app inexample.com
. And reverse proxy with nginx. I have few question:-When user logins or signs up which route we should POST method to?
-Do I need to installnpm install jsonwebtoken
?
-Is this JWT Secret key obtained from jwt.io website?
-How can I save a cookie to user browser?
-When I achieve all this and users logins with nodebb credentials how can i access to current logged in user info?
-Do I need to include the user's passwords to Json web token?
-Do I need to set secret in nodebb admin panel?Edit:So I did some googling and what I understand I need to post the user info to some expressjs route on my app and generate the Json web token in backend and use some cookie plugin for nodejs. But my last two question is remain unclear for me.
@julian -
-
first sorry for my english it is not my first language
i am using the session sharing plugin and it is working wonderful , the users on my app login directly to the nodeBB, but i need to classify them into groups I created two group already from the admin panel (Group-1 , Group-2) as i under stand i need to setup the settings from the admin panel and put the group title at the JWT payload that i send to be saved at the cookies
here is how my payload looks like id: uuid,
email: [email protected],
username: username,
groupTitle: 'Group-1',but when i check the user on nodebb i notes that the user created and logged in successfully but the user join no group ... is it the right approach ??? what to do??
@julian