Skip to content

Commit

Permalink
updated the configurations and added method to check the allowed groups
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirujayathilake committed Aug 26, 2024
1 parent f241781 commit babfce3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions veda-app-samples/jupyterhub/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
environment:
OAUTH_CLIENT_ID: "veda-xxxxx-10000000"
OAUTH_CLIENT_SECRET: "xxxxxx"
JUPYTERHUB_CRYPT_KEY: "a99323294a5d6f9b1d0e7e33450dff44db664264231b985e069c6eba8f9a3e09"
volumes:
- ./jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py
- /var/run/docker.sock:/var/run/docker.sock
Expand Down
6 changes: 4 additions & 2 deletions veda-app-samples/jupyterhub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
c.VedaOAuthenticator.authorize_url = 'https://api.veda.usecustos.org/api/v1/identity-management/authorize'
c.VedaOAuthenticator.token_url = 'https://api.veda.usecustos.org/api/v1/identity-management/token'
c.VedaOAuthenticator.userdata_url = 'https://api.veda.usecustos.org/api/v1/user-management/userinfo'
c.VedaOAuthenticator.userdata_method = 'GET'
c.VedaOAuthenticator.userdata_token_method = 'GET'
c.VedaOAuthenticator.userdata_params = {"scope": "openid profile email"}
c.VedaOAuthenticator.username_key = 'email'
c.VedaOAuthenticator.username_claim = 'email'
c.Authenticator.enable_auth_state = True
c.VedaOAuthenticator.allow_all= True

# Set the required OAuth2 scopes
c.VedaOAuthenticator.scope = ['openid', 'profile', 'email']
Expand Down
7 changes: 7 additions & 0 deletions veda-app-samples/jupyterhub/veda_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class VedaOAuthenticator(OAuthenticator):
token_url = Unicode(config=True)
oauth_callback_url = Unicode(config=True)
scope = List(Unicode(), default_value=['openid', 'email', 'org.cilogon.userinfo'], config=True)
allowed_groups = List(Unicode(), default_value=['VedaHubAdmin', 'VedaHubEditor'], config=True)

@default("authorize_url")
def _authorize_url_default(self):
Expand Down Expand Up @@ -86,6 +87,12 @@ async def authenticate(self, handler, data=None):
app_log.error("Failed to decode JWT token: %s", str(e))
raise HTTPError(500, "Invalid token")

# Check user groups against allowed groups
user_groups = payload.get('groups', [])
if not any(group in self.allowed_groups for group in user_groups):
app_log.error("User %s is not in an allowed group", payload.get('preferred_username'))
raise HTTPError(403, f"User is not authorized to use this hub.")

userdict = {
"name": payload.get('preferred_username'),
"auth_state": {
Expand Down

0 comments on commit babfce3

Please sign in to comment.