-
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
Extend userprofile endpoint with all data on the current user from Jupyter Server #510
Extend userprofile endpoint with all data on the current user from Jupyter Server #510
Conversation
Tests for this part of the code are in test_handlers.py and test_auth.py. There is a test to check whats returned from this endpoint contains the 'name' field so Im not sure it needs anything more than that |
After discussion with @oliver-sanders : --suggest-- |
Sadly, when token authenticated, Jupyter Server appears to set:
Which isn't helpful for what we're trying to achieve. In Cylc we make the assumption that the bearer of the token is the user the server is running as. This isn't technically true, you could give another user your token, however, this is how it's intended to work. |
If not authenticated: username "ae507119171a4306bb631b4b01d5ed82" name "ae507119171a4306bb631b4b01d5ed82" display_name "Anonymous Herse" initials "AH" If authenticated and have a . in username username "m.dawson" name "m.dawson" display_name "Anonymous Herse" initials "MD" If authenticated and dont have a . in username username "mdawson" name "mdawson" display_name "Anonymous Herse" initials "M"
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #510 +/- ##
==========================================
- Coverage 75.42% 74.80% -0.62%
==========================================
Files 12 12
Lines 1428 1437 +9
Branches 236 239 +3
==========================================
- Hits 1077 1075 -2
- Misses 301 309 +8
- Partials 50 53 +3
☔ View full report in Codecov by Sentry. |
Return empty string for initials if user is not authenticated then on the front end if there is no value for initials we can show a user edit icon. Also changed the way in whic initials were calculated if there is a '.' to ensure only first character of the first name is taken
Surely this can't be "not authenticated", as someone who is not authenticated (either by a token or logging on in Jupyter Hub) cannot access the app? Are you talking about the token authenticated case which seems similar to Oliver's comment:
|
Or is it for the case that a site has turned off authentication in the Cylc UIServer config? |
This is the related change in the uiserver code |
That is someone who is not token authenticated, so presumably password authenticated? |
The user has to be authenticated (the |
So then in what circumstance do you get this?
|
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.
Good. Got a couple of suggestions to tidy the code a little
…pyter Server (cylc#510) Extend userprofile endpoint with all data on the current user from Jupyter Server
Closes cylc/cylc-ui#1504
Extends the userprofile endpoint to provide all the fields on current_user.
This is required for cylc/cylc-ui#1505
Available data
Available data Single user mode
In single user mode the user is authenticated with a bearer token. Inside the UserProfileHandler a function
is_token_authenticated
will return True.In this case jupyter server knows no info about the user, so handler.current_user is populated with values that are not helpful:
Available data Multi user / hub mode
In multiuser (hub) mode the user provides a username and password to the server for auth. Inside the UserProfileHandler a function
is_token_authenticated
will return False. In this case the jupyter server knows the users username so uses that for populating handler.current_user.Note: initials set to none
This is what we have to work with to try and send some useful data back to the
/user-profile/
endpoint.The approach
The username used for hub login depends on how jupyterhub is configured and can potentially accept more than one value. For example
jsmith
and[email protected]
may both be valid.An alternative method for attaining a name for the user is to get it from the operating system using getpass (
ME = getpass.getuser()
) .Approach for Multi user / hub mode
Use the username that can be accessed through jupyter on
handler.current_user
.Calculate a value for the initials field.
Approach for Single user
Get a username from the OS
Calculate a value for the initials field.
Example responses
If authenticated and have a
.
in usernameIf authenticated and dont have a
.
in usernamehttps://jupyter-server.readthedocs.io/en/latest/operators/security.html#jupyter_server.auth.User
Check List
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
(andconda-environment.yml
if present).CHANGES.md
entry included if this is a change that can affect users - Not added but can do if required??.?.x
branch.