dwyl / hapi-auth-jwt2

:lock: Secure Hapi.js authentication plugin using JSON Web Tokens (JWT) in Headers, URL or Cookies
ISC License
798 stars 126 forks source link

JWT Socket.io authentication #301

Closed PavelKv closed 3 years ago

PavelKv commented 5 years ago

Hi All,

This is more of a question than issue, I would like to use JWT to authenticate calls on Hapi with socket.io however I am not sure how should I validate token. Here is server part of socket.io on HAPI server:

const io = SocketIO.listen(server.listener); io.use(function(socket, next) { let token = socket.handshake.query.token;

next();

}); io.sockets.on('connection', (socket) => { socket.emit('msg', 'welcome') });

I could just pass token to validate function for hapi-auth-jwt2 but I would have to decode it first, would this be a correct approach?

Thanks, Pav

nelsonic commented 3 years ago

Socket.io auth is a legitimate use case. If anyone still needs/wants it, we would gladly accept a PR. Thanks. 👍