Those 2 .NET libraries do not require the JSON file be present or the environment variable set in order to obtain credentials needed to communicate with the service. Both of these classes can be initialized with a Google.Apis.Auth.OAuth2.ServiceAccountCredential object, which can be constructed with just the UPN of the service account and the private key:
ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountUpn)
{
Scopes = new List<string>() { AndroidEnterpriseService.Scope.Androidenterprise }
}.FromPrivateKey(serviceAccountPrivateKey));
return new AndroidEnterpriseService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyServiceName"
});
Due to how we must store this information in our service, this works great. From what I can tell, I cannot do something similar when creating a PublisherClient or SubscriberClient instance. There doesn't seem to be a way to provide credentials that's at least straightforward (this
Create method looks somewhat promising, but I don't see an obvious way to be able to do that). Basically, we aren't really able to store the JSON on disk and set the environment variable in our environment, so I'm looking for a way to programmatically provide the credentials to the Subscriber and Publisher clients.