to_upstream #2

Merged
mountain merged 2 commits from ws/maingate:to_upstream into master 2024-07-18 15:09:47 +09:00
4 changed files with 17 additions and 26 deletions

View File

@ -36,7 +36,7 @@ import (
var devflag = flagx.Bool("dev", false, "") var devflag = flagx.Bool("dev", false, "")
var noauth = flagx.Bool("noauth", false, "") var noauth = flagx.Bool("noauth", false, "")
var authtype = flagx.String("auth", "", "yes|no|both") var authtype = flagx.String("auth", "on", "on|off|both")
var ( var (
CollectionLink = gocommon.CollectionName("link") CollectionLink = gocommon.CollectionName("link")
@ -193,11 +193,11 @@ func New(ctx context.Context) (*Maingate, error) {
return nil, err return nil, err
} }
if *noauth && len(*authtype) == 0 { if len(*authtype) == 0 {
*authtype = "no" *authtype = "on"
} }
if *authtype == "yes" || *authtype == "both" { if !*noauth && (*authtype == "on" || *authtype == "both") {
if len(config.FirebaseAdminSDKCredentialFile) > 0 { if len(config.FirebaseAdminSDKCredentialFile) > 0 {
opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile) opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile)
firebaseApp, err := firebase.NewApp(context.Background(), nil, opt) firebaseApp, err := firebase.NewApp(context.Background(), nil, opt)

View File

@ -56,11 +56,7 @@ func (mg *Maingate) platform_hybeim_authorize(w http.ResponseWriter, r *http.Req
return return
} }
if !*noauth { if err = authenticateHybeImUser(config.HybeImProjectIdstring, config.HybeImServiceIdstring, config.HybeImAccessKey, config.HybeImEndPoint, authinfo.UserHybeimid, authinfo.UserLoginVerifyToken); err == nil {
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() acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix()
var info usertokeninfo var info usertokeninfo

View File

@ -39,11 +39,7 @@ func (mg *Maingate) platform_steamsdk_authorize(w http.ResponseWriter, r *http.R
return return
} }
if !*noauth { if err := authenticateSteamUser(config.SteamPublisherAuthKey, config.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken); err == nil {
err = authenticateSteamUser(config.SteamPublisherAuthKey, config.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken)
}
if err == nil {
acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix() acceestoken_expire_time := time.Date(2999, 1, int(time.January), 0, 0, 0, 0, time.UTC).Unix()
var info usertokeninfo var info usertokeninfo

View File

@ -653,7 +653,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
} }
queryvals := r.URL.Query() queryvals := r.URL.Query()
authtype := queryvals.Get("type") reqauthtype := queryvals.Get("type")
uid := queryvals.Get("id") uid := queryvals.Get("id")
sk := queryvals.Get("sk") sk := queryvals.Get("sk")
@ -692,9 +692,8 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
} }
var email string var email string
if !*noauth && (*authtype == "on" || *authtype == "both") {
if !*noauth { if len(reqauthtype) > 0 {
if len(authtype) > 0 {
//email, err := sh.readProfile(authtype, uid, accesstoken) //email, err := sh.readProfile(authtype, uid, accesstoken)
bfinfo, err := sh.getUserBrowserInfo(r) bfinfo, err := sh.getUserBrowserInfo(r)
if err != nil { if err != nil {
@ -703,25 +702,25 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
return return
} }
email, err = sh.readProfile(authtype, uid, bfinfo) email, err = sh.readProfile(reqauthtype, uid, bfinfo)
if err != nil { if err != nil {
logger.Error("readProfile failed :", err) logger.Error("readProfile failed :", err)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
newType, newId, err := sh.getProviderInfo(authtype, uid) newType, newId, err := sh.getProviderInfo(reqauthtype, uid)
if err != nil { if err != nil {
logger.Error("getProviderInfo failed :", err) logger.Error("getProviderInfo failed :", err)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
if authtype != newType || uid != newId { if reqauthtype != newType || uid != newId {
authtype = newType reqauthtype = newType
uid = newId uid = newId
} }
} else if *devflag { } else if *authtype == "both" {
email = fmt.Sprintf("%s@guest.flag", uid) email = fmt.Sprintf("%s@guest.flag", uid)
} else { } else {
// authtype이 없으면 입장 불가 // authtype이 없으면 입장 불가
@ -736,7 +735,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
// platform + id -> account id // platform + id -> account id
createtime := primitive.NewDateTimeFromTime(time.Now().UTC()) createtime := primitive.NewDateTimeFromTime(time.Now().UTC())
link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{ link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{
"platform": authtype, "platform": reqauthtype,
"uid": uid, "uid": uid,
}, bson.M{ }, bson.M{
"$setOnInsert": bson.M{ "$setOnInsert": bson.M{
@ -780,7 +779,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
sk, err = sh.sessionProvider.New(&session.Authorization{ sk, err = sh.sessionProvider.New(&session.Authorization{
Account: accid, Account: accid,
Platform: authtype, Platform: reqauthtype,
Uid: uid, Uid: uid,
Email: email, Email: email,
}) })
@ -796,7 +795,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
"newAccount": newaccount, "newAccount": newaccount,
"accid": accid.Hex(), "accid": accid.Hex(),
} }
if *noauth { if len(reqauthtype) == 0 {
output["noauth"] = true output["noauth"] = true
} }