From 718c54f7967950e6ea607b42864a3c027e089dd1 Mon Sep 17 00:00:00 2001 From: rehjinh Date: Thu, 22 Jun 2023 10:49:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=ED=8A=B8=EC=9C=84=ED=84=B0=20-=20Userinfo?= =?UTF-8?q?=20=EC=96=BB=EC=96=B4=EC=98=A4=EB=8A=94=20API=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20verify=5Fcredentials=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.=20email=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EC=96=BB=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/platformtwitter.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/platformtwitter.go b/core/platformtwitter.go index 4accfc9..11397e4 100644 --- a/core/platformtwitter.go +++ b/core/platformtwitter.go @@ -222,14 +222,13 @@ func (mg *Maingate) platform_twitter_authorize_result(w http.ResponseWriter, r * func (mg *Maingate) platform_twitter_getuserinfo(token, secret string) (bool, string, string) { - result := mg.CallTwitterAPI("https://api.twitter.com/2/users/me", "GET", token, secret, mg.GeneratePlatformLoginNonceKey()) + result := mg.CallTwitterAPI("https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true", "GET", token, secret, mg.GeneratePlatformLoginNonceKey()) var TwitterUserInfo struct { - Data struct { - Id string `json:"id"` - Name string `json:"name"` - Username string `json:"username"` - } `json:"data"` + Id string `json:"id_str"` + Name string `json:"name"` + Username string `json:"screen_name"` + Email string `json:"email"` } err := json.Unmarshal([]byte(result), &TwitterUserInfo) @@ -240,12 +239,13 @@ func (mg *Maingate) platform_twitter_getuserinfo(token, secret string) (bool, st // fmt.Println("=====================") // fmt.Println(result) - // fmt.Println(TwitterUserInfo.Data.Id) - // fmt.Println(TwitterUserInfo.Data.Name) - // fmt.Println(TwitterUserInfo.Data.Username) + // fmt.Println(TwitterUserInfo.Id) + // fmt.Println(TwitterUserInfo.Name) + // fmt.Println(TwitterUserInfo.Username) + // fmt.Println(TwitterUserInfo.Email) // fmt.Println("=====================") - return true, TwitterUserInfo.Data.Id, "" + return true, TwitterUserInfo.Id, TwitterUserInfo.Email } func (mg *Maingate) CallTwitterAPI_WithAPPKey(requesturl, method, nonce string) string { From a55a4358118ebd5f40ef4ff769e3064dfd4f5d9e Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 22 Jun 2023 11:56:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?noauth=20=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/maingate.go b/core/maingate.go index d6920bc..b759347 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -505,17 +505,20 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu } }() - apitoken := r.Header.Get("MG-X-API-TOKEN") - if len(apitoken) == 0 { - logger.Println("MG-X-API-TOKEN is missing") - w.WriteHeader(http.StatusBadRequest) - return + if !*noauth { + apitoken := r.Header.Get("MG-X-API-TOKEN") + if len(apitoken) == 0 { + logger.Println("MG-X-API-TOKEN is missing") + w.WriteHeader(http.StatusBadRequest) + return + } + + apitokenObj, _ := primitive.ObjectIDFromHex(apitoken) + if mg.service().isValidToken(apitokenObj) { + convertedConfig["divisions"] = mg.service().Divisions + } } - apitokenObj, _ := primitive.ObjectIDFromHex(apitoken) - if mg.service().isValidToken(apitokenObj) { - convertedConfig["divisions"] = mg.service().Divisions - } enc := json.NewEncoder(w) enc.Encode(convertedConfig) })