firebase 설정에 따라 인스턴스 생성
This commit is contained in:
@ -36,6 +36,7 @@ import (
|
||||
|
||||
var devflag = flagx.Bool("dev", false, "")
|
||||
var noauth = flagx.Bool("noauth", false, "")
|
||||
var authtype = flagx.String("auth", "", "yes|no|both")
|
||||
|
||||
var (
|
||||
CollectionLink = gocommon.CollectionName("link")
|
||||
@ -133,6 +134,11 @@ func (ga *globalAdmins) parse() {
|
||||
ga.modtime = gocommon.ConfigModTime()
|
||||
}
|
||||
|
||||
type firebaseClient struct {
|
||||
firebaseAppClient *auth.Client
|
||||
firebaseAppContext context.Context
|
||||
}
|
||||
|
||||
// Maingate :
|
||||
type Maingate struct {
|
||||
mongoClient gocommon.MongoClient
|
||||
@ -148,8 +154,8 @@ type Maingate struct {
|
||||
authorizationEndpoints map[string]string
|
||||
userinfoEndpoint map[string]string
|
||||
jwksUri map[string]string
|
||||
firebaseAppClient *auth.Client
|
||||
firebaseAppContext context.Context
|
||||
|
||||
firebase *firebaseClient
|
||||
}
|
||||
|
||||
var config maingateConfig
|
||||
@ -186,18 +192,29 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !*noauth {
|
||||
opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile)
|
||||
firebaseApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||
if err != nil {
|
||||
logger.Error("firebase admin error initializing app failed :", err)
|
||||
return nil, err
|
||||
}
|
||||
if *noauth && len(*authtype) == 0 {
|
||||
*authtype = "no"
|
||||
}
|
||||
|
||||
mg.firebaseAppContext = ctx
|
||||
mg.firebaseAppClient, err = firebaseApp.Auth(mg.firebaseAppContext)
|
||||
if err != nil {
|
||||
logger.Println("FirebaseAppClient error getting Auth client:", err)
|
||||
if *authtype == "yes" || *authtype == "both" {
|
||||
if len(config.FirebaseAdminSDKCredentialFile) > 0 {
|
||||
opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile)
|
||||
firebaseApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||
if err != nil {
|
||||
logger.Error("firebase admin error initializing app failed :", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
firebaseAppClient, err := firebaseApp.Auth(ctx)
|
||||
if err != nil {
|
||||
logger.Println("FirebaseAppClient error getting Auth client:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mg.firebase = &firebaseClient{
|
||||
firebaseAppContext: ctx,
|
||||
firebaseAppClient: firebaseAppClient,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user