Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS connection based context/session data #42

Closed
petslane opened this issue Aug 6, 2019 · 3 comments
Closed

WS connection based context/session data #42

petslane opened this issue Aug 6, 2019 · 3 comments
Assignees

Comments

@petslane
Copy link

petslane commented Aug 6, 2019

Is there some way to have authentication mechanism or have session data based on ws connection?

Basically I would like to register methods that are usable anonymously (eg. login) and methods that require authenticated connection (eg. getPermissions). So on client connect, when calling getPermissions I would get some error, but calling it after successful login, I would get my data.

This use-case could be achieved by passing socket (<ws.WebSocket>) to registered method handler as second argument. Then registered methods can set and check custom properties.

Currently only way to achieved this is to return some token with login and require it on getPermissions. But because ws connections are not shared, then if feels strange to pass some session tokens to methods.

@mkozjak
Copy link
Member

mkozjak commented Aug 6, 2019

@petslane: this feature is not available at this time. It's clearly an interesting use-case and it might be implemented without much difficulty.

ws' connection event has all sufficient parameters to handle login data such as cookies, etc., so it might be handled on server-side to mark the connection as logged in or anonymous.

We could introduce a special protected method _login or such where you'd be able to provide your own authentication middleware. You'd also be able to register rpc methods as "private" that could only be called when authenticated.

Care to do a PR, maybe?

@mkozjak mkozjak mentioned this issue Aug 7, 2019
@mkozjak mkozjak self-assigned this Aug 7, 2019
@mkozjak
Copy link
Member

mkozjak commented Aug 7, 2019

@petslane: Care to test this feature? It should be ready. Please check the PR.

@mkozjak mkozjak closed this as completed in f276316 Aug 8, 2019
@mkozjak
Copy link
Member

mkozjak commented Aug 10, 2019

This feature is now available in version 4.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants