Skip to content

Commit

Permalink
move userdata_url / userdata_from_id_token conflict to config validation
Browse files Browse the repository at this point in the history
rather than if attribute is defined
  • Loading branch information
minrk committed Feb 13, 2024
1 parent 12695d5 commit e6e68fd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions oauthenticator/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
from traitlets import Any, Bool, Dict, List, Unicode, default, validate


def guess_callback_uri(protocol, host, hub_server_url):
Expand Down Expand Up @@ -397,6 +397,14 @@ def _token_url_default(self):
def _userdata_url_default(self):
return os.environ.get("OAUTH2_USERDATA_URL", "")

@validate("userdata_url")
def _validate_userdata_url(self, proposal):
if proposal.value and self.userdata_from_id_token:
raise ValueError(
"Cannot specify both authenticator.userdata_url and authenticator.userdata_from_id_token."
)
return proposal.value

username_claim = Unicode(
"username",
config=True,
Expand Down Expand Up @@ -897,10 +905,6 @@ async def token_to_user(self, token_info):
"""
if self.userdata_from_id_token:
# Use id token instead of exchanging access token with userinfo endpoint.
if self.userdata_url:
raise ValueError(
"Cannot specify both authenticator.userdata_url and authenticator.userdata_from_id_token."
)
id_token = token_info.get("id_token", None)
if not id_token:
raise web.HTTPError(
Expand Down

0 comments on commit e6e68fd

Please sign in to comment.