From ec3edbd8d5c55398c907809be8f0dae019fb920a Mon Sep 17 00:00:00 2001 From: mountain Date: Wed, 10 Jul 2024 14:54:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?noauth=EB=8C=80=EC=8B=A0=20authtype=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 8 ++++---- core/platformhybeim.go | 6 +----- core/platformsteam.go | 6 +----- core/service.go | 21 ++++++++++----------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/core/maingate.go b/core/maingate.go index 055763b..784d4fe 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -36,7 +36,7 @@ import ( var devflag = flagx.Bool("dev", false, "") var noauth = flagx.Bool("noauth", false, "") -var authtype = flagx.String("auth", "", "yes|no|both") +var authtype = flagx.String("auth", "on", "on|off|both") var ( CollectionLink = gocommon.CollectionName("link") @@ -193,11 +193,11 @@ func New(ctx context.Context) (*Maingate, error) { return nil, err } - if *noauth && len(*authtype) == 0 { - *authtype = "no" + if len(*authtype) == 0 { + *authtype = "on" } - if *authtype == "yes" || *authtype == "both" { + if !*noauth && (*authtype == "on" || *authtype == "both") { if len(config.FirebaseAdminSDKCredentialFile) > 0 { opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile) firebaseApp, err := firebase.NewApp(context.Background(), nil, opt) diff --git a/core/platformhybeim.go b/core/platformhybeim.go index 710cd31..a852bb4 100644 --- a/core/platformhybeim.go +++ b/core/platformhybeim.go @@ -56,11 +56,7 @@ func (mg *Maingate) platform_hybeim_authorize(w http.ResponseWriter, r *http.Req return } - if !*noauth { - err = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken) - } - - if err == nil { + if err = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken); err == nil { acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix() var info usertokeninfo diff --git a/core/platformsteam.go b/core/platformsteam.go index 4dfc2f7..66e5b5f 100644 --- a/core/platformsteam.go +++ b/core/platformsteam.go @@ -39,11 +39,7 @@ func (mg *Maingate) platform_steamsdk_authorize(w http.ResponseWriter, r *http.R return } - if !*noauth { - err = authenticateSteamUser(config.SteamPublisherAuthKey, config.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken) - } - - if err == nil { + if err := authenticateSteamUser(config.SteamPublisherAuthKey, config.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken); err == nil { acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix() var info usertokeninfo diff --git a/core/service.go b/core/service.go index d8638b7..e13b5d7 100644 --- a/core/service.go +++ b/core/service.go @@ -653,7 +653,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) } queryvals := r.URL.Query() - authtype := queryvals.Get("type") + reqauthtype := queryvals.Get("type") uid := queryvals.Get("id") sk := queryvals.Get("sk") @@ -692,9 +692,8 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) } var email string - - if !*noauth { - if len(authtype) > 0 { + if !*noauth && (*authtype == "on" || *authtype == "both") { + if len(reqauthtype) > 0 { //email, err := sh.readProfile(authtype, uid, accesstoken) bfinfo, err := sh.getUserBrowserInfo(r) if err != nil { @@ -703,25 +702,25 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) return } - email, err = sh.readProfile(authtype, uid, bfinfo) + email, err = sh.readProfile(reqauthtype, uid, bfinfo) if err != nil { logger.Error("readProfile failed :", err) w.WriteHeader(http.StatusBadRequest) return } - newType, newId, err := sh.getProviderInfo(authtype, uid) + newType, newId, err := sh.getProviderInfo(reqauthtype, uid) if err != nil { logger.Error("getProviderInfo failed :", err) w.WriteHeader(http.StatusBadRequest) return } - if authtype != newType || uid != newId { - authtype = newType + if reqauthtype != newType || uid != newId { + reqauthtype = newType uid = newId } - } else if *devflag { + } else if *authtype == "both" { email = fmt.Sprintf("%s@guest.flag", uid) } else { // authtype이 없으면 입장 불가 @@ -780,7 +779,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) sk, err = sh.sessionProvider.New(&session.Authorization{ Account: accid, - Platform: authtype, + Platform: reqauthtype, Uid: uid, Email: email, }) @@ -796,7 +795,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) "newAccount": newaccount, "accid": accid.Hex(), } - if *noauth { + if len(reqauthtype) == 0 { output["noauth"] = true } From 894663ed384b9d45838784a42c1cfc94cbf5e186 Mon Sep 17 00:00:00 2001 From: rehjinh Date: Tue, 16 Jul 2024 14:38:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?reqauthtype=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=95=98=EB=A9=B4=EC=84=9C=20=EB=B9=A0?= =?UTF-8?q?=EC=A7=84=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95=20->=20plat?= =?UTF-8?q?form=20=EC=A0=95=EB=B3=B4=EA=B0=80=20flag=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A1=9C=20=EC=94=8C=EC=9B=8C=EC=A7=80=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/service.go b/core/service.go index e13b5d7..c9b4647 100644 --- a/core/service.go +++ b/core/service.go @@ -735,7 +735,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) // platform + id -> account id createtime := primitive.NewDateTimeFromTime(time.Now().UTC()) link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{ - "platform": authtype, + "platform": reqauthtype, "uid": uid, }, bson.M{ "$setOnInsert": bson.M{