|
@@ -135,7 +135,7 @@ class OAuthService:
|
|
|
return token
|
|
return token
|
|
|
|
|
|
|
|
async def get_user_info(self, user_id: str, scope: list) -> Optional[Dict[str, Any]]:
|
|
async def get_user_info(self, user_id: str, scope: list) -> Optional[Dict[str, Any]]:
|
|
|
- """获取用户信息(根据scope过滤)"""
|
|
|
|
|
|
|
+ """获取用户信息(根据scope过滤),包含角色信息"""
|
|
|
conn = get_db_connection()
|
|
conn = get_db_connection()
|
|
|
if not conn:
|
|
if not conn:
|
|
|
return None
|
|
return None
|
|
@@ -157,8 +157,22 @@ class OAuthService:
|
|
|
if not user_data:
|
|
if not user_data:
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
+ # 查询用户角色(同时返回 name 和 code)
|
|
|
|
|
+ cursor.execute("""
|
|
|
|
|
+ SELECT r.name, r.code
|
|
|
|
|
+ FROM t_sys_role r
|
|
|
|
|
+ INNER JOIN t_sys_user_role ur ON r.id = ur.role_id
|
|
|
|
|
+ WHERE ur.user_id = %s
|
|
|
|
|
+ AND ur.is_active = 1
|
|
|
|
|
+ AND r.is_active = 1
|
|
|
|
|
+ AND (ur.expires_at IS NULL OR ur.expires_at > NOW())
|
|
|
|
|
+ """, (user_id,))
|
|
|
|
|
+
|
|
|
|
|
+ role_rows = cursor.fetchall()
|
|
|
|
|
+ roles = [{"name": row["name"], "code": row["code"]} for row in role_rows]
|
|
|
|
|
+
|
|
|
# 构建用户信息响应(根据scope过滤)
|
|
# 构建用户信息响应(根据scope过滤)
|
|
|
- user_info = {"sub": user_data["id"]}
|
|
|
|
|
|
|
+ user_info = {"sub": user_data["id"], "roles": roles}
|
|
|
|
|
|
|
|
if "profile" in scope:
|
|
if "profile" in scope:
|
|
|
user_info.update({
|
|
user_info.update({
|