Merge pull request #45 from twofas/feat/connect-firebase-sdk

feat: connect firebase sdk
This commit is contained in:
Tobiasz Heller 2024-05-06 15:33:26 +02:00 committed by GitHub
commit 6a7d36b955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 0 deletions

View File

@ -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
}

View File

@ -20,6 +20,10 @@
}
],
"secrets": [
{
"name": "FIREBASE_SA",
"valueFrom": "arn:aws:secretsmanager:us-east-2:<AWS_ACCOUNT_ID>:secret:prod/pass-8pVN76:pass_firebase_sa::"
}
],
"logConfiguration": {
"logDriver": "awslogs",

View File

@ -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")