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

Rework noauth #62

Merged
merged 4 commits into from
Sep 21, 2021
Merged

Conversation

davidbrochart
Copy link
Collaborator

Implement authentication backend for no-auth.
Not functional yet, cc @frankie567.

@davidbrochart davidbrochart marked this pull request as draft September 21, 2021 10:15
Copy link
Contributor

@frankie567 frankie567 left a comment

Choose a reason for hiding this comment

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

I took the liberty to leave some comments 😊 I think we're on the right track here to handle the different auth modes.

As I mention in one comment, I think this approach could also be expanded to work with token mode.

plugins/auth/fps_auth/backends.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/backends.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/backends.py Outdated Show resolved Hide resolved
plugins/auth/fps_auth/backends.py Outdated Show resolved Hide resolved
@@ -17,7 +17,7 @@
from fps.hooks import register_router # type: ignore

from fps_auth.db import get_user_db # type: ignore
from fps_auth.routes import ( # type: ignore
from fps_auth.backends import ( # type: ignore
current_user,
cookie_authentication,
LoginCookieAuthentication,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you are implementing a kind of login endpoint for token authentication mode. IMO, this should also be a custom authentication backend that would check for a static token in query params and return a static user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually the mechanism for token authentication is that when you access the root endpoint with the token as a query parameter, the server will set a cookie so that you don't have to pass the token again in next accesses (this is the default behavior for jupyter-server). I'm not sure how we could implement that differently. Maybe you have ideas?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I think I see what you mean, we should check for this token in query parameters for all endpoints, and thus have a special authentication back-end for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, if the goal is to set a cookie, then what you did is indeed a good solution.

I thought the token was required to be passed on each request (like a REST API), in which case, a custom auth backend would have been more appropriate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes but still, we should allow the token to be passed on any endpoint, not just the root endpoint. I tried playing with a TokenAuthentication class, but then I was faced with the problem of getting the token as a query parameter, and basically didn't know where to get it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The key is to use the security schemes of FastAPI: there is one for most common cases. In this case, APIKeyQuery seems a good candidate: name argument is the name of your query parameter to read the token from.

It's also important to set auto_error to False to prevent the scheme from raising a 403 when the value is not present: FastAPI Users needs this to try several backends before raising an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll keep that for a next PR, thanks.

@davidbrochart
Copy link
Collaborator Author

Thanks for the review @frankie567, I'll push another commit with the changes you suggested.

@davidbrochart davidbrochart marked this pull request as ready for review September 21, 2021 16:20
@davidbrochart davidbrochart merged commit 6ea4e14 into jupyter-server:main Sep 21, 2021
@davidbrochart davidbrochart deleted the rework_noauth branch September 21, 2021 16:20
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