Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 25, 2024
1 parent 86b5bdc commit b713281
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 7 additions & 4 deletions oauthenticator/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"""

import os
from functools import reduce

from jupyterhub.auth import LocalAuthenticator
from jupyterhub.traitlets import Callable
from tornado.httpclient import AsyncHTTPClient
from traitlets import Bool, Dict, Set, Unicode, Union, default, observe
from traitlets import Bool, Dict, Unicode, Union, default, observe

from .oauth2 import OAuthenticator

Expand Down Expand Up @@ -37,9 +36,13 @@ def _login_service_default(self):
def _claim_groups_key_changed(self, change):
if callable(change.new):
# Automatically wrap the claim_gorups_key call so it gets what it thinks it should get
self.auth_model_groups_key = lambda auth_model: self.claim_groups_key(auth_model["auth_state"][self.user_auth_state_key])
self.auth_model_groups_key = lambda auth_model: self.claim_groups_key(
auth_model["auth_state"][self.user_auth_state_key]
)
else:
self.auth_model_groups_key = f"auth_state.{self.user_auth_state_key}.{self.claim_groups_key}"
self.auth_model_groups_key = (
f"auth_state.{self.user_auth_state_key}.{self.claim_groups_key}"
)

@default("http_client")
def _default_http_client(self):
Expand Down
19 changes: 16 additions & 3 deletions oauthenticator/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import base64
import json
import os
from functools import reduce
import uuid
from functools import reduce
from urllib.parse import quote, urlencode, urlparse, urlunparse

import jwt
Expand All @@ -21,7 +21,18 @@
from tornado.httpclient import AsyncHTTPClient, HTTPClientError, HTTPRequest
from tornado.httputil import url_concat
from tornado.log import app_log
from traitlets import Any, Bool, Callable, Dict, List, Unicode, Union, default, Set, validate
from traitlets import (
Any,
Bool,
Callable,
Dict,
List,
Set,
Unicode,
Union,
default,
validate,
)


def guess_callback_uri(protocol, host, hub_server_url):
Expand Down Expand Up @@ -1047,7 +1058,9 @@ def get_user_groups(self, auth_model: dict):
if callable(self.claim_groups_key):
return set(self.auth_model_groups_key(auth_model))
try:
return set(reduce(dict.get, self.auth_model_groups_key.split("."), auth_model))
return set(
reduce(dict.get, self.auth_model_groups_key.split("."), auth_model)
)
except TypeError:
self.log.error(
f"The auth_model_groups_key {self.auth_model_groups_key} does not exist in the auth_model. Available keys are: {auth_model.keys()}"
Expand Down

0 comments on commit b713281

Please sign in to comment.