Maingate - Hybeim SDK를 통한 Steam 로그인 처리
This commit is contained in:
163
core/platformhybeim.go
Normal file
163
core/platformhybeim.go
Normal file
@ -0,0 +1,163 @@
|
||||
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 {
|
||||
State string `json:"state"`
|
||||
ImId string `json:"imId"`
|
||||
Provider string `json:"provider"`
|
||||
Os string `json:"os"`
|
||||
AppStore string `json:"appStore"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if !*noauth {
|
||||
err = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
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)
|
||||
} else {
|
||||
logger.Println(err)
|
||||
http.Redirect(w, r, "actionsquare://error", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func authenticateHybeImUser(projectid, serviceid, accesskey, endpoint, imid, UserLoginVerifyToken string) error {
|
||||
|
||||
// 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()
|
||||
}()
|
||||
|
||||
body, e := ioutil.ReadAll(resp.Body)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
json.Unmarshal(body, &respReferesh)
|
||||
|
||||
//fmt.Println(string(body))
|
||||
|
||||
var doc map[string]interface{}
|
||||
if err := json.Unmarshal(body, &doc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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.Provider != "STEAM" {
|
||||
return errors.New("higveimSDK: Provider is not STEAM")
|
||||
}
|
||||
|
||||
if respReferesh.ResultData.ImId != imid {
|
||||
return errors.New("higveimSDK: ImId is not match")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user