Skip to content

Commit b8bb806

Browse files
committed
ENGAGE-132 fix analytics api role parsing
1 parent aa9d0dc commit b8bb806

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

analytics-api/src/analytics_api/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ def setup_jwt_manager(app_context, jwt_manager):
9393
"""Use flask app to configure the JWTManager to work for a particular Realm."""
9494

9595
def get_roles(a_dict):
96-
return a_dict['realm_access']['roles'] # pragma: no cover
96+
"""Extract user roles from Keycloak token."""
97+
# Realm roles
98+
roles = a_dict.get('realm_access', {}).get('roles', [])
99+
# Resource roles for epic-engage
100+
keycloak_client = app_context.config.get('KEYCLOAK_CLIENT_ID', 'epic-engage')
101+
resource_roles = a_dict.get('resource_access', {}).get(keycloak_client, {}).get('roles', [])
102+
# Combine and remove duplicates
103+
all_roles = set(roles + resource_roles)
104+
return list(all_roles)
97105

98106
app_context.config['JWT_ROLE_CALLBACK'] = get_roles
99107
jwt_manager.init_app(app_context)

0 commit comments

Comments
 (0)