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

consolidate auth config on IdentityProvider #825

Merged
merged 17 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ repos:
rev: v0.961
hooks:
- id: mypy
exclude: examples/simple/setup.py
additional_dependencies: [types-requests]

- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
7 changes: 7 additions & 0 deletions examples/identity/system_password/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Jupyter login with system password

This `jupyter_server_config.py` defines and enables a `SystemPasswordIdentityProvider`.
This IdentityProvider checks the entered password against your system password using PAM.
Only the current user's password (the user the server is running as) is accepted.

The result is a User whose name matches the system user, rather than a randomly generated one.
29 changes: 29 additions & 0 deletions examples/identity/system_password/jupyter_server_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pwd
from getpass import getuser

from pamela import PAMError, authenticate

from jupyter_server.auth.identity import IdentityProvider, User


class SystemPasswordIdentityProvider(IdentityProvider):
# no need to generate a default token (token can still be used, but it's opt-in)
need_token = False

def process_login_form(self, handler):
username = getuser()
password = handler.get_argument("password", "")
try:
authenticate(username, password)
except PAMError as e:
self.log.error(f"Failed login for {username}: {e}")
return None

user_info = pwd.getpwnam(username)
# get human name from pwd, if not empty
return User(username=username, name=user_info.pw_gecos or username)


c = get_config() # type: ignore # noqa

c.ServerApp.identity_provider_class = SystemPasswordIdentityProvider
Loading