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

Login page #75

Merged
merged 8 commits into from
Oct 18, 2021
Merged

Login page #75

merged 8 commits into from
Oct 18, 2021

Conversation

hbcarlos
Copy link
Contributor

@hbcarlos hbcarlos commented Sep 23, 2021

Added a new plugin that registers a new endpoint for the login page.

The login page has three ways of login, GitHub, token or anonymous.

The GitHub login throws a server error when redirecting, looks like the error comes from FastAPI Users when it tries to retrieve the user information from GitHub. I'll debug tomorrow.

Regarding the login with the token, I'm not sure how it works.

Screenshot from 2021-09-23 19-22-51

@welcome
Copy link

welcome bot commented Sep 23, 2021

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@davidbrochart
Copy link
Collaborator

The GitHub login throws a server error when redirecting, looks like the error comes from FastAPI Users when it tries to retrieve the user information from GitHub. I'll debug tomorrow.

It works on my side. You need to pass your client_id and client_secret e.g. on the command line:

jupyverse --authenticator.client_id=my_client_id --authenticator.client_secret=my_client_secret

@hbcarlos
Copy link
Contributor Author

Thanks, @davidbrochart! I was using the conf.toml as explained in the jupyverse-auth extension.

@davidbrochart
Copy link
Collaborator

Thanks, @davidbrochart! I was using the conf.toml as explained in the jupyverse-auth extension.

It should work too.

@hbcarlos
Copy link
Contributor Author

How do the token works? How can I redirect the user to /lab adding the token provided by the user?

@davidbrochart
Copy link
Collaborator

davidbrochart commented Sep 24, 2021

It should work out of the box with FastAPI-Users, provided that you configured your GitHub OAuth App correctly:
image

@hbcarlos
Copy link
Contributor Author

I have the correct callback URL, and it fails.
I think the error is because the app doesn't have enough permissions. When granting permission to Jupyverse to read my GitHub profile, it only asks for permission to read public information of my profile (my email is private). Then when logging in, there is an error when FastAPI_users tries to retrieve my email.

@hbcarlos

This comment has been minimized.

@hbcarlos
Copy link
Contributor Author

Tests are failing because instead of returning 404 when the user doesn't have permissions, we redirect to the logging page, which returns a 200.

@hbcarlos
Copy link
Contributor Author

Changed test to check if the server returns an HTML page instead of the 404.

@hbcarlos hbcarlos marked this pull request as ready for review September 24, 2021 20:53
Copy link
Collaborator

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks great @hbcarlos !
On thing though, anonymous login doesn't seem to work for me (no effect when clicking), but maybe it's for a next PR?

plugins/login/fps_login/static/index.html Outdated Show resolved Hide resolved
tests/test_auth.py Outdated Show resolved Hide resolved
@hbcarlos
Copy link
Contributor Author

I can take a look at anonymous login on this PR too, should be an easy fix.

@hbcarlos
Copy link
Contributor Author

Regarding the anonymous login, when using the flag --authenticator.mode=noauth automatically redirects to /lab without showing the login page. And if we use user or token, clicking in the anonymous link redirects to /lab in the login page, but we don't have permission, so we are redirected to the login page again.

@davidbrochart
Copy link
Collaborator

Regarding the anonymous login, when using the flag --authenticator.mode=noauth automatically redirects to /lab without showing the login page.

Yes, that's the expected behavior.

And if we use user or token, clicking in the anonymous link redirects to /lab in the login page, but we don't have permission, so we are redirected to the login page again.

That's because we first have to register the anonymous user.

@hbcarlos
Copy link
Contributor Author

Oooh, got it. I'll implement it on this PR.

@hbcarlos
Copy link
Contributor Author

I've been looking into the anonymous user, and I don't think it is the right approach to the problem.
With this solution, we don't have an anonymous user. We are just registering a new user with random values.
The proper solution would be to let users in and assign a cookie to identify them but not register them in the database.

@davidbrochart
Copy link
Collaborator

davidbrochart commented Sep 26, 2021

With this solution, we don't have an anonymous user. We are just registering a new user with random values.

Yes, the system is user-based, even if it's not a "real" user. The token user is also a user, with a token as his ID.

The proper solution would be to let users in and assign a cookie to identify them but not register them in the database.

But then other users won't be able to "see" anonymous users? For me, an anonymous user is just a regular user (maybe with less permissions) who didn't want to bother registering himself. There is no reason for him not to be in the database.

@hbcarlos
Copy link
Contributor Author

Thanks, @davidbrochart. You are right.
We need to identify anonymous users somehow. Even if they don't have an identity, we need to know who is connected.

Can we merge this PR and open a new one to tackle the role-based access control? That would make it much easier to know what every user can do.

@davidbrochart
Copy link
Collaborator

Since there are quite a lot of changes in this last commit, could you explain a bit?

@hbcarlos
Copy link
Contributor Author

hbcarlos commented Oct 6, 2021

Yes, yes. It would be best to chat and show you the code because I changed everything even though it was fine. Sorry for that.

@davidbrochart
Copy link
Collaborator

Sure, but it's also nice to have it written here, even a summary. At a high-level, what are you trying to achieve?

@hbcarlos hbcarlos marked this pull request as draft October 6, 2021 14:01
@hbcarlos
Copy link
Contributor Author

hbcarlos commented Oct 6, 2021

Okay, I'll write it tomorrow. I need to do some more changes.

Copy link
Collaborator

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC both noauth and token authentication modes use the same "guest user"? I like that because it solves the settings persistence issue mentioned in #61 (comment).

plugins/login/fps_login/static/index.html Outdated Show resolved Hide resolved
plugins/auth/fps_auth/backends.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/routes.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/routes.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/routes.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/routes.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/routes.py Outdated Show resolved Hide resolved
@hbcarlos
Copy link
Contributor Author

I'm not sure why the Check release is failing.

ERROR: Could not find a version that satisfies the requirement fps-login (from jupyverse) (from versions: none)
ERROR: No matching distribution found for fps-login

@hbcarlos
Copy link
Contributor Author

hbcarlos commented Oct 14, 2021

The test in windows fails because we use termios doesn't work on Windows. How is it possible that the test didn't fail in other PRs?

https://stackoverflow.com/a/52063932

@davidbrochart
Copy link
Collaborator

How is it possible that the test didn't fail in other PRs?

We don't install fps-terminals in the main branch.

@hbcarlos
Copy link
Contributor Author

Thanks, @davidbrochart!

It is still missing the check release test that I don't know why it is failing.

@davidbrochart
Copy link
Collaborator

I think we can ignore that, as fps-login has not been published on PyPI yet.

@hbcarlos
Copy link
Contributor Author

What is missing to merge this PR and continue with Authorization?

README.md Outdated Show resolved Hide resolved
tests/test_auth.py Outdated Show resolved Hide resolved
tests/test_auth.py Outdated Show resolved Hide resolved
plugins/login/pyproject.toml Outdated Show resolved Hide resolved
plugins/login/fps_login/__init__.py Outdated Show resolved Hide resolved
@davidbrochart
Copy link
Collaborator

The CI failure is caused by FPS master, see jupyter-server/fps#49.
cc @adriendelsalle

expected = 200
content_type = "text/html; charset=utf-8"
if auth_mode in ["token", "user"]:
expected = 404
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to return a 401 when no login plugin is installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that depends on auth_config.login_url if it exists, will always redirect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that's the responsibility of the user, if they set a login_url without installing a login plugin, it's a 404, otherwise it's a 401?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the login_url is in fps_auth config and defaults to /login. Is there a way to default to None and then the fps_login plugin modifies the auth_config to set the desired URL?

@davidbrochart davidbrochart merged commit b03b142 into jupyter-server:main Oct 18, 2021
@welcome
Copy link

welcome bot commented Oct 18, 2021

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

@davidbrochart
Copy link
Collaborator

Thanks @hbcarlos !

@hbcarlos hbcarlos deleted the login branch October 18, 2021 12:38
This was referenced Oct 18, 2021
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

Successfully merging this pull request may close these issues.

2 participants