[keycloak-dev] keycloak-nodejs-connect - Expose Token for manual websocket handling

Wolfgang Ederer wolfgangederer at gmail.com
Mon Nov 18 04:46:23 EST 2019


Hello,

in our application we are using the nodejs adapter in the backend and
communicate to the frontend via a websocket connection. Because the adapter
does not provide websocket authentication out of the box we need to check
the token manually.

Because *Token *is not exposed via the *Keycloak *module we need to do the
following:


*const Token =
require('node_modules/keycloak-connect/middleware/auth-utils/token.js');*

*const newToken = new Token(socket.handshake.query.token);*


This is a workaround of sorts - especially when using TypeScript - and in
my opinion *Token *should be exposed via the *Keycloak *prototype in order
to be used like this:


*import * as Keycloak from 'keycloak-connect';*

*const newToken = new Keycloak.Token(socket.handshake.query.token);*
*//or*
*const newToken = new Keycloak.getToken(socket.handshake.query.token);  *


What is your opinion on this topic?

Best Regards
Wolfgang Ederer
https://github.com/wederer


More information about the keycloak-dev mailing list