Skip to content

Commit 8111795

Browse files
committed
Fix: Pass token_info dict instead of token string to get_user_roles
1 parent 2c02851 commit 8111795

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

api/utils/keycloak_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,19 @@ def get_user_roles(self, token_info: dict) -> list[str]:
122122

123123
return roles
124124

125-
def get_user_organizations(self, token: str) -> List[Dict[str, Any]]:
125+
def get_user_organizations(self, token_info: dict) -> List[Dict[str, Any]]:
126126
"""
127-
Get the organizations a user belongs to from their token.
127+
Get the organizations a user belongs to from their token info.
128128
This assumes that organization information is stored in the token
129129
as client roles or in user attributes.
130130
131131
Args:
132-
token: The user's token
132+
token_info: The decoded token information
133133
134134
Returns:
135135
List of organization information
136136
"""
137137
try:
138-
# Decode the token to get user info
139-
token_info = self.keycloak_openid.decode_token(token)
140-
141138
# Get organization info from resource_access or attributes
142139
# This implementation depends on how organizations are represented in Keycloak
143140
# This is a simplified example - adjust based on your Keycloak configuration

api/views/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ def post(self, request: Request) -> Response:
3232
status=status.HTTP_401_UNAUTHORIZED,
3333
)
3434

35+
# Get token introspection data for roles and organizations
36+
token_info = keycloak_manager.keycloak_openid.introspect(keycloak_token)
37+
3538
# Get user roles and organizations from the token
36-
roles = keycloak_manager.get_user_roles(keycloak_token)
37-
organizations = keycloak_manager.get_user_organizations(keycloak_token)
39+
roles = keycloak_manager.get_user_roles(token_info)
40+
organizations = keycloak_manager.get_user_organizations(token_info)
3841

3942
# Sync the user information with our database
4043
user = keycloak_manager.sync_user_from_keycloak(user_info, roles, organizations)

0 commit comments

Comments
 (0)