From a8317c1af659167cdde2ea2e513fa2931399ccf8 Mon Sep 17 00:00:00 2001 From: Tobiasz Heller Date: Mon, 6 May 2024 08:27:08 +0200 Subject: [PATCH] feat: connect firebase sdk --- config/pass_config.go | 1 + deployments/pass/taskdef.json | 4 ++++ internal/pass/server.go | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/config/pass_config.go b/config/pass_config.go index d78ac74..9b4e7c7 100644 --- a/config/pass_config.go +++ b/config/pass_config.go @@ -7,6 +7,7 @@ type PassConfig struct { KMSKeyID string `envconfig:"KMS_KEY_ID" default:"alias/pass_service_signing_key"` AWSEndpoint string `envconfig:"AWS_ENDPOINT" default:""` AWSRegion string `envconfig:"AWS_REGION" default:"us-east-2"` + FirebaseServiceAccount string `envconfig:"FIREBASE_SA"` FakeMobilePush bool `envconfig:"FAKE_MOBILE_PUSH" default:"false"` PairingRequestTokenValidityDuration time.Duration `envconfig:"PAIRING_REQUEST_TOKEN_VALIDITY_DURATION" default:"8765h"` // 1 year } diff --git a/deployments/pass/taskdef.json b/deployments/pass/taskdef.json index ae3e7bc..fb0913a 100644 --- a/deployments/pass/taskdef.json +++ b/deployments/pass/taskdef.json @@ -20,6 +20,10 @@ } ], "secrets": [ + { + "name": "FIREBASE_SA", + "valueFrom": "arn:aws:secretsmanager:us-east-2::secret:prod/pass-8pVN76:pass_firebase_sa::" + } ], "logConfiguration": { "logDriver": "awslogs", diff --git a/internal/pass/server.go b/internal/pass/server.go index b3db1f5..654fff2 100644 --- a/internal/pass/server.go +++ b/internal/pass/server.go @@ -1,12 +1,16 @@ package pass import ( + "context" "log" + firebase "firebase.google.com/go/v4" + "firebase.google.com/go/v4/messaging" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" "github.com/gin-gonic/gin" + "google.golang.org/api/option" "github.com/twofas/2fas-server/config" httphelpers "github.com/twofas/2fas-server/internal/common/http" @@ -51,6 +55,22 @@ func NewServer(cfg config.PassConfig) *Server { log.Fatal(err) } + ctx := context.Background() + var fcmClient *messaging.Client + if cfg.FirebaseServiceAccount != "" { + opt := option.WithCredentialsJSON([]byte(cfg.FirebaseServiceAccount)) + app, err := firebase.NewApp(ctx, nil, opt) + if err != nil { + log.Fatalf("Error initializing FCM App: %v", err) + } + fcmClient, err = app.Messaging(ctx) + if err != nil { + log.Fatalf("Error initializing Messaging Client: %v", err) + } + } + // TODO: use client in later phase. + _ = fcmClient + pairingApp := pairing.NewApp(signSvc, cfg.PairingRequestTokenValidityDuration) proxyPairingApp := connection.NewProxyServer("device_id")