From 2165a4400bf01ae1e9bcb0ae7c6cebc7f8a2d78a Mon Sep 17 00:00:00 2001 From: rehjinh Date: Tue, 9 Jan 2024 14:43:23 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Session=EC=97=90=20email=EB=8F=84=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=B4=EB=91=94=EB=8B=A4.=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=A0=EB=95=8C=20=EA=BA=BC=EB=82=B4=EC=A4=84=20api?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=20=EC=98=88=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 10 ++++++++++ core/platformapple.go | 1 + core/platformfirebaseauth.go | 1 + core/platformgoogle.go | 2 ++ core/platformmicrosoft.go | 2 ++ core/platformsteam.go | 1 + core/platformtwitter.go | 1 + core/service.go | 1 + 8 files changed, 19 insertions(+) diff --git a/core/maingate.go b/core/maingate.go index 7131a91..d55b2e3 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -587,6 +587,7 @@ func (mg *Maingate) setUserToken(info usertokeninfo) error { "lastupdate": time.Now().Unix(), "accesstoken": info.accesstoken, "accesstoken_expire_time": info.accesstoken_expire_time, + "email": info.email, }, }, options.Update().SetUpsert(true)) return logger.ErrorWithCallStack(err) @@ -639,6 +640,11 @@ func (mg *Maingate) getUserTokenWithCheck(platform string, userid string, brinfo info.accesstoken_expire_time = accesstoken_expire_time.(int64) } + email := found["email"] + if email != nil { + info.email = email.(string) + } + return info, nil } @@ -676,6 +682,10 @@ func (mg *Maingate) updateUserinfo(info usertokeninfo) (bool, string, string) { return false, "", "" } + if !(strings.HasPrefix("email", "__dummy_") && strings.HasSuffix("email", "temp__")) { + info.email = email + } + mg.setUserToken(info) return success, userid, email diff --git a/core/platformapple.go b/core/platformapple.go index dc9daa9..c8a0370 100644 --- a/core/platformapple.go +++ b/core/platformapple.go @@ -255,6 +255,7 @@ func (mg *Maingate) platform_apple_authorize_result(w http.ResponseWriter, r *ht info.userid = userid info.token = resp.RefreshToken info.brinfo = brinfo + info.email = email mg.setUserToken(info) params := url.Values{} diff --git a/core/platformfirebaseauth.go b/core/platformfirebaseauth.go index 5741818..abc2d46 100644 --- a/core/platformfirebaseauth.go +++ b/core/platformfirebaseauth.go @@ -208,6 +208,7 @@ func (mg *Maingate) platform_firebaseauth_authorize_raw(w http.ResponseWriter, b info.brinfo = brinfo info.accesstoken = "" info.accesstoken_expire_time = acceestoken_expire_time + info.email = email mg.setUserToken(info) mg.mongoClient.Delete(CollectionFirebaseUserInfo, bson.M{ diff --git a/core/platformgoogle.go b/core/platformgoogle.go index 10d6013..3a58f5a 100644 --- a/core/platformgoogle.go +++ b/core/platformgoogle.go @@ -262,6 +262,7 @@ func (mg *Maingate) platform_google_authorize_result(w http.ResponseWriter, r *h info.brinfo = brinfo info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time + info.email = email mg.setUserToken(info) params := url.Values{} @@ -316,6 +317,7 @@ func (mg *Maingate) platform_google_getuserinfo(info usertokeninfo) (bool, strin info.token = respReferesh.RefreshToken info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time + info.email = email mg.setUserToken(info) //-- accesstoken 업데이트 } else { logger.Println("JWTparseCode fail.") diff --git a/core/platformmicrosoft.go b/core/platformmicrosoft.go index 3375905..b444692 100644 --- a/core/platformmicrosoft.go +++ b/core/platformmicrosoft.go @@ -239,6 +239,7 @@ func (mg *Maingate) platform_microsoft_authorize_result(w http.ResponseWriter, r info.brinfo = brinfo info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time + info.email = "" mg.setUserToken(info) params := url.Values{} @@ -295,6 +296,7 @@ func (mg *Maingate) platform_microsoft_getuserinfo(info usertokeninfo) (bool, st info.token = respReferesh.RefreshToken info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time + info.email = "" mg.setUserToken(info) //-- accesstoken 업데이트 } else { logger.Println("JWTparseCode fail.") diff --git a/core/platformsteam.go b/core/platformsteam.go index bcdd229..4c3b602 100644 --- a/core/platformsteam.go +++ b/core/platformsteam.go @@ -53,6 +53,7 @@ func (mg *Maingate) platform_steamsdk_authorize(w http.ResponseWriter, r *http.R info.brinfo = brinfo //info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time + info.email = "" mg.setUserToken(info) params := url.Values{} diff --git a/core/platformtwitter.go b/core/platformtwitter.go index 58396c5..a10017a 100644 --- a/core/platformtwitter.go +++ b/core/platformtwitter.go @@ -208,6 +208,7 @@ func (mg *Maingate) platform_twitter_authorize_result(w http.ResponseWriter, r * info.token = token info.secret = secret info.brinfo = brinfo + info.email = "" mg.setUserToken(info) params := url.Values{} diff --git a/core/service.go b/core/service.go index 1389d95..e0b911a 100644 --- a/core/service.go +++ b/core/service.go @@ -63,6 +63,7 @@ type usertokeninfo struct { token string //refreshtoken secret string brinfo string + email string accesstoken string // microsoft only accesstoken_expire_time int64 // microsoft only } From bc82cb123ccf5f66612532bf3ca3e04784c9236a Mon Sep 17 00:00:00 2001 From: rehjinh Date: Tue, 9 Jan 2024 15:31:15 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"Session=EC=97=90=20email=EB=8F=84?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=ED=95=B4=EB=91=94=EB=8B=A4.=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=A0=EB=95=8C=20=EA=BA=BC=EB=82=B4=EC=A4=84=20api?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=20=EC=98=88=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2165a4400bf01ae1e9bcb0ae7c6cebc7f8a2d78a. --- core/maingate.go | 10 ---------- core/platformapple.go | 1 - core/platformfirebaseauth.go | 1 - core/platformgoogle.go | 2 -- core/platformmicrosoft.go | 2 -- core/platformsteam.go | 1 - core/platformtwitter.go | 1 - core/service.go | 1 - 8 files changed, 19 deletions(-) diff --git a/core/maingate.go b/core/maingate.go index d55b2e3..7131a91 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -587,7 +587,6 @@ func (mg *Maingate) setUserToken(info usertokeninfo) error { "lastupdate": time.Now().Unix(), "accesstoken": info.accesstoken, "accesstoken_expire_time": info.accesstoken_expire_time, - "email": info.email, }, }, options.Update().SetUpsert(true)) return logger.ErrorWithCallStack(err) @@ -640,11 +639,6 @@ func (mg *Maingate) getUserTokenWithCheck(platform string, userid string, brinfo info.accesstoken_expire_time = accesstoken_expire_time.(int64) } - email := found["email"] - if email != nil { - info.email = email.(string) - } - return info, nil } @@ -682,10 +676,6 @@ func (mg *Maingate) updateUserinfo(info usertokeninfo) (bool, string, string) { return false, "", "" } - if !(strings.HasPrefix("email", "__dummy_") && strings.HasSuffix("email", "temp__")) { - info.email = email - } - mg.setUserToken(info) return success, userid, email diff --git a/core/platformapple.go b/core/platformapple.go index c8a0370..dc9daa9 100644 --- a/core/platformapple.go +++ b/core/platformapple.go @@ -255,7 +255,6 @@ func (mg *Maingate) platform_apple_authorize_result(w http.ResponseWriter, r *ht info.userid = userid info.token = resp.RefreshToken info.brinfo = brinfo - info.email = email mg.setUserToken(info) params := url.Values{} diff --git a/core/platformfirebaseauth.go b/core/platformfirebaseauth.go index abc2d46..5741818 100644 --- a/core/platformfirebaseauth.go +++ b/core/platformfirebaseauth.go @@ -208,7 +208,6 @@ func (mg *Maingate) platform_firebaseauth_authorize_raw(w http.ResponseWriter, b info.brinfo = brinfo info.accesstoken = "" info.accesstoken_expire_time = acceestoken_expire_time - info.email = email mg.setUserToken(info) mg.mongoClient.Delete(CollectionFirebaseUserInfo, bson.M{ diff --git a/core/platformgoogle.go b/core/platformgoogle.go index 3a58f5a..10d6013 100644 --- a/core/platformgoogle.go +++ b/core/platformgoogle.go @@ -262,7 +262,6 @@ func (mg *Maingate) platform_google_authorize_result(w http.ResponseWriter, r *h info.brinfo = brinfo info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time - info.email = email mg.setUserToken(info) params := url.Values{} @@ -317,7 +316,6 @@ func (mg *Maingate) platform_google_getuserinfo(info usertokeninfo) (bool, strin info.token = respReferesh.RefreshToken info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time - info.email = email mg.setUserToken(info) //-- accesstoken 업데이트 } else { logger.Println("JWTparseCode fail.") diff --git a/core/platformmicrosoft.go b/core/platformmicrosoft.go index b444692..3375905 100644 --- a/core/platformmicrosoft.go +++ b/core/platformmicrosoft.go @@ -239,7 +239,6 @@ func (mg *Maingate) platform_microsoft_authorize_result(w http.ResponseWriter, r info.brinfo = brinfo info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time - info.email = "" mg.setUserToken(info) params := url.Values{} @@ -296,7 +295,6 @@ func (mg *Maingate) platform_microsoft_getuserinfo(info usertokeninfo) (bool, st info.token = respReferesh.RefreshToken info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time - info.email = "" mg.setUserToken(info) //-- accesstoken 업데이트 } else { logger.Println("JWTparseCode fail.") diff --git a/core/platformsteam.go b/core/platformsteam.go index 4c3b602..bcdd229 100644 --- a/core/platformsteam.go +++ b/core/platformsteam.go @@ -53,7 +53,6 @@ func (mg *Maingate) platform_steamsdk_authorize(w http.ResponseWriter, r *http.R info.brinfo = brinfo //info.accesstoken = respReferesh.AccessToken info.accesstoken_expire_time = acceestoken_expire_time - info.email = "" mg.setUserToken(info) params := url.Values{} diff --git a/core/platformtwitter.go b/core/platformtwitter.go index a10017a..58396c5 100644 --- a/core/platformtwitter.go +++ b/core/platformtwitter.go @@ -208,7 +208,6 @@ func (mg *Maingate) platform_twitter_authorize_result(w http.ResponseWriter, r * info.token = token info.secret = secret info.brinfo = brinfo - info.email = "" mg.setUserToken(info) params := url.Values{} diff --git a/core/service.go b/core/service.go index e0b911a..1389d95 100644 --- a/core/service.go +++ b/core/service.go @@ -63,7 +63,6 @@ type usertokeninfo struct { token string //refreshtoken secret string brinfo string - email string accesstoken string // microsoft only accesstoken_expire_time int64 // microsoft only } From e7b3f59dd0a66a039cb495838d7b04710c63f484 Mon Sep 17 00:00:00 2001 From: rehjinh Date: Wed, 10 Jan 2024 07:37:06 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EA=B3=84=EC=A0=95=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=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/service.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/core/service.go b/core/service.go index 1389d95..0664cf9 100644 --- a/core/service.go +++ b/core/service.go @@ -533,6 +533,49 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) { } +// == 계정 이메일 조회 +func (sh *serviceDescription) emailinfo(w http.ResponseWriter, r *http.Request) { + defer func() { + s := recover() + if s != nil { + logger.Error(s) + } + }() + + if r.Method != "GET" { + w.WriteHeader(http.StatusBadRequest) + return + } + + queryvals := r.URL.Query() + sk := queryvals.Get("sk") + + authInfo, err := sh.sessionProvider.Query(sk) + if err != nil { + logger.Println("sessionProvider.Query return err :", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + email := authInfo.Email + + if strings.HasPrefix(email, "__dummy_") && strings.HasSuffix(email, "temp__") { + email = "" + } + + if strings.HasSuffix(email, "@noauth.flag") || strings.HasSuffix(email, "@guest.flag") { + email = "" + } + + // fmt.Println("=================") + // fmt.Println(email) + // fmt.Println("=================") + //logger.Println("Email :", email) + + w.Write([]byte(fmt.Sprintf(`{"email":"%s"}`, email))) + +} + func (sh *serviceDescription) authorize_dev(w http.ResponseWriter, r *http.Request) { if r.Method == "DELETE" { sk := r.Header.Get("AS-X-SESSION") @@ -748,6 +791,8 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) sh.unlink(w, r) } else if strings.HasSuffix(r.URL.Path, "/linkinfo") { sh.linkinfo(w, r) + } else if strings.HasSuffix(r.URL.Path, "/emailinfo") { + sh.emailinfo(w, r) } else if strings.HasSuffix(r.URL.Path, "/divs") { // TODO : 세션키와 authtoken을 헤더로 받아서 accid 조회 queryvals := r.URL.Query()