Спасибо за отзыв Фрэнк, По вашей ссылке я нашел ответ. Для аутентификации в firestore из настольного приложения вам нужно сделать следующее:
public FirestoreDb CreateFirestoreDbWithEmailAuthentication(string emailAddress,
string password, string firebaseApiKey, string firebaseProjectId)
{
// Create a custom authentication mechanism for Email/Password authentication
// If the authentication is successful, we will get back the current authentication token and the refresh token
// The authentication expires every hour, so we need to use the obtained refresh token to obtain a new authentication token as the previous one expires
var authProvider = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));
var auth = authProvider.SignInWithEmailAndPasswordAsync(emailAddress, password).Result;
var callCredentials = CallCredentials.FromInterceptor(async (context, metadata) =>
{
if (auth.IsExpired()) auth = await auth.GetFreshAuthAsync();
if (string.IsNullOrEmpty(auth.FirebaseToken)) return;
metadata.Clear();
metadata.Add("authorization", $"Bearer {auth.FirebaseToken}");
});
var credentials = ChannelCredentials.Create(new SslCredentials(), callCredentials);
// Create a custom Firestore Client using custom credentials
var grpcChannel = new Channel("firestore.googleapis.com", credentials);
var grcpClient = new Firestore.FirestoreClient(grpcChannel);
var firestoreClient = new FirestoreClientImpl(grcpClient, FirestoreSettings.GetDefault());
return FirestoreDb.Create(firebaseProjectId, null, firestoreClient);
}
Конечно, сначала вам нужно добавить пользователя электронной почты в консоль firestore.