From 4212d3ed59427bb1f5a2f44ec75f3da15222d299 Mon Sep 17 00:00:00 2001 From: rehjinh Date: Mon, 22 Jul 2024 16:16:11 +0900 Subject: [PATCH] =?UTF-8?q?Hybe=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=A0=9C=EC=9E=AC=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EA=B8=88=EC=A7=80=20=EC=B2=98=EB=A6=AC=20-=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20authorize=EC=97=90=EC=84=9C=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=AC=20=EC=B2=98=EB=A6=AC=20=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/platformhybeim.go | 81 +++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/core/platformhybeim.go b/core/platformhybeim.go index a852bb4..2a4d61c 100644 --- a/core/platformhybeim.go +++ b/core/platformhybeim.go @@ -25,11 +25,20 @@ type HybeImSDKLoginAuthInfo struct { } type Hiveim_LoginVerifyResult struct { - State string `json:"state"` - ImId string `json:"imId"` - Provider string `json:"provider"` - Os string `json:"os"` - AppStore string `json:"appStore"` + State string `json:"state"` + ImId string `json:"imId"` + Provider string `json:"provider"` + Os string `json:"os"` + AppStore string `json:"appStore"` + UserBlockInfo []Hiveim_UserBlockInfo `json:"blocks"` +} + +type Hiveim_UserBlockInfo struct { + BlockId int `json:"blockId"` + ReasonId int `json:"reasonId"` + BlockedAt int64 `json:"blockedAt"` + ExpireAt int64 `json:"expireAt"` + Permanent bool `json:"permanent"` } type Hiveim_LoginValidationResponse struct { @@ -56,7 +65,22 @@ func (mg *Maingate) platform_hybeim_authorize(w http.ResponseWriter, r *http.Req return } - if err = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken); err == nil { + var resultcode string + var blockinfo Hiveim_UserBlockInfo + if !*noauth { + err, resultcode, blockinfo = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken) + } + + // https://hybeim.gitbook.io/im-assemble/api/im-assemble-s2s-api#login-verify + // SUCCESS : 성공 + // INVALID_LOGIN_VERIFY_TOKEN : login 인증 토큰 오류 + // LOGIN_VERIFY_EXPIRED : login 인증 토큰 만료 + // INVALID_SERVICE_ID : 유효 하지 않은 서비스 id + // WITHDRAWAL_ACCOUNT : 탈퇴 대기 상태 유저 + // RELOGIN_REQUIRED : 로그인 데이터에 문제가 있어 다시 로그인 해야 되는 경우 + // INTERNAL_SERVER_ERROR : 서버 오류 + + if err == nil && resultcode == "SUCCESS" { acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix() var info usertokeninfo @@ -73,14 +97,25 @@ func (mg *Maingate) platform_hybeim_authorize(w http.ResponseWriter, r *http.Req params.Add("authtype", AuthPlatformHybeim) w.Write([]byte("?" + params.Encode())) //http.Redirect(w, r, "actionsquare://login?"+Result, http.StatusSeeOther) + return } else { - logger.Println(err) - http.Redirect(w, r, "actionsquare://error", http.StatusSeeOther) + params := url.Values{} + params.Add("resultcode", resultcode) + if resultcode == "BLOCKED" { + blockinfoBytes, _ := json.Marshal(blockinfo) + blockinfostr := string(blockinfoBytes) + params.Add("blockinfo", blockinfostr) + } + w.WriteHeader(http.StatusUnauthorized) + w.Write([]byte("?" + params.Encode())) } + // logger.Println(err) + // http.Redirect(w, r, "actionsquare://error", http.StatusSeeOther) + } -func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, UserLoginVerifyToken string) error { +func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, UserLoginVerifyToken string) (error, string, Hiveim_UserBlockInfo) { // endpoint // qa = https://api-qa.pub-dev.hybegames.io @@ -118,9 +153,10 @@ func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, Use resp.Body.Close() }() + var blockinfo Hiveim_UserBlockInfo body, e := ioutil.ReadAll(resp.Body) if e != nil { - return e + return e, "", blockinfo } json.Unmarshal(body, &respReferesh) @@ -129,26 +165,29 @@ func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, Use var doc map[string]interface{} if err := json.Unmarshal(body, &doc); err != nil { - return err + return err, respReferesh.ResultCode, blockinfo } - if respReferesh.ResultCode != "SUCCESS" { - return errors.New("higveimSDK: ResultCode is not SUCCESS") - } - - if respReferesh.ResultData.State != "NORMAL" { - return errors.New("higveimSDK: State is not NORMAL") - } + // if respReferesh.ResultData.State != "NORMAL" { + // return errors.New("higveimSDK: State is not NORMAL"), respReferesh.ResultCode, blockinfo + // } if respReferesh.ResultData.Provider != "STEAM" { - return errors.New("higveimSDK: Provider is not STEAM") + return errors.New("higveimSDK: Provider is not STEAM"), respReferesh.ResultCode, blockinfo } if respReferesh.ResultData.ImId != imid { - return errors.New("higveimSDK: ImId is not match") + return errors.New("higveimSDK: ImId is not match"), respReferesh.ResultCode, blockinfo } - return nil + if respReferesh.ResultCode == "SUCCESS" { + if respReferesh.ResultData.State == "BLOCKED" && len(respReferesh.ResultData.UserBlockInfo) > 0 { + blockinfo = respReferesh.ResultData.UserBlockInfo[0] + return nil, "BLOCKED", blockinfo + } + } + + return nil, respReferesh.ResultCode, blockinfo } func (mg *Maingate) platform_hybeim_getuserinfo(info usertokeninfo) (bool, string, string) {