Skip to content

Commit ee6ec00

Browse files
committed
Handling logout
1 parent 2e3992d commit ee6ec00

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

docker-compose.dev.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ services:
6767

6868
postgres:
6969
image: postgres
70+
networks:
71+
- clowder2
7072
volumes:
7173
- postgres_data:/var/lib/postgresql/data
7274
environment:
@@ -79,6 +81,8 @@ services:
7981
volumes:
8082
- ./scripts/keycloak/clowder-realm-dev.json:/opt/keycloak/data/import/realm.json:ro
8183
- ./scripts/keycloak/clowder-theme/:/opt/keycloak/themes/clowder-theme/:ro
84+
networks:
85+
- clowder2
8286
command:
8387
- start-dev
8488
- --http-relative-path /keycloak

jupyterhub/.env-example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ DOCKER_NETWORK_NAME="clowder2"
1010
DOCKER_NOTEBOOK_IMAGE="quay.io/jupyter/base-notebook:latest"
1111
DOCKER_NOTEBOOK_DIR="/home/jovyan/work"
1212
JUPYTERHUB_CRYPT_KEY=""
13+
CLOWDER_URL="localhost:3000"
14+
PROD_DEPLOYMENT="false"

jupyterhub/authenticator/customauthenticator/custom.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class CustomTokenAuthenticator(Authenticator):
3434
help="the landing page login entry",
3535
)
3636

37+
landing_page_logout_url = Unicode(
38+
os.environ.get("LANDING_PAGE_LOGOUT", ""),
39+
config=True,
40+
help="the landing page logout entry",
41+
)
42+
3743
keycloak_url = Unicode(
3844
os.environ.get("KEYCLOAK_URL", ""),
3945
config=True,
@@ -229,9 +235,9 @@ class CustomTokenLogoutHandler(LogoutHandler):
229235
async def handle_logout(self):
230236
# remove clowder token on logout
231237
self.log.info("Remove clowder token on logout")
232-
error_msg = (
238+
self.log.info(
233239
"You have logged out of Clowder system from Clowder . Please login again if you want to use "
234240
"Clowder components."
235241
)
236242
self.set_cookie(self.authenticator.auth_cookie_header, "")
237-
self.redirect(f"{self.authenticator.landing_page_login_url}?error={error_msg}")
243+
self.redirect(f"{self.authenticator.landing_page_logout_url}")

jupyterhub/jupyterhub_config.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,36 @@
5959
c.KubeSpawner.args = ["--allow-root"]
6060
c.JupyterHub.authenticator_class = CustomTokenAuthenticator
6161
# TODO:Change this keycloak_url as required
62-
c.CustomTokenAuthenticator.keycloak_url = "http://%s/realms/%s/" % (
63-
os.getenv("KEYCLOAK_HOSTNAME"),
64-
os.getenv("KEYCLOAK_REALM"),
65-
)
62+
6663
c.CustomTokenAuthenticator.auth_cookie_header = "Authorization"
6764
c.CustomTokenAuthenticator.auth_username_key = "preferred_username"
6865
c.CustomTokenAuthenticator.auth_uid_number_key = "uid_number"
6966
c.CustomTokenAuthenticator.enable_auth_state = True
7067
c.CustomTokenAuthenticator.auto_login = True
71-
c.CustomTokenAuthenticator.landing_page_login_url = "https://" + os.getenv(
72-
"KEYCLOAK_HOSTNAME"
73-
)
68+
69+
if os.getenv("PROD_DEPLOYMENT") == "true":
70+
c.CustomTokenAuthenticator.keycloak_url = "https://%s/realms/%s/" % (
71+
os.getenv("KEYCLOAK_HOSTNAME"),
72+
os.getenv("KEYCLOAK_REALM"),
73+
)
74+
c.CustomTokenAuthenticator.landing_page_login_url = "https://" + os.getenv(
75+
"KEYCLOAK_HOSTNAME"
76+
)
77+
c.CustomTokenAuthenticator.landing_page_logout_url = (
78+
"https://" + os.getenv("CLOWDER_URL") + "/auth/logout"
79+
)
80+
81+
else:
82+
c.CustomTokenAuthenticator.keycloak_url = "http://%s/realms/%s/" % (
83+
os.getenv("KEYCLOAK_HOSTNAME"),
84+
os.getenv("KEYCLOAK_REALM"),
85+
)
86+
c.CustomTokenAuthenticator.landing_page_login_url = "http://" + os.getenv(
87+
"KEYCLOAK_HOSTNAME"
88+
)
89+
c.CustomTokenAuthenticator.landing_page_logout_url = (
90+
"http://" + os.getenv("CLOWDER_URL") + "/auth/logout"
91+
)
7492

7593
c.JupyterHub.cookie_secret = os.getenv("JUPYTERHUB_CRYPT_KEY")
7694

0 commit comments

Comments
 (0)