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 Jan 17, 2024
1 parent edbf67a commit 4417ec8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions oauthenticator/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from tornado.httpclient import AsyncHTTPClient, HTTPClientError, HTTPRequest
from tornado.httputil import url_concat
from tornado.log import app_log
from traitlets import Any, Bool, Dict, List, Unicode, default, Union, Callable
from traitlets import Any, Bool, Callable, Dict, List, Unicode, Union, default


def guess_callback_uri(protocol, host, hub_server_url):
Expand Down Expand Up @@ -772,7 +772,6 @@ def user_info_to_username(self, user_info):
Called by the :meth:`oauthenticator.OAuthenticator.authenticate`
"""


if callable(self.username_claim):
username = self.username_claim(user_info)
else:
Expand Down
3 changes: 3 additions & 0 deletions oauthenticator/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,22 @@ async def test_generic(
else:
assert auth_model == None


async def test_username_claim_callable(
get_authenticator,
generic_client,
):
c = Config()
c.GenericOAuthenticator = Config()

def username_claim(user_info):
username = user_info["sub"]
if username.startswith("oauth2|cilogon"):
cilogon_sub = username.rsplit("|", 1)[-1]
cilogon_sub_parts = cilogon_sub.split("/")
username = f"oauth2|cilogon|{cilogon_sub_parts[3]}|{cilogon_sub_parts[5]}"
return username

c.GenericOAuthenticator.username_claim = username_claim
c.GenericOAuthenticator.allow_all = True
authenticator = get_authenticator(config=c)
Expand Down

0 comments on commit 4417ec8

Please sign in to comment.