2024-06-11 11:54:17 +09:00
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type HybeImSDKAuthInfo struct {
|
|
|
|
|
UserHybeimid string `json:"imid"`
|
|
|
|
|
UserLoginVerifyToken string `json:"loginVerifyToken"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HybeImSDKLoginAuthInfo struct {
|
|
|
|
|
ServiceId string `json:"serviceId"`
|
|
|
|
|
UserLoginVerifyToken string `json:"loginVerifyToken"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Hiveim_LoginVerifyResult struct {
|
2024-07-22 16:16:11 +09:00
|
|
|
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"`
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Hiveim_LoginValidationResponse struct {
|
|
|
|
|
ResultCode string `json:"resultCode"`
|
|
|
|
|
ResultMessage string `json:"resultMessage"`
|
|
|
|
|
ResultData Hiveim_LoginVerifyResult `json:"resultData"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (mg *Maingate) platform_hybeim_authorize(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
defer r.Body.Close()
|
|
|
|
|
|
|
|
|
|
brinfo, err := mg.GetUserBrowserInfo(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
logger.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var authinfo HybeImSDKAuthInfo
|
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&authinfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Println("authinfo decoding fail:", err)
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
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" {
|
2024-06-11 11:54:17 +09:00
|
|
|
acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix()
|
|
|
|
|
|
|
|
|
|
var info usertokeninfo
|
|
|
|
|
info.platform = AuthPlatformHybeim
|
|
|
|
|
info.userid = authinfo.UserHybeimid
|
|
|
|
|
info.token = authinfo.UserLoginVerifyToken
|
|
|
|
|
info.brinfo = brinfo
|
|
|
|
|
//info.accesstoken = respReferesh.AccessToken
|
|
|
|
|
info.accesstoken_expire_time = acceestoken_expire_time
|
|
|
|
|
mg.setUserToken(info)
|
|
|
|
|
|
|
|
|
|
params := url.Values{}
|
|
|
|
|
params.Add("id", authinfo.UserHybeimid)
|
|
|
|
|
params.Add("authtype", AuthPlatformHybeim)
|
|
|
|
|
w.Write([]byte("?" + params.Encode()))
|
|
|
|
|
//http.Redirect(w, r, "actionsquare://login?"+Result, http.StatusSeeOther)
|
2024-07-22 16:16:11 +09:00
|
|
|
return
|
2024-06-11 11:54:17 +09:00
|
|
|
} else {
|
2024-07-22 16:16:11 +09:00
|
|
|
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()))
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
// logger.Println(err)
|
|
|
|
|
// http.Redirect(w, r, "actionsquare://error", http.StatusSeeOther)
|
|
|
|
|
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, UserLoginVerifyToken string) (error, string, Hiveim_UserBlockInfo) {
|
2024-06-11 11:54:17 +09:00
|
|
|
|
|
|
|
|
// endpoint
|
|
|
|
|
// qa = https://api-qa.pub-dev.hybegames.io
|
|
|
|
|
// prod = https://api.hybegames.com
|
|
|
|
|
|
|
|
|
|
verifyurl := endpoint + "/member/api-game/v1/auth/login/verify"
|
|
|
|
|
|
|
|
|
|
var param HybeImSDKLoginAuthInfo
|
|
|
|
|
param.UserLoginVerifyToken = UserLoginVerifyToken
|
|
|
|
|
param.ServiceId = serviceid
|
|
|
|
|
|
|
|
|
|
dat, err := json.Marshal(param)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var respReferesh Hiveim_LoginValidationResponse
|
|
|
|
|
req, err := http.NewRequest("POST", verifyurl, bytes.NewBuffer(dat))
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req.Header.Add("X-Auth-Access-Key", accesskey)
|
|
|
|
|
req.Header.Add("X-Req-Pjid", projectid)
|
|
|
|
|
|
|
|
|
|
client := &http.Client{}
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
io.Copy(io.Discard, resp.Body)
|
|
|
|
|
resp.Body.Close()
|
|
|
|
|
}()
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
var blockinfo Hiveim_UserBlockInfo
|
2024-06-11 11:54:17 +09:00
|
|
|
body, e := ioutil.ReadAll(resp.Body)
|
|
|
|
|
if e != nil {
|
2024-07-22 16:16:11 +09:00
|
|
|
return e, "", blockinfo
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json.Unmarshal(body, &respReferesh)
|
|
|
|
|
|
|
|
|
|
//fmt.Println(string(body))
|
|
|
|
|
|
|
|
|
|
var doc map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal(body, &doc); err != nil {
|
2024-07-22 16:16:11 +09:00
|
|
|
return err, respReferesh.ResultCode, blockinfo
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
// if respReferesh.ResultData.State != "NORMAL" {
|
|
|
|
|
// return errors.New("higveimSDK: State is not NORMAL"), respReferesh.ResultCode, blockinfo
|
|
|
|
|
// }
|
2024-06-11 11:54:17 +09:00
|
|
|
|
|
|
|
|
if respReferesh.ResultData.Provider != "STEAM" {
|
2024-07-22 16:16:11 +09:00
|
|
|
return errors.New("higveimSDK: Provider is not STEAM"), respReferesh.ResultCode, blockinfo
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if respReferesh.ResultData.ImId != imid {
|
2024-07-22 16:16:11 +09:00
|
|
|
return errors.New("higveimSDK: ImId is not match"), respReferesh.ResultCode, blockinfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if respReferesh.ResultCode == "SUCCESS" {
|
|
|
|
|
if respReferesh.ResultData.State == "BLOCKED" && len(respReferesh.ResultData.UserBlockInfo) > 0 {
|
|
|
|
|
blockinfo = respReferesh.ResultData.UserBlockInfo[0]
|
|
|
|
|
return nil, "BLOCKED", blockinfo
|
|
|
|
|
}
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:16:11 +09:00
|
|
|
return nil, respReferesh.ResultCode, blockinfo
|
2024-06-11 11:54:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (mg *Maingate) platform_hybeim_getuserinfo(info usertokeninfo) (bool, string, string) {
|
|
|
|
|
// Hybeim ( Steam )도 이메일 정보를 받을수 없기 때문에 userid로 리턴한다.
|
|
|
|
|
dummyEmail := fmt.Sprintf("%s@hibeim.id", info.userid)
|
|
|
|
|
return true, info.userid, dummyEmail
|
|
|
|
|
|
|
|
|
|
}
|