Skip to content

Commit 7c8912a

Browse files
Implement oidc userinfo and attempt hardcoded rubin group settings
1 parent 8dd7c9c commit 7c8912a

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

service/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def authnz_for_authenticator():
7979
#api.add_resource(OIDCMetadataResource, '/v3/oauth2/.well-known/openid-configuration')
8080
api.add_resource(OIDCjwksResource, '/v3/oauth2/jwks')
8181
api.add_resource(OIDCTokensResource, '/v3/oauth2/tokens/oidc')
82+
api.add_resource(OIDCUserInfoResource, '/v3/oauth2/userinfo/oidc')
8283

8384
# Auth server resources
8485
api.add_resource(AuthorizeResource, '/v3/oauth2/authorize')

service/controllers.py

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,55 @@ def get(self):
203203
return resp
204204

205205

206+
def _handle_userinfo_request(request, oidc=False):
207+
if oidc:
208+
logger.debug(f'top of GET /v3/oauth2/userinfo/oidc')
209+
else:
210+
logger.debug(f'top of GET /v3/oauth2/userinfo')
211+
tenant_id = g.request_tenant_id
212+
# note that the user info endpoint is more limited for custom oauth idp extensions in general because the
213+
# custom OAuth server may not provide a profile endpoint.
214+
custom_oa2_extension_type = tenant_configs_cache.get_custom_oa2_extension_type(tenant_id=tenant_id)
215+
216+
## token should maybe already have:
217+
# jti iss sub exp tapis/tenant_id tapis/token_type
218+
# tapis/delegation tapis/delegation_sub tapis/username
219+
# tapis/account_type tapis/client_id tapis/grant_type
220+
221+
if custom_oa2_extension_type and not custom_oa2_extension_type == 'ldap':
222+
result = {"username": g.username}
223+
return utils.ok(result=result, msg="User profile retrieved successfully.")
224+
225+
userinfo = get_tenant_user(tenant_id=tenant_id, username=g.username)
226+
227+
## Rubin Science place needs
228+
# rubin scope with info via data_rights
229+
# adding data rights for specific users for rubin - test
230+
logger.debug(f"userinfo: {userinfo}")
231+
if oidc and hasattr(userinfo, 'username'):
232+
if userinfo.username in ["cgarcia", "mpackard", "kprice", "jstubbs"]:
233+
data_rights = get_user_data_rights(user)
234+
if data_rights:
235+
userinfo["data_rights"] = " ".join(data_rights)
236+
237+
return utils.ok(result=userinfo.serialize, msg="User profile retrieved successfully.")
238+
239+
240+
def get_user_data_rights(user):
241+
# Implement logic to retrieve the list of data releases the user has access to
242+
# This function should return a list of strings representing data releases
243+
return ["release1", "release2", "lsst-sqre", "admin:jupyterlab", "admin", "jupyterlab", "square", "tacc-spherex"]
244+
245+
206246
class UserInfoResource(Resource):
207247
def get(self):
208-
logger.debug(f'top of GET /v3/oauth2/userinfo')
209-
tenant_id = g.request_tenant_id
210-
# note that the user info endpoint is more limited for custom oauth idp extensions in general because the
211-
# custom OAuth server may not provider a profile endpoint.
212-
custom_oa2_extension_type = tenant_configs_cache.get_custom_oa2_extension_type(tenant_id=tenant_id)
213-
if custom_oa2_extension_type and not custom_oa2_extension_type == 'ldap':
214-
result = {"username": g.username}
215-
return utils.ok(result=result, msg="User profile retrieved successfully.")
248+
return _handle_userinfo_request(request, oidc=False)
249+
250+
251+
class OIDCUserInfoResource(Resource):
252+
def get(self):
253+
return _handle_userinfo_request(request, oidc=True)
216254

217-
user = get_tenant_user(tenant_id=tenant_id, username=g.username)
218-
return utils.ok(result=user.serialize, msg="User profile retrieved successfully.")
219255

220256

221257
class ProfileResource(Resource):

0 commit comments

Comments
 (0)