tethysplatform / tethys

The Tethys Platform main Django website project repository.
http://tethysplatform.org/
BSD 2-Clause "Simplified" License
91 stars 50 forks source link

[BUG] Websocket Decorator Permissions #1009

Closed ckrew closed 4 months ago

ckrew commented 5 months ago

Describe the bug Currently the websocket decorator has an authenticator but no way to check permissions to make sure the user (or anonymous user) should be able to access the endpoint.

Expected behavior The websocket decorator should have an option to specify permissions to access the endpoint, just like the controller decorator. That way a user can be checked for authentication and authorization.

Tethys Environment Information

swainn commented 5 months ago

@ckrew is the authentication enforced currently? Can a anonymous in user access a web socket?

ckrew commented 5 months ago

So if I use an incognito window and open up the dev tools, I can connect to the websocket using the lines below. image

If I add a breakpoint in the python code, the code above connects to the websocket and I get the scoped user below image

You can see that it is anonymous and not authenticated (which I was wrong about in the description) but it can still connect to the websocket unless I put some custom user handling like the code below. image

If I connect to the websocket from tethys using an actual user, I can get the id of the scoped user and get the actual user from django users. I get the results below which shows the actual user is not anonymous and it is active. image