Skip to content

Commit 6fea5d8

Browse files
minrkpre-commit-ci[bot]Zsailer
authored
consolidate auth config on IdentityProvider (#825)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Zachary Sailer <[email protected]>
1 parent e4bf162 commit 6fea5d8

17 files changed

+1138
-250
lines changed

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ repos:
3333
rev: v0.961
3434
hooks:
3535
- id: mypy
36-
exclude: examples/simple/setup.py
3736
additional_dependencies: [types-requests]
3837

3938
- repo: https://github.com/pre-commit/mirrors-prettier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Jupyter login with system password
2+
3+
This `jupyter_server_config.py` defines and enables a `SystemPasswordIdentityProvider`.
4+
This IdentityProvider checks the entered password against your system password using PAM.
5+
Only the current user's password (the user the server is running as) is accepted.
6+
7+
The result is a User whose name matches the system user, rather than a randomly generated one.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pwd
2+
from getpass import getuser
3+
4+
from pamela import PAMError, authenticate
5+
6+
from jupyter_server.auth.identity import IdentityProvider, User
7+
8+
9+
class SystemPasswordIdentityProvider(IdentityProvider):
10+
# no need to generate a default token (token can still be used, but it's opt-in)
11+
need_token = False
12+
13+
def process_login_form(self, handler):
14+
username = getuser()
15+
password = handler.get_argument("password", "")
16+
try:
17+
authenticate(username, password)
18+
except PAMError as e:
19+
self.log.error(f"Failed login for {username}: {e}")
20+
return None
21+
22+
user_info = pwd.getpwnam(username)
23+
# get human name from pwd, if not empty
24+
return User(username=username, name=user_info.pw_gecos or username)
25+
26+
27+
c = get_config() # type: ignore # noqa
28+
29+
c.ServerApp.identity_provider_class = SystemPasswordIdentityProvider

0 commit comments

Comments
 (0)