auth0 provider if reusing client will ensure callback url exists
import os
+import logging
from auth0.v3.management import Auth0
from auth0.v3.authentication import GetToken
+logger = logging.getLogger(__name__)
+
def create_client(jupyterhub_endpoint, project_name, reuse_existing=True):
for variable in {"AUTH0_DOMAIN", "AUTH0_CLIENT_ID", "AUTH0_CLIENT_SECRET"}:
@@ -19,10 +22,21 @@ def create_client(jupyterhub_endpoint, project_name, reuse_existing=True):
auth0 = Auth0(os.environ["AUTH0_DOMAIN"], mgmt_api_token)
+ oauth_callback_url = f"https://{jupyterhub_endpoint}/hub/oauth_callback"
+
for client in auth0.clients.all(
- fields=["name", "client_id", "client_secret"], include_fields=True
+ fields=["name", "client_id", "client_secret", "callbacks"], include_fields=True
):
if client["name"] == project_name and reuse_existing:
+ if oauth_callback_url not in client["callbacks"]:
+ logger.info(
+ f"updating existing application={project_name} client_id={client['client_id']} adding callback url={oauth_callback_url}"
+ )
+ auth0.clients.update(
+ client["client_id"],
+ {"callbacks": client["callbacks"] + [oauth_callback_url]},
+ )
+
return {
"auth0_subdomain": ".".join(os.environ["AUTH0_DOMAIN"].split(".")[:-2]),
"client_id": client["client_id"],
