diff --git a/core/maingate.go b/core/maingate.go index d89de86..6aed706 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -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 } diff --git a/core/service.go b/core/service.go index 999d223..ca79711 100644 --- a/core/service.go +++ b/core/service.go @@ -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,34 +426,39 @@ 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 - //email, err := sh.readProfile(authtype, uid, accesstoken) - bfinfo, err := sh.getUserBrowserInfo(r) - if err != nil { - logger.Error("getUserBrowserInfo failed :", err) - w.WriteHeader(http.StatusBadRequest) - return - } + if !*flag.Noauth { + //email, err := sh.readProfile(authtype, uid, accesstoken) + bfinfo, err := sh.getUserBrowserInfo(r) + if err != nil { + logger.Error("getUserBrowserInfo failed :", err) + w.WriteHeader(http.StatusBadRequest) + return + } - email, err := sh.readProfile(authtype, uid, bfinfo) - if err != nil { - logger.Error("readProfile failed :", err) - w.WriteHeader(http.StatusBadRequest) - return - } + email, err = sh.readProfile(authtype, uid, bfinfo) + if err != nil { + logger.Error("readProfile failed :", err) + w.WriteHeader(http.StatusBadRequest) + return + } - logger.Println("auth success :", authtype, uid, email, session) + logger.Println("auth success :", authtype, uid, email, session) - newType, newId, err := sh.getProviderInfo(authtype, uid) - if err != nil { - logger.Error("getProviderInfo failed :", err) - w.WriteHeader(http.StatusBadRequest) - } + newType, newId, err := sh.getProviderInfo(authtype, uid) + if err != nil { + logger.Error("getProviderInfo failed :", err) + w.WriteHeader(http.StatusBadRequest) + } - if authtype != newType || uid != newId { - authtype = newType - uid = newId - logger.Println("auth success ( redirect ) :", authtype, uid, email, session) + if authtype != newType || uid != newId { + authtype = newType + 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 {