I am attempting to initialize the Firebase Admin SDK using a Heroku instance running a Java Spring application. The Firebase instructions reference the .json file directly.
Initialize the Firebase Admin SDK
I do not want to include my admin SDK json file directly in my git repo because I don't want my firebase credentials exposed. To access the .json values in Heroku I have created an environment variable with the contents of the Firebase Admin SDK .json file inside of it. I have done the same thing in my local development environment and the app works by accessing the environment var using this method:
String serviceAccountJson = System.getenv("SERVICE_ACCOUNT_JSON");
InputStream serviceAccount = new ByteArrayInputStream(serviceAccountJson.getBytes(StandardCharsets.UTF_8));
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))'
.setDatabaseUrl("https://myfirebase-app.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
When I attempt to run the app in Heroku it crashes when firebase tries to initialize.
Are there any work arounds or other methods to access a .json file that is not in a .git repo, but available on a Heroku server?