mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
fail if external oauth service lacks required oauth_redirect_uri config
and log service creation with oauth enabled/disabled
This commit is contained in:
@@ -2501,6 +2501,11 @@ class JupyterHub(Application):
|
|||||||
if orm_service.oauth_client is not None:
|
if orm_service.oauth_client is not None:
|
||||||
service.oauth_client_id = orm_service.oauth_client.identifier
|
service.oauth_client_id = orm_service.oauth_client.identifier
|
||||||
service.oauth_redirect_uri = orm_service.oauth_client.redirect_uri
|
service.oauth_redirect_uri = orm_service.oauth_client.redirect_uri
|
||||||
|
oauth_msg = f"with ouath_client_id={orm_service.oauth_client.identifier}"
|
||||||
|
else:
|
||||||
|
oauth_msg = "without oauth"
|
||||||
|
|
||||||
|
self.log.info(f"Loaded service {service.name} from database {oauth_msg}.")
|
||||||
|
|
||||||
self._service_map[name] = service
|
self._service_map[name] = service
|
||||||
|
|
||||||
@@ -2626,6 +2631,15 @@ class JupyterHub(Application):
|
|||||||
service.orm.server = None
|
service.orm.server = None
|
||||||
|
|
||||||
if service.oauth_available:
|
if service.oauth_available:
|
||||||
|
self.log.info(
|
||||||
|
f"Creating service {service.name} with oauth_client_id={service.oauth_client_id}"
|
||||||
|
)
|
||||||
|
if not service.oauth_redirect_uri:
|
||||||
|
# redirect uri has a default value if a URL is configured,
|
||||||
|
# but must be specified explicitly for external services
|
||||||
|
raise ValueError(
|
||||||
|
f"Service {service.name} has oauth configured, but is missing required oauth_redirect_uri."
|
||||||
|
)
|
||||||
allowed_scopes = set()
|
allowed_scopes = set()
|
||||||
if service.oauth_client_allowed_scopes:
|
if service.oauth_client_allowed_scopes:
|
||||||
allowed_scopes.update(service.oauth_client_allowed_scopes)
|
allowed_scopes.update(service.oauth_client_allowed_scopes)
|
||||||
@@ -2655,7 +2669,11 @@ class JupyterHub(Application):
|
|||||||
allowed_scopes.update(scopes.access_scopes(oauth_client))
|
allowed_scopes.update(scopes.access_scopes(oauth_client))
|
||||||
oauth_client.allowed_scopes = sorted(allowed_scopes)
|
oauth_client.allowed_scopes = sorted(allowed_scopes)
|
||||||
else:
|
else:
|
||||||
|
self.log.info(f"Creating service {service.name} without oauth.")
|
||||||
if service.oauth_client:
|
if service.oauth_client:
|
||||||
|
self.log.warning(
|
||||||
|
f"Deleting unused oauth client for service {service.name} with client_id={service.oauth_client.identifier}"
|
||||||
|
)
|
||||||
self.db.delete(service.oauth_client)
|
self.db.delete(service.oauth_client)
|
||||||
|
|
||||||
self._service_map[name] = service
|
self._service_map[name] = service
|
||||||
|
@@ -54,6 +54,7 @@ from traitlets import (
|
|||||||
List,
|
List,
|
||||||
Unicode,
|
Unicode,
|
||||||
default,
|
default,
|
||||||
|
observe,
|
||||||
validate,
|
validate,
|
||||||
)
|
)
|
||||||
from traitlets.config import LoggingConfigurable
|
from traitlets.config import LoggingConfigurable
|
||||||
@@ -306,6 +307,7 @@ class Service(LoggingConfigurable):
|
|||||||
cookie_options = Dict()
|
cookie_options = Dict()
|
||||||
|
|
||||||
oauth_provider = Any()
|
oauth_provider = Any()
|
||||||
|
_oauth_specified = List(help="List of oauth config fields specified via config.")
|
||||||
|
|
||||||
oauth_client_id = Unicode(
|
oauth_client_id = Unicode(
|
||||||
help="""OAuth client ID for this service.
|
help="""OAuth client ID for this service.
|
||||||
@@ -342,12 +344,20 @@ class Service(LoggingConfigurable):
|
|||||||
return ''
|
return ''
|
||||||
return self.host + url_path_join(self.prefix, 'oauth_callback')
|
return self.host + url_path_join(self.prefix, 'oauth_callback')
|
||||||
|
|
||||||
|
@observe("oauth_client_id", "oauth_redirect_uri")
|
||||||
|
def _oauth_config_set(self, change):
|
||||||
|
# record that some oauth config is specified
|
||||||
|
self._oauth_specified.append(change.name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def oauth_available(self):
|
def oauth_available(self):
|
||||||
"""Is OAuth available for this client?
|
"""Is OAuth available for this client?
|
||||||
|
|
||||||
Returns True if a server is defined or oauth_redirect_uri is specified manually
|
Returns True if a server is defined or oauth_redirect_uri is specified manually
|
||||||
"""
|
"""
|
||||||
|
if self._oauth_specified:
|
||||||
|
# if any oauth config is set, oauth should be available
|
||||||
|
return True
|
||||||
return bool(self.server is not None or self.oauth_redirect_uri)
|
return bool(self.server is not None or self.oauth_redirect_uri)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Reference in New Issue
Block a user