fix(oauth): 支持 Casdoor 认证,修复第三方回调的用户id为string时会导致服务器内部错误的问题 (#46)

* fix(oauth): support Casdoor string user IDs

* test(oauth): verify legacy IDs and auth source isolation

---------

Co-authored-by: Noru Wyrms <wyrmsnoru@gmail.com>
This commit is contained in:
velor2012
2026-10-08 08:20:15 +08:00
committed by GitHub
parent 6f63715182
commit fec9bd18dd
6 changed files with 173 additions and 26 deletions
+1 -16
View File
@@ -6,7 +6,6 @@ package model
import (
"errors"
"strconv"
"strings"
"time"
@@ -15,8 +14,8 @@ import (
)
// OAuthUserInfo 用户信息结构(同时支持 OIDC ID Token claims 和 UserEndpoint 响应)
// 第三方身份使用 Sub;忽略非标准 id 字段,本地用户 ID 独立生成。
type OAuthUserInfo struct {
ID uint64 `json:"id"`
Sub string `json:"sub"`
Username string `json:"username"`
PreferredUsername string `json:"preferred_username"`
@@ -26,20 +25,6 @@ type OAuthUserInfo struct {
AvatarURL string `json:"avatar_url"`
}
// GetID 获取用户 ID
func (u *OAuthUserInfo) GetID() uint64 {
if u.ID != 0 {
return u.ID
}
// 从 sub 解析(OIDC 格式)
if u.Sub != "" {
if id, err := strconv.ParseUint(u.Sub, 10, 64); err == nil {
return id
}
}
return 0
}
// User 用户表实体
type User struct {
ID uint64 `json:"id,string" gorm:"primaryKey;not null"`