My idea is as follows.
When connection from client-side (browser) is requested, server generates random token on websocket upgrade request and sends it via HTTP Set-Cookie header. Then, client authenticates via Challenge-Response authentication over websocket connection. On successful auth, server saves previously generated token in database for user. token cookie is needed to restore session, when user re-initiates websocket connection.
My question is, how can I temporarily store token on memory per connection (per user), so that I can access it later and save in database for that user? (sort of "request context").