-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add decorator for websockets authentication #124
Add decorator for websockets authentication #124
Conversation
def wrapper( # type: ignore | ||
self: RequestHandler, *args, **kwargs | ||
) -> Optional[Awaitable[None]]: | ||
if not self.current_user: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to this point, this is the same as tornado.web.authenticated
. Then after that we skip all the redirect and just log + return error.
c66580b
to
2aabb16
Compare
And what happens if someone tries to open the connection to our (ready state 3 means connection closed - https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState) |
Codecov Report
@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 52.56% 52.68% +0.12%
==========================================
Files 6 6
Lines 371 372 +1
Branches 58 58
==========================================
+ Hits 195 196 +1
Misses 173 173
Partials 3 3
Continue to review full report at Codecov.
|
Phew, all done! Works on my environment (famous last words), changelog created for 0.3 (which I also created and set a random release date), and a tentative documentation created too. Will ask for reviewers later after 0.2 release. |
5ba8f85
to
adc7196
Compare
adc7196
to
e7fdf5f
Compare
Rebased. |
Codecov Report
@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 50.75% 50.88% +0.12%
==========================================
Files 6 6
Lines 396 397 +1
Branches 64 64
==========================================
+ Hits 201 202 +1
Misses 192 192
Partials 3 3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although I couldn't exactly reproduce the backend error..
I suppose I'd need to use a non-browser client I suppose?
The subscription/web-socket connection stays open when you logout at the moment..
Or create a JavaScript client, without being logged in to the UIS. Doing so, will fail as the handler won't have the authentication token.
Hmm, good point. I will test that, and if reproduced, will create an issue for that. This one should take care of authentication for the websockets, but not sure if it makes any difference after you logged out. Will confirm later with Cylc UI 👍 Thanks @dwsutherland ! |
redirect users to log-in forms (not available for JS clients).
e7fdf5f
to
442e298
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
These changes partially address #110
The default
tornado.web.authenticated
decorator, with the settings from JupyterHub that we have in our application, will try to redirected unauthenticated requests to the log-in form.This redirect may succeed if the user is already logged-in, and is using a browser. But for a JS client initiating the WebSocket communication, it fails in the backend:
For the WebSocket client, it's better to simply fail, and avoid polluting users' logs. So here we simply return HTTP status code 403, and log in debug level that there was an unauthenticated request to WebSocket.
Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.