Maingate - Hybeim SDK를 통한 Steam 로그인 처리
This commit is contained in:
@ -57,6 +57,7 @@ const (
|
|||||||
AuthPlatformMicrosoft = "microsoft"
|
AuthPlatformMicrosoft = "microsoft"
|
||||||
AuthPlatformApple = "apple"
|
AuthPlatformApple = "apple"
|
||||||
AuthPlatformTwitter = "twitter"
|
AuthPlatformTwitter = "twitter"
|
||||||
|
AuthPlatformHybeim = "hybeim"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -98,6 +99,11 @@ type maingateConfig struct {
|
|||||||
SteamAppId string `json:"steam_app_id"`
|
SteamAppId string `json:"steam_app_id"`
|
||||||
SteamPublisherAuthKey string `json:"steam_publisher_authkey"`
|
SteamPublisherAuthKey string `json:"steam_publisher_authkey"`
|
||||||
GlobalMaingateToken string `json:"maingate_api_token"`
|
GlobalMaingateToken string `json:"maingate_api_token"`
|
||||||
|
HybeImProjectIdstring string `json:"hybeim_projectid"`
|
||||||
|
HybeImServiceIdstring string `json:"hybeim_serviceid"`
|
||||||
|
HybeImAccessKey string `json:"hybeim_acesskey"`
|
||||||
|
HybeImEndPoint string `json:"hybeim_Endpoint"`
|
||||||
|
|
||||||
Firebase_Google_Analytics_JS_SDK_Config
|
Firebase_Google_Analytics_JS_SDK_Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,6 +554,8 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
|||||||
|
|
||||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_sdk", AuthPlatformSteamSDK), mg.platform_steamsdk_authorize)
|
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_sdk", AuthPlatformSteamSDK), mg.platform_steamsdk_authorize)
|
||||||
|
|
||||||
|
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_sdk", AuthPlatformHybeim), mg.platform_hybeim_authorize)
|
||||||
|
|
||||||
go mg.watchServiceCollection(ctx, serveMux, prefix)
|
go mg.watchServiceCollection(ctx, serveMux, prefix)
|
||||||
go mg.watchFileCollection(ctx, serveMux, prefix)
|
go mg.watchFileCollection(ctx, serveMux, prefix)
|
||||||
// fsx := http.FileServer(http.Dir("console"))
|
// fsx := http.FileServer(http.Dir("console"))
|
||||||
@ -671,6 +679,8 @@ func (mg *Maingate) updateUserinfo(info usertokeninfo) (bool, string, string) {
|
|||||||
success, userid, email = mg.platform_google_getuserinfo(info)
|
success, userid, email = mg.platform_google_getuserinfo(info)
|
||||||
case AuthPlatformSteamSDK:
|
case AuthPlatformSteamSDK:
|
||||||
success, userid, email = mg.platform_steamsdk_getuserinfo(info)
|
success, userid, email = mg.platform_steamsdk_getuserinfo(info)
|
||||||
|
case AuthPlatformHybeim:
|
||||||
|
success, userid, email = mg.platform_hybeim_getuserinfo(info)
|
||||||
case AuthPlatformFirebaseAuth:
|
case AuthPlatformFirebaseAuth:
|
||||||
success, userid, email = mg.platform_firebase_getuserinfo(info)
|
success, userid, email = mg.platform_firebase_getuserinfo(info)
|
||||||
}
|
}
|
||||||
|
|||||||
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