Hybe로그인 관련 제재 로그인 금지 처리 - 로그인 authorize에서 제재 처리 하는 기능 추가

This commit is contained in:
2024-07-22 16:16:11 +09:00
parent bdae4eeb48
commit 4212d3ed59

View File

@ -30,6 +30,15 @@ type Hiveim_LoginVerifyResult struct {
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) {