Byrd — Chat & Sockets — Authentication

That was quite a task, to get this going. I even had a serious problem with getting git commits separated from each other, so I ended up committing it all together.

Introduction

But finally, I decided to go with WebSockets — on top of Socket.IO. Decision was pretty simple, I’ve used WS before, and as I’m pretty limited if goes about time I can spend on this project — that was the easiest solution.

Doubts…

Of course, agents do need to authenticate, as they pay the key role on the platform. I’m not building a simple chat, I’m building a helpdesk system. Since agents already are being authenticated with use of Tokens — there was no doubt I’m gonna have to use them as well for that purpose. And since I’m going have to use them for agent auth — clear is, they’d have to use used for guests as well.

Solution

Returned token is afterwards passed within a query string. The beauty of JWT gives me possibility to store data inside of it — so I took advantage of it, and I pass Chat result along with it. This helps me to save some time, as well as database performance.

You could also notice type key/value, being passed within the token. That helps me to verify whether the user is an agent or a guest, so I can split the auh process. Again — this is safe practice, as token is signed, so nobody will be able to successfully fake the token, without access to my secret.

--

--

Software Engineer. Email me at me@polethedev.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store