diff --git a/internal/db/user.go b/internal/db/user.go index 06d2f76..711fbd4 100644 --- a/internal/db/user.go +++ b/internal/db/user.go @@ -19,7 +19,7 @@ func WithRole(role model.Role) CreateUserConfig { } } -func CreateUser(username string, p provider.OAuth2Provider, puid uint64, conf ...CreateUserConfig) (*model.User, error) { +func CreateUser(username string, p provider.OAuth2Provider, puid string, conf ...CreateUserConfig) (*model.User, error) { u := &model.User{ Username: username, Role: model.RoleUser, @@ -41,7 +41,7 @@ func CreateUser(username string, p provider.OAuth2Provider, puid uint64, conf .. } // 只有当provider和puid没有找到对应的user时才会创建 -func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid uint64, conf ...CreateUserConfig) (*model.User, error) { +func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid string, conf ...CreateUserConfig) (*model.User, error) { var user model.User var userProvider model.UserProvider @@ -60,7 +60,7 @@ func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid uint64, c return &user, nil } -func GetProviderUserID(p provider.OAuth2Provider, puid uint64) (string, error) { +func GetProviderUserID(p provider.OAuth2Provider, puid string) (string, error) { var userProvider model.UserProvider if err := db.Where("provider = ? AND provider_user_id = ?", p, puid).First(&userProvider).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/internal/model/oauth2.go b/internal/model/oauth2.go index a172953..fbd2437 100644 --- a/internal/model/oauth2.go +++ b/internal/model/oauth2.go @@ -8,7 +8,7 @@ import ( type UserProvider struct { Provider provider.OAuth2Provider `gorm:"not null;primarykey"` - ProviderUserID uint64 `gorm:"not null;primarykey;autoIncrement:false"` + ProviderUserID string `gorm:"not null;primarykey;autoIncrement:false"` CreatedAt time.Time UpdatedAt time.Time UserID string `gorm:"not null;index"` diff --git a/internal/op/users.go b/internal/op/users.go index 555088b..ececede 100644 --- a/internal/op/users.go +++ b/internal/op/users.go @@ -43,7 +43,7 @@ func GetUserById(id string) (*User, error) { return u2, userCache.SetWithExpire(id, u2, time.Hour) } -func CreateUser(username string, p provider.OAuth2Provider, pid uint64, conf ...db.CreateUserConfig) (*User, error) { +func CreateUser(username string, p provider.OAuth2Provider, pid string, conf ...db.CreateUserConfig) (*User, error) { if username == "" { return nil, errors.New("username cannot be empty") } @@ -59,7 +59,7 @@ func CreateUser(username string, p provider.OAuth2Provider, pid uint64, conf ... return u2, userCache.SetWithExpire(u.ID, u2, time.Hour) } -func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid uint64, conf ...db.CreateUserConfig) (*User, error) { +func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid string, conf ...db.CreateUserConfig) (*User, error) { if username == "" { return nil, errors.New("username cannot be empty") } @@ -75,7 +75,7 @@ func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid uint64, co return u2, userCache.SetWithExpire(u.ID, u2, time.Hour) } -func GetUserByProvider(p provider.OAuth2Provider, pid uint64) (*User, error) { +func GetUserByProvider(p provider.OAuth2Provider, pid string) (*User, error) { uid, err := db.GetProviderUserID(p, pid) if err != nil { return nil, err diff --git a/internal/provider/plugins/example/example_gitee.go b/internal/provider/plugins/example/example_gitee.go index de12319..25c84da 100644 --- a/internal/provider/plugins/example/example_gitee.go +++ b/internal/provider/plugins/example/example_gitee.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "net/http" + "strconv" plugin "github.com/hashicorp/go-plugin" "github.com/synctv-org/synctv/internal/provider" @@ -75,7 +76,7 @@ func (p *GiteeProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro } return &provider.UserInfo{ Username: ui.Login, - ProviderUserID: ui.ID, + ProviderUserID: strconv.FormatUint(ui.ID, 10), }, nil } diff --git a/internal/provider/plugins/server.go b/internal/provider/plugins/server.go index fbe179a..a02878d 100644 --- a/internal/provider/plugins/server.go +++ b/internal/provider/plugins/server.go @@ -56,7 +56,7 @@ func (s *GRPCServer) GetUserInfo(ctx context.Context, req *providerpb.GetUserInf } resp := &providerpb.GetUserInfoResp{ Username: userInfo.Username, - ProviderUserId: uint64(userInfo.ProviderUserID), + ProviderUserId: userInfo.ProviderUserID, } return resp, nil } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 3b3e3d4..19119f1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -10,7 +10,7 @@ type OAuth2Provider string type UserInfo struct { Username string - ProviderUserID uint64 + ProviderUserID string } type Oauth2Option struct { diff --git a/internal/provider/providers/baidu-netdisk.go b/internal/provider/providers/baidu-netdisk.go index 6a2dcbf..82f3dd9 100644 --- a/internal/provider/providers/baidu-netdisk.go +++ b/internal/provider/providers/baidu-netdisk.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "strconv" json "github.com/json-iterator/go" "github.com/synctv-org/synctv/internal/provider" @@ -63,7 +64,7 @@ func (p *BaiduNetDiskProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token } return &provider.UserInfo{ Username: ui.BaiduName, - ProviderUserID: ui.Uk, + ProviderUserID: strconv.FormatUint(ui.Uk, 10), }, nil } diff --git a/internal/provider/providers/baidu.go b/internal/provider/providers/baidu.go index be4ada0..1969a81 100644 --- a/internal/provider/providers/baidu.go +++ b/internal/provider/providers/baidu.go @@ -3,7 +3,6 @@ package providers import ( "context" "fmt" - "hash/crc64" "net/http" json "github.com/json-iterator/go" @@ -61,7 +60,7 @@ func (p *BaiduProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro } return &provider.UserInfo{ Username: ui.Uname, - ProviderUserID: crc64.Checksum([]byte(ui.Openid), crc64.MakeTable(crc64.ECMA)), + ProviderUserID: ui.Openid, }, nil } diff --git a/internal/provider/providers/gitee.go b/internal/provider/providers/gitee.go index 46e6235..8c7a0dd 100644 --- a/internal/provider/providers/gitee.go +++ b/internal/provider/providers/gitee.go @@ -3,6 +3,7 @@ package providers import ( "context" "net/http" + "strconv" json "github.com/json-iterator/go" "github.com/synctv-org/synctv/internal/provider" @@ -58,7 +59,7 @@ func (p *GiteeProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro } return &provider.UserInfo{ Username: ui.Login, - ProviderUserID: ui.ID, + ProviderUserID: strconv.FormatUint(ui.ID, 10), }, nil } diff --git a/internal/provider/providers/github.go b/internal/provider/providers/github.go index 7c21869..2460fbd 100644 --- a/internal/provider/providers/github.go +++ b/internal/provider/providers/github.go @@ -3,6 +3,7 @@ package providers import ( "context" "net/http" + "strconv" json "github.com/json-iterator/go" "github.com/synctv-org/synctv/internal/provider" @@ -56,7 +57,7 @@ func (p *GithubProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pr } return &provider.UserInfo{ Username: ui.Login, - ProviderUserID: ui.ID, + ProviderUserID: strconv.FormatUint(ui.ID, 10), }, nil } diff --git a/internal/provider/providers/google.go b/internal/provider/providers/google.go index 0c388df..739d6e4 100644 --- a/internal/provider/providers/google.go +++ b/internal/provider/providers/google.go @@ -65,6 +65,6 @@ func init() { } type googleUserInfo struct { - ID uint64 `json:"id,string"` + ID string `json:"id"` Name string `json:"name"` } diff --git a/internal/provider/providers/microsoft.go b/internal/provider/providers/microsoft.go index 17fd608..ac20d4a 100644 --- a/internal/provider/providers/microsoft.go +++ b/internal/provider/providers/microsoft.go @@ -2,12 +2,10 @@ package providers import ( "context" - "hash/crc64" "net/http" json "github.com/json-iterator/go" "github.com/synctv-org/synctv/internal/provider" - "github.com/zijiren233/stream" "golang.org/x/oauth2" "golang.org/x/oauth2/microsoft" ) @@ -58,7 +56,7 @@ func (p *MicrosoftProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) ( } return &provider.UserInfo{ Username: ui.DisplayName, - ProviderUserID: crc64.Checksum(stream.StringToBytes(ui.ID), crc64.MakeTable(crc64.ECMA)), + ProviderUserID: ui.ID, }, nil } diff --git a/internal/provider/providers/qq.go b/internal/provider/providers/qq.go index 891f666..caee76d 100644 --- a/internal/provider/providers/qq.go +++ b/internal/provider/providers/qq.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strconv" json "github.com/json-iterator/go" "github.com/synctv-org/synctv/internal/provider" @@ -59,7 +58,7 @@ func (p *QQProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*provid return nil, err } return &provider.UserInfo{ - Username: strconv.FormatUint(ui.Openid, 10), + Username: ui.Openid, ProviderUserID: ui.Openid, }, nil } @@ -70,5 +69,5 @@ func init() { type qqProviderUserInfo struct { ClientID string `json:"client_id"` - Openid uint64 `json:"openid,string"` + Openid string `json:"openid"` } diff --git a/proto/provider/plugin.pb.go b/proto/provider/plugin.pb.go index 9c29b0d..9d4501a 100644 --- a/proto/provider/plugin.pb.go +++ b/proto/provider/plugin.pb.go @@ -489,7 +489,7 @@ type GetUserInfoResp struct { unknownFields protoimpl.UnknownFields Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - ProviderUserId uint64 `protobuf:"varint,2,opt,name=provider_user_id,json=providerUserId,proto3" json:"provider_user_id,omitempty"` + ProviderUserId string `protobuf:"bytes,2,opt,name=provider_user_id,json=providerUserId,proto3" json:"provider_user_id,omitempty"` } func (x *GetUserInfoResp) Reset() { @@ -531,11 +531,11 @@ func (x *GetUserInfoResp) GetUsername() string { return "" } -func (x *GetUserInfoResp) GetProviderUserId() uint64 { +func (x *GetUserInfoResp) GetProviderUserId() string { if x != nil { return x.ProviderUserId } - return 0 + return "" } type Enpty struct { @@ -620,7 +620,7 @@ var file_proto_provider_plugin_proto_rawDesc = []byte{ 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e, + 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x32, 0xd7, 0x02, 0x0a, 0x0c, 0x4f, 0x61, 0x75, 0x74, 0x68, 0x32, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x26, 0x0a, 0x04, 0x49, 0x6e, 0x69, 0x74, diff --git a/proto/provider/plugin.proto b/proto/provider/plugin.proto index 7df77c1..4d69116 100644 --- a/proto/provider/plugin.proto +++ b/proto/provider/plugin.proto @@ -32,7 +32,7 @@ message GetUserInfoReq { Token token = 1; } message GetUserInfoResp { string username = 1; - uint64 provider_user_id = 2; + string provider_user_id = 2; } message Enpty {}