mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using FirebaseAdmin;
|
|
using FirebaseAdmin.Messaging;
|
|
using Google.Apis.Auth.OAuth2;
|
|
//using Google.Cloud.Firestore;
|
|
//using Google.Cloud.Firestore.V1;
|
|
//using Grpc.Auth;
|
|
//using Grpc.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCore.Framework.Business
|
|
{
|
|
public class FirebaseClient
|
|
{
|
|
//public FirestoreDb _firestore;
|
|
public FirebaseClient(string computeCredsJson, string firebaseCredsJson, string project)
|
|
{
|
|
var _credential = GoogleCredential.FromJson(computeCredsJson);
|
|
if (_credential.IsCreateScopedRequired)
|
|
{
|
|
//_credential = _credential.CreateScoped(FirestoreClient.DefaultScopes);
|
|
}
|
|
|
|
//Channel channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), _credential.ToChannelCredentials());
|
|
//FirestoreClient client = FirestoreClient.Create(channel);
|
|
//_firestore = FirestoreDb.CreateAsync(project, client).GetAwaiter().GetResult();
|
|
|
|
if (FirebaseApp.DefaultInstance == null)
|
|
{
|
|
try{
|
|
FirebaseApp.Create(new AppOptions()
|
|
{
|
|
Credential = GoogleCredential.FromJson(firebaseCredsJson),
|
|
ProjectId = project,
|
|
//ServiceAccountId = firebaseCredsJson["client_email"]
|
|
});
|
|
} catch(Exception e)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|