I am trying to figure out how best to secure some websocket gateways that sit beside my 'normal' http things.
My authentication system currently works like so:
-
user signs in with username / password
-
I issue a short lived access token directly to them in response body and send a refresh token as a signed http-only cookie
-
when a user attempts to access some part of the api, the client's process is generally to grab an access token from the refresh endpoint (relying on its cookies) and then do the operation, after which it throws away the access token (it expires very quickly)
So, now, knowing this...I am trying to figure out how to get my websocket secured, as I'll probably need a longer lived token to continue authorizing stuff while the user is connected to the websocket.
I guess, before they connect, the client can grab an access token, send that along with the websocket connection, and I can set up a lifecycle listener to quickly grab the access token, validate it, and then issue a third type of token that is longer lived that they can hold onto while they're active on the websocket...
I mean, I think it will work? But I'll need a new guard, I think. Has anyone done something similar? I'd appreciate other ideas or if my idea is good, just some validation. Thanks