From 3f341891ffeba6e93910e96b667d1c0aa0f0c4a7 Mon Sep 17 00:00:00 2001 From: lxw665 <62870122+lxw665@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:06:40 +0800 Subject: [PATCH] feat: wechat login in [wip] --- .gitignore | 1 + internal/api/provider/wechat.go | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 internal/api/provider/wechat.go diff --git a/.gitignore b/.gitignore index 38a57a969..24740f770 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ www/.DS_Store www/node_modules npm-debug.log .data +.idea/ diff --git a/internal/api/provider/wechat.go b/internal/api/provider/wechat.go new file mode 100644 index 000000000..3c55cafd9 --- /dev/null +++ b/internal/api/provider/wechat.go @@ -0,0 +1,70 @@ +package provider + +import ( + "context" + "github.com/supabase/gotrue/internal/conf" + "golang.org/x/oauth2" + "net/http" + "sync" +) + +var ( + WechatCacheMap map[string]WechatCacheMapValue + Lock sync.RWMutex +) + +type WechatCacheMapValue struct { + IsScanned bool + WechatUnionId string +} + +type weChatProvider struct { + Client *http.Client + Config *oauth2.Config +} + +type WechatUser struct { + Openid string `json:"openid"` // The ID of an ordinary user, which is unique to the current developer account + Nickname string `json:"nickname"` // Ordinary user nickname + Sex int `json:"sex"` // Ordinary user gender, 1 is male, 2 is female + Language string `json:"language"` + City string `json:"city"` // City filled in by general user's personal data + Province string `json:"province"` // Province filled in by ordinary user's personal information + Country string `json:"country"` // Country, such as China is CN + Headimgurl string `json:"headimgurl"` // User avatar, the last value represents the size of the square avatar (there are optional values of 0, 46, 64, 96, 132, 0 represents a 640*640 square avatar), this item is empty when the user does not have an avatar + Privilege []string `json:"privilege"` // User Privilege information, json array, such as Wechat Woka user (chinaunicom) + Unionid string `json:"unionid"` // Unified user identification. For an application under a WeChat open platform account, the unionid of the same user is unique. +} + +func NewWeChatIdProvider(clientId string, clientSecret string, redirectUrl string, ext conf.OAuthProviderConfiguration, scopes string) (OAuthProvider, error) { + //idp := &WeChatIdProvider{} + // + //config := idp.getConfig(clientId, clientSecret, redirectUrl) + //idp.Config = config + //if scopes == "" { + // scopes = "logs" + //} + // + //return &weChatProvider{ + // Config: &oauth2.Config{ + // ClientID: ext.ClientID[0], + // ClientSecret: ext.Secret, + // Endpoint: oauth2.Endpoint{ + // AuthURL: authHost + "/login/oauth/authorize", + // TokenURL: authHost + "/login/oauth/access_token", + // }, + // RedirectURL: ext.RedirectURI, + // Scopes: oauthScopes, + // }, + // APIHost: apiHost, + //}, nil + return nil, nil +} + +func (p weChatProvider) GetOAuthToken(code string) (*oauth2.Token, error) { + return nil, nil +} + +func (p weChatProvider) GetUserData(ctx context.Context, tok *oauth2.Token) (*UserProvidedData, error) { + return nil, nil +}