How to make authorization in the chat node.js + socket.io on the website using PHP?

Is there a website in php that I want to put the chat like the best option I chose the chat using sockets(node.js + socket.io), seems to be all done, but I don't know how to implement user authorization in this chat using account data from php and databases.

p.s. using database MongoDB
September 26th 19 at 11:40
3 answers
September 26th 19 at 11:42
Solution
1) request from node a php-script, which will say whether the user is authorized. (easiest way)
2) store in a shared database session (session token), so that from node easy to know whether the user is authorized (in a good way)
3) Implement node in the same authentication method as in php. (a bad way - will have to re-request a password to enter the chat)
4) use Redis PubSub for the exchange of information between php and node. (a bad way - in php have to constantly request data whether the channel is a new request)
I do not quite understand the essence of the second method can be a little bit more? - Evie93 commented on September 26th 19 at 11:45
what is the authorization token you know? something like a sessionid. It is stored in a session, the session is stored in the database (as mentioned ) or just the info on the token is duplicated in the database. The same token knows the client js and passes through a websocket in node. It only remains to check whether received from the client token in the database or not. - Gustave.Fay commented on September 26th 19 at 11:48
September 26th 19 at 11:44
You can pomudrit with sessions in PHP. To move the storage of sessions with files on mongodb. Then Noda and PHP will work with shared variables sessions.

Or stupid authorization from PHP to the database to write auth_key randomly, and store it in a cookie.
And in a nod to cook auth_key and search it in database and user for example to check the IP log.
September 26th 19 at 11:46
I'd be checking the authorization purely on the PHP side, for example.
And would use node.js with the module socket.oi, for signaler server instant messaging/notification in chat.

Find more questions by tags ChatsNode.jsPHPSocket.ioSockets