I have to implement firebase in 2 configurations Debug and Release.
This is the reason I have removed json files and wrote code line this:
for configuration 1-
var env1 = new FirebaseOptions.Builder()
.SetApplicationId(myId)
.SetApiKey(myKey)
.SetStorageBucket(appspot.com)
.SetProjectId(myPID)
.SetDatabaseUrl(MYURL)
.Build();
var app1 = FirebaseApp.InitializeApp(Application.Context, env1, "Debug");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);
For configuration 2-
var env2 = new FirebaseOptions.Builder()
.SetApplicationId(myId)
.SetApiKey(myKey)
.SetStorageBucket(appspot.com)
.SetProjectId(myPID)
.SetDatabaseUrl(MYURL)
.Build();
var app2 = FirebaseApp.InitializeApp(Application.Context, env2, "Release");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);
Here either it is giving error like missing_google_id or firebase is not initialized.
I have tried adding string value in xml file for android,still same error.
To acieve my goal I have also tried adding multiple json files in different directories as per the link below
Xamarin firebase different google-services,json for different build configurations
but it seems it still looks for json file in root folder..
So how to implement firebase without or with json file for multiple environments
There definitely is no way to report analytics data from multiple FirebaseApp instances in a single app. See Firebase Analytics (Two projects) for single app.
If I remember correctly, Google Analytics for Firebase always reports analytics for the default FirebaseApp instance. The best reference I found for that is Use multiple firebase accounts in single android app for google analytics, but if someone has a more authoritative source I'd love to hear.
If that is the case, since each build is either Debug *or Release, you could initialize only the relevant FirebaseApp instances for the specific build target.
Related
I am trying to create a IoT DPS device with a symmetric key, For that to work, I need a ProvisioningTransportHandlerMqtt.
I have tried the console application fromlearn: https://learn.microsoft.com/en-us/azure/iot-dps/how-to-legacy-device-symm-key?tabs=windows&pivots=programming-language-csharp and I can provision devices with it.
I have tried making an interactive .Net notebook, and I can also provision devices from that:
The issue is only in my own cs file. When I try to run a similar line in a cs file the object is different:
The samplecode from Microsoft produces a valid transportHandeler:
I have no clue how to create a proper transportHandler. How do I get a proper ProvisioningTransportHandlerMqtt()?
Turned out including the DotNetty dlls in my app solved the issue.
I'm creating a MAUI app and I'm trying to connect it to Firestore.
I have set everything up in Firebase and I can successfully connect to the Firestore by setting the environment variable: "GOOGLE_APPLICATION_CREDENTIALS" on my windows machine locally.
However, I cannot make it work if I test out the app using my local android device since this device doesn't have the environment variable set up.
So my question is, how would I go about doing this, so I can connect to the Firestore on my android device?
Some thoughts:
I would imagine that I need to set the environment variable in the MAUI code and somehow read it, but wouldn't that expose the secret file since it would now exist inside the MAUI project?
It looks like some people are using the google-services.json file for this purpose (which is not strictly secret) so if I could use that instead, then I guess that would be the best, but again, how would I do that?
I have tried adding the files in the Asset files, .csproj file, setting environment variables in the MainProgram etc. but I just can't make it work and even worse, I'm unsure whether that approach would be insecure.
Any help would be greatly appreciated.
Possible duplicate: How do I connect my MAUI app to a Firestore database? (via service account json file)
I just still don't understand how they made it work.
This is how I successfully set it up in .NET Maui:
Copy the "Json" file from Google under the "Resource/Raw" folder
with a BuildAction "MauiAsset"
Below is my initialization code:
public async Task<FirestoreDb> initFirestore()
{
try
{
var stream = await FileSystem.OpenAppPackageFileAsync(Constants.FirestoreKeyFilename);
var reader = new StreamReader(stream);
var contents = reader.ReadToEnd();
FirestoreClientBuilder fbc = new FirestoreClientBuilder { JsonCredentials = contents };
return FirestoreDb.Create(Constants.FirestoreProjectID, fbc.Build());
}
catch (Exception)
{
throw;
}
}
Hope that helps.
I have been using c# code to get blob items for the past few days, however, with no changes to the way the program gets the blob data, it stopped working. I run into the same error every time I run now:
"EnvironmentCredential authentication unavailable. Environment variables are not fully configured"
Here is the code I am using to connect to Azure:
Uri accountUri = new Uri(mystorageurl);
BlobServiceClient client = new BlobServiceClient(accountUri, new DefaultAzureCredential(true));
BlobContainerClient container = client.GetBlobContainerClient(blobname);
BlobClient bundle = container.GetBlobClient(itemname);
What I've been confused by is that if I run this same code in a separate vs solution, I get no error getting the files from Azure. I've also tried sending the same solution that's getting the error to another person and they were able to run it without issue. I know it isn't an issue with environment variables, since it used to work up until now and they haven't been modified in any way.
This unresolved issue on github is most similar to what I've encountered:
https://github.com/Azure/azure-sdk-for-net/issues/16079
It worked fine when you never set Environment variables, it means that you didn't use EnvironmentCredential. The DefaultAzureCredential will attempt to authenticate via the following mechanisms in order, and Environment is the first one.
If you just use Environment to authenticate, it's better to use EnvironmentCredential instead of DefaultAzureCredential. And it's necessary to set the following variables.
AZURE_CLIENT_ID: id of an Azure Active Directory application
AZURE_TENANT_ID: id of the application's Azure Active Directory tenant
AZURE_CLIENT_SECRET: one of the application's client secrets
I am trying to create an app for Android 4.0.3 that listens for UDP-telegrams and starts other apps, depending on the received message.
I am already able to Launch some apps, like the "Music" app:
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
intent.SetFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
Is there any chance to do the same for the Video app?
I dont find a valid command for that. (especially WITHOUT loading a defined Video, like Action_View would do)
I was also thinking about using the StartApp, like the following:
OpenApp(context, "com.google.android.apps.maps");
But I also dont find a valid package-name for the Video app, like the other apps have.
Background:
This is for a car-project. The Android-tablet should be used as infotainment system and I want to use an "Ardoino Leonardo Ethernet" to switch between the most important app, using hardkeys instead of the touchscreen.
I prefer to avoid hardcoding any package names as doing so will cause the code to break on different APIs and different vendor's ROMs as they include their own "players" and "viewers".
You can determine which packages are installed that will response to different Uri and Mime types by using the Package Manager and making a query to it, i.e.
var activityIntent = new Intent(Intent.ActionView);
activityIntent.SetDataAndTypeAndNormalize(Uri.Parse("pseudo.mp4"), "video/mp4");
var resolvedActivityList = PackageManager.QueryIntentActivities(activityIntent, PackageInfoFlags.MatchAll);
foreach (var info in resolvedActivityList)
{
Log.Debug("SO", info.ActivityInfo.ApplicationInfo.PackageName);
}
var rawData = Convert.FromBase64String(_signingKey);
var cng = CngKey.Import(rawData, CngKeyBlobFormat.Pkcs8PrivateBlob);
I use this code to extract key, from embedded base64 string.
It works fine when I test it locally but when I publish on azure I get following exception:
WindowsCryptographicException: The system cannot find the file specified
(once again I'm not reading from any file)
I need this to communicate with apple apns for push notifications, is there any workaround?
And this happens only on free service plan, if I switch to basic plan it's working.
I ran into the same error after publishing an existing application to Azure. In my case the problem was solved after I set WEBSITE_LOAD_USER_PROFILE = 1 in App Services / App Name / Application Settings.
Setting WEBSITE_LOAD_USER_PROFILE to equal 1 in the Azure App Service configuration definitely got my remote iOS notifications working. Using dotAPNS for C# .NET I also needed to omit apns.UseSandbox().
It seems that it causes by there is no certificate attached in your Azure Mobile App. If it is that case, we need to upload the "Development" or "Distribution" SSL certificate to the WebApp. More info about how to send push notifications to iOS App, please refer to the azure document.
I've had a similar error trying to construct a X509Certificate2 from a byte array - worked fine locally but once I deploy to Azure Web App, I got the same and VERY misleading file not found exception.
The real issue turned out to be that there was no user store associated with the web service account. You can also get a similar error if there are permission-related errors with accessing the certificate store on Windows.
In any case - In my scenario I fixed the problem by using MachineKeySet:
new X509Certificate2(certRawBytes, default(string), X509KeyStorageFlags.MachineKeySet);
So, in your scenario, try something like:
var keyParams = new CngKeyCreationParameters
{
KeyCreationOptions = CngKeyCreationOptions.MachineKey,
};
CngKey.Create(CngAlgorithm.Rsa, keyName, keyParams);
Note: You may have to set a few parameters to get the above working. The Import method doesn't seem to support MachineKey - but you should be able to achieve similar outcome by using the Create method.
To add to #strohmsn's answer, you can also set the App Service settings with this value directly within Visual Studio on the Publish page for web apps: Right click on web app and select Publish, then select App Service Settings, and you can add setting properties there: WEBSITE_LOAD_USER_PROFILE = 1 in this case. See screenshot:
For making it works, I needed TWO things in AzureWebApp..
So my code is :
//I load the PrivateKey here
ReadedByte = System.IO.File.ReadAllBytes(strPathPrivateKey);
//create the RSA thing
RSA rsa = System.Security.Cryptography.RSA.Create();
//import the key. It crashed HERE with the 'System cannot find file specified'
rsa.ImportPkcs8PrivateKey(source: ReadedByte,bytesRead: out int _);
It works perfectly locally. But, to make it WORK on Azure Web App, I had to have those TWO requirements :
1 - the WEBSITE_LOAD_USER_PROFILE = 1 spoken in the discussion above and below
2 - The App Service Plan must include "Custom domains / SSL" !
...so No 'F1 Share Infrastructure' nor 'D1 Share Infrastructure'. The lowest Service plan that worked for me was 'B1 - 100 Total Acu'.
Maybe I have something wrong somewhere else in my code, or my 'RSA' choice is bad..anyway...
It now works!