Skip to content

Commit 174cf84

Browse files
author
Your Name
committed
fix(oidc): 占位用户username使用sub哈希避免唯一索引冲突
1 parent 3b6f52d commit 174cf84

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

backend/package/yuxi/services/oidc_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,13 @@ async def _create_oidc_binding_placeholder(db, sub: str, target_user: User) -> N
571571
random_password = secrets.token_urlsafe(32)
572572
password_hash = AuthUtils.hash_password(random_password)
573573

574+
# username 使用 oidc-binding-{sub_hash} 避免冲突,sub_hash 基于完整 sub 生成
575+
import hashlib
576+
sub_hash = hashlib.sha256(sub.encode()).hexdigest()[:8]
577+
username = f"oidc-binding-{sub_hash}"
578+
574579
placeholder_user = User(
575-
username=f"oidc-binding-{sub[:8]}",
580+
username=username,
576581
user_id=oidc_placeholder_id,
577582
phone_number=None,
578583
avatar=None,

0 commit comments

Comments
 (0)