noauth 플래그 처리

This commit is contained in:
2023-06-20 15:50:18 +09:00
parent 6db196df28
commit 7d4d4049e8
2 changed files with 50 additions and 25 deletions

View File

@ -80,6 +80,7 @@ func init() {
CollectionAuth = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAuth)))
CollectionWhitelist = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionWhitelist)))
CollectionService = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionService)))
CollectionAccount = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAccount)))
CollectionBlock = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionBlock)))
CollectionPlatformLoginToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionPlatformLoginToken)))
CollectionUserToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionUserToken)))
@ -448,8 +449,26 @@ func whitelistKey(email string) string {
func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux, prefix string) error {
var allServices []*serviceDescription
logger.Println(CollectionService)
if err := mg.mongoClient.AllAs(CollectionService, &allServices, options.Find().SetReturnKey(false)); err != nil {
if *flag.Noauth {
host, _ := os.Hostname()
empty := serviceDescription{
ServiceDescriptionSummary: ServiceDescriptionSummary{
ServiceCode: "000000000000",
},
Divisions: map[string]*Division{
host: {
DivisionForUser: DivisionForUser{
Priority: 0,
State: DivisionState_FullOpen,
},
Url: fmt.Sprintf("http://%s/warehouse", host),
},
},
}
empty.prepare(mg)
allServices = append(allServices, &empty)
} else if err := mg.mongoClient.AllAs(CollectionService, &allServices, options.Find().SetReturnKey(false)); err != nil {
return err
}

View File

@ -16,6 +16,7 @@ import (
common "repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/maingate/flag"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
@ -425,7 +426,9 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
uid := queryvals.Get("id")
//accesstoken := queryvals.Get("token") //-- 이거 이제 받지마라
session := queryvals.Get("sk")
var email string
if !*flag.Noauth {
//email, err := sh.readProfile(authtype, uid, accesstoken)
bfinfo, err := sh.getUserBrowserInfo(r)
if err != nil {
@ -434,7 +437,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
return
}
email, err := sh.readProfile(authtype, uid, bfinfo)
email, err = sh.readProfile(authtype, uid, bfinfo)
if err != nil {
logger.Error("readProfile failed :", err)
w.WriteHeader(http.StatusBadRequest)
@ -454,6 +457,9 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
uid = newId
logger.Println("auth success ( redirect ) :", authtype, uid, email, session)
}
} else {
email = fmt.Sprintf("%s@noauth.flag", uid)
}
//if len(session) == 0 && len(email) > 0 {
if len(session) == 0 {